:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --ink: #17211d;
  --muted: #68736d;
  --line: #d9e1dc;
  --accent: #176d5a;
  --accent-2: #b8402a;
  --focus: #246bdb;
  --shadow: 0 18px 50px rgba(30, 43, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100% - 12px, 1920px);
  margin: 0 auto;
  padding: 2px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  min-height: 48px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.05;
}

.topbar .eyebrow {
  margin-bottom: 0;
  font-size: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

.stats {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.account-box {
  display: grid;
  grid-template-rows: 18px 24px;
  gap: 4px;
  min-width: 138px;
}

.account-box span {
  font-size: 13px;
  font-weight: 700;
}

.account-box button {
  width: 100%;
}

.stats div {
  height: 48px;
  min-width: 76px;
  padding: 4px 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 28px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
}

.stats span {
  display: block;
  font-size: 18px;
  font-weight: 800;
}

.stats small,
.switch-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats > div:not(.account-box) {
  display: grid;
  align-content: center;
  gap: 1px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.module-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.module-tab {
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.module-tab.active {
  color: var(--accent);
  border-color: var(--line);
  background: var(--surface);
}

.subject-change-view {
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  gap: 10px;
  min-height: calc(100vh - 125px);
}

.subject-change-form-panel,
.subject-change-list-panel {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.subject-change-form-panel {
  align-self: start;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
}

.subject-change-form-panel form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.subject-change-form-panel label {
  display: grid;
  gap: 4px;
  color: #304039;
  font-size: 12px;
  font-weight: 700;
}

.subject-change-form-panel input {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.subject-change-list-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 145px);
  min-height: 0;
  overflow: hidden;
}

.subject-change-list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.subject-change-list-tools input {
  max-width: 360px;
  min-height: 34px;
}

.subject-change-table-wrap {
  min-height: 0;
  overflow: auto;
}

.subject-change-table-wrap table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.subject-change-table-wrap th,
.subject-change-table-wrap td {
  min-width: 120px;
  padding: 8px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.subject-change-table-wrap th:nth-child(1),
.subject-change-table-wrap td:nth-child(1),
.subject-change-table-wrap th:nth-child(5),
.subject-change-table-wrap td:nth-child(5) {
  min-width: 220px;
}

.subject-change-table-wrap th:nth-child(2),
.subject-change-table-wrap td:nth-child(2) {
  min-width: 190px;
}

.subject-change-table-wrap th:nth-child(3),
.subject-change-table-wrap td:nth-child(3) {
  min-width: 190px;
}

.subject-change-table-wrap th:nth-child(4),
.subject-change-table-wrap td:nth-child(4),
.subject-change-table-wrap th:nth-child(5),
.subject-change-table-wrap td:nth-child(5) {
  min-width: 110px;
}

.subject-change-table-wrap th:nth-child(5),
.subject-change-table-wrap td:nth-child(5) {
  min-width: 100px;
  width: 100px;
  max-width: 100px;
}

.subject-change-table-wrap th:nth-child(6),
.subject-change-table-wrap td:nth-child(6) {
  min-width: 240px;
}

.subject-change-table-wrap th:nth-child(7),
.subject-change-table-wrap td:nth-child(7),
.subject-change-table-wrap th:nth-child(8),
.subject-change-table-wrap td:nth-child(8),
.subject-change-table-wrap th:nth-child(9),
.subject-change-table-wrap td:nth-child(9) {
  min-width: 80px;
  width: 80px;
  max-width: 80px;
}

.subject-change-table-wrap th:nth-child(9),
.subject-change-table-wrap td:nth-child(9) {
  min-width: 90px;
  width: 90px;
  max-width: 90px;
}

.subject-change-table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}

.subject-change-table-wrap thead tr:first-child th {
  z-index: 3;
}

.subject-change-table-wrap .subject-change-filter-row th {
  top: 33px;
  z-index: 2;
  padding: 5px 7px;
  background: var(--surface-2);
}

.subject-change-filter-row input,
.subject-change-filter-row select {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid #cbd8d4;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.subject-change-filter-row input:focus,
.subject-change-filter-row select:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(36, 107, 219, 0.13);
}

.invoice-view {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 10px;
  min-height: calc(100vh - 125px);
}

.invoice-form-panel,
.invoice-list-panel {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* Keep the invoice editor visible while the records list is scrolled. */
.invoice-form-panel {
  position: sticky;
  top: 10px;
  align-self: start;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
}

.invoice-form-panel form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.invoice-form-panel label {
  display: grid;
  gap: 4px;
  color: #304039;
  font-size: 12px;
  font-weight: 700;
}

.invoice-form-panel input,
.invoice-form-panel select,
.invoice-form-panel textarea {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.invoice-list-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 145px);
  min-height: 0;
  overflow: hidden;
}

.invoice-list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.invoice-list-tools input {
  max-width: 360px;
  min-height: 34px;
}

.invoice-result-count {
  color: var(--muted);
  font-size: 13px;
}

.invoice-table-wrap {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.invoice-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}

.invoice-horizontal-scrollbar {
  flex: 0 0 16px;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--line);
  background: #f9fbfa;
}

.invoice-horizontal-scrollbar > div {
  height: 1px;
}

.invoice-table-wrap table {
  width: 100%;
  min-width: 1050px;
  table-layout: fixed;
}

.invoice-table-wrap th,
.invoice-table-wrap td {
  padding: 9px 8px;
  overflow-wrap: anywhere;
}

.invoice-table-wrap th:nth-child(1),
.invoice-table-wrap td:nth-child(1) { width: 180px; }
.invoice-table-wrap th:nth-child(2),
.invoice-table-wrap td:nth-child(2) { width: 180px; }
.invoice-table-wrap th:nth-child(3),
.invoice-table-wrap td:nth-child(3) { width: 220px; }
.invoice-table-wrap th:nth-child(4),
.invoice-table-wrap td:nth-child(4) { width: 260px; }
.invoice-table-wrap th:nth-child(5),
.invoice-table-wrap td:nth-child(5) { width: 110px; }
.invoice-table-wrap th:nth-child(6),
.invoice-table-wrap td:nth-child(6) { width: 90px; }
.invoice-table-wrap th:nth-child(7),
.invoice-table-wrap td:nth-child(7) { width: 160px; }
.invoice-table-wrap th:nth-child(8),
.invoice-table-wrap td:nth-child(8) { width: 210px; }
.invoice-row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  white-space: nowrap;
}
.invoice-row-actions button + button { margin-left: 0; }

.workspace#licenseView {
  height: calc(100vh - 125px);
  min-height: 0;
  overflow: hidden;
}

.workspace#licenseView > .form-panel {
  position: static;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.workspace#licenseView > .list-panel {
  height: 100%;
}

.seal-loan-view {
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  gap: 10px;
  min-height: calc(100vh - 125px);
}
.seal-loan-form-panel,
.seal-loan-list-panel {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.seal-loan-form-panel {
  align-self: start;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
}
.seal-loan-form-panel form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.seal-loan-form-panel label {
  display: grid;
  gap: 4px;
  color: #304039;
  font-size: 12px;
  font-weight: 700;
}
.seal-loan-form-panel input,
.seal-loan-form-panel select,
.seal-loan-form-panel textarea {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}
.seal-loan-form-panel select[multiple] {
  min-height: 150px;
}
.seal-loan-list-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 145px);
  min-height: 0;
  overflow: hidden;
}
.seal-loan-list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.seal-loan-list-tools input {
  max-width: 360px;
  min-height: 34px;
}
.seal-loan-tabs {
  display: inline-flex;
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.seal-loan-tab {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.seal-loan-tab:last-child { border-right: 0; }
.seal-loan-tab.active { background: #e7f3ef; color: var(--accent-strong); font-weight: 700; }
.seal-loan-tab strong { margin-left: 4px; }
.seal-loan-table-wrap {
  min-height: 0;
  overflow: auto;
}
.seal-loan-table-wrap table {
  width: max-content;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
}
.seal-loan-table-wrap th,
.seal-loan-table-wrap td {
  min-width: 0;
  padding: 8px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}
.seal-loan-table-wrap th:nth-child(1),
.seal-loan-table-wrap td:nth-child(1) { width: 54px; }
.seal-loan-table-wrap th:nth-child(2),
.seal-loan-table-wrap td:nth-child(2) { width: 108px; }
.seal-loan-table-wrap th:nth-child(3),
.seal-loan-table-wrap td:nth-child(3) { width: 190px; }
.seal-loan-table-wrap th:nth-child(4),
.seal-loan-table-wrap td:nth-child(4) {
  width: 380px;
  white-space: nowrap;
}
.seal-loan-table-wrap th:nth-child(5),
.seal-loan-table-wrap td:nth-child(5) { width: 100px; }
.seal-loan-table-wrap th:nth-child(6),
.seal-loan-table-wrap td:nth-child(6) { width: 100px; }
.seal-loan-table-wrap th:nth-child(7),
.seal-loan-table-wrap td:nth-child(7) { width: 240px; }
.seal-loan-table-wrap th:nth-child(8),
.seal-loan-table-wrap td:nth-child(8) { width: 150px; }
.seal-loan-table-wrap th:nth-child(7),
.seal-loan-table-wrap td:nth-child(7) { width: 110px; }
.seal-loan-table-wrap th:nth-child(8),
.seal-loan-table-wrap td:nth-child(8) { width: 240px; }
.seal-loan-table-wrap th:nth-child(9),
.seal-loan-table-wrap td:nth-child(9) { width: 150px; }
.seal-loan-table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}

.seal-loan-table-wrap thead tr:first-child th {
  z-index: 3;
}

.seal-loan-table-wrap .seal-loan-filter-row th {
  top: 33px;
  z-index: 2;
  padding: 5px 7px;
  background: var(--surface-2);
}

.seal-loan-filter-row input,
.seal-loan-filter-row select {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid #cbd8d4;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.seal-loan-filter-row input:focus,
.seal-loan-filter-row select:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(36, 107, 219, 0.13);
}

.seal-loan-detail-row td {
  background: var(--surface-2);
}
.seal-loan-return-table {
  width: 100% !important;
  min-width: 0 !important;
  margin-top: 8px;
}
.seal-loan-return-table th,
.seal-loan-return-table td {
  min-width: 0;
}
.seal-loan-item-picker {
  display: grid;
  gap: 5px;
  max-height: 170px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.seal-loan-item-picker label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 3px 4px;
  color: var(--ink);
  font-weight: 400;
  cursor: pointer;
}
.seal-loan-item-picker label:hover {
  background: var(--surface-2);
}
.seal-loan-item-picker input {
  min-height: 16px;
  width: 16px;
  accent-color: var(--accent);
}
.account-box { position: relative; }
.account-trigger { position: relative; min-height: 30px; width: 100%; padding-right: 22px; border: 0; background: transparent; font-weight: 700; text-align: left; cursor: pointer; }
.account-trigger::after { content: ""; position: absolute; right: 8px; top: 50%; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid currentColor; transform: translateY(-35%); transition: transform .15s ease; }
.account-trigger[aria-expanded="true"]::after { transform: translateY(-65%) rotate(180deg); }
.account-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 100; display: grid; min-width: 150px; padding: 5px; background: #ffffff; opacity: 1; border: 1px solid #cbd8d4; border-radius: 6px; box-shadow: 0 8px 20px rgba(23, 33, 29, .18); }
.account-menu button { display: block; width: 100%; min-height: 34px; padding: 8px 12px; border: 0; border-radius: 4px; background: #ffffff; color: var(--ink); text-align: left; white-space: nowrap; cursor: pointer; }
.account-menu button:hover, .account-menu button:focus-visible { background: #e8f3ef; outline: none; }
.seal-confirmation-direct-button { min-height: 34px; padding: 0 12px; border: 1px solid #e0b04b; border-radius: 6px; background: #fff8e6; color: #805800; font-weight: 700; white-space: nowrap; }
.seal-confirmation-direct-button:hover, .seal-confirmation-direct-button:focus-visible { background: #ffefc2; outline: none; }
.auth-modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(23, 33, 29, .35); }
.auth-modal[hidden] { display: none; }
.auth-modal-card { width: min(100%, 980px); max-height: min(90vh, 720px); overflow: auto; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.seal-confirmation-card { width: min(100%, 680px); }
.seal-confirmation-list { display: grid; gap: 10px; }
.seal-confirmation-item { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
.seal-confirmation-details { min-width: 0; }
.seal-confirmation-details p { margin: 0 0 5px; font-size: 13px; }
.seal-confirmation-details p:last-child { margin-bottom: 0; }
.seal-confirmation-actions { display: flex; flex: 0 0 auto; gap: 8px; white-space: nowrap; }
.seal-confirmation-actions button { min-height: 34px; }
.bulk-update-card { width: min(100%, 560px); }
.bulk-update-actions { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.bulk-update-actions input { min-width: 0; }
.bulk-update-result { min-height: 22px; margin: 12px 0 0; color: var(--ink); font-size: 13px; white-space: pre-wrap; }
.account-list { display: grid; gap: 4px; }
.account-list span { display: block; white-space: nowrap; }
.user-form, .password-form { display: grid; gap: 9px; margin-top: 12px; }
.user-toolbar { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.user-toolbar button { min-width: 72px; }
.user-form[hidden] { display: none; }
.user-enabled { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.user-enabled input { min-height: 16px; width: 16px; }
.permission-fieldset { margin: 4px 0 0; padding: 10px; border: 1px solid var(--line); }
.permission-fieldset legend { padding: 0 5px; font-size: 13px; font-weight: 700; }
.permission-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px 12px; }
.permission-grid label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.permission-grid input { width: 15px; min-height: 15px; accent-color: var(--accent); }
.permission-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.permission-group { border: 1px solid var(--line); background: var(--surface-2); }
.permission-group summary { padding: 8px 10px; cursor: pointer; font-size: 13px; font-weight: 700; list-style-position: inside; }
.permission-group-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px 12px; padding: 9px 10px; background: var(--surface); }
.user-table-wrap { margin-top: 16px; overflow: auto; }
.user-table-wrap table { width: 100%; min-width: 760px; border-collapse: collapse; }
.user-table-wrap th, .user-table-wrap td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
.user-table-wrap tbody tr { cursor: pointer; }
.user-table-wrap tbody tr:hover, .user-table-wrap tbody tr.selected-user-row { background: #e8f3ef; }
.user-table-wrap .user-role-group-row { cursor: default; }
.user-table-wrap .user-role-group-row:hover { background: transparent; }
.user-table-wrap .user-role-group-row td { padding: 0; border-bottom: 1px solid var(--line); }
.user-role-group-toggle { display: flex; align-items: center; width: 100%; min-height: 40px; gap: 9px; padding: 8px 10px; border: 0; background: #f3f7f5; color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; text-align: left; cursor: pointer; }
.user-role-group-toggle:hover, .user-role-group-toggle:focus-visible { background: #e8f3ef; outline: none; }
.user-role-group-toggle strong { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #d9ebe4; color: #0c6b57; font-size: 12px; }
.user-role-group-chevron { width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 6px solid #547269; transition: transform .16s ease; }
.user-role-group-toggle[aria-expanded="true"] .user-role-group-chevron { transform: rotate(90deg); }
.user-table-wrap .user-role-member-row td:first-child { padding-left: 26px; }
@media (max-width: 980px) {
  .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .permission-group-items { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  .seal-loan-view {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .seal-loan-form-panel {
    max-height: none;
    overflow: visible;
  }
  .seal-loan-list-panel {
    height: auto;
    min-height: 420px;
  }
}
@media (max-width: 980px) {
  .invoice-view {
    grid-template-columns: 1fr;
  }

  .invoice-form-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .invoice-list-panel {
    height: auto;
    min-height: 420px;
  }
}

.form-panel,
.list-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  position: sticky;
  top: 18px;
  padding: 9px;
}

.form-panel form {
  gap: 6px;
  margin-top: 8px;
}

.form-panel label {
  gap: 3px;
  font-size: 12px;
}

.form-panel input,
.form-panel select,
.form-panel textarea {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.form-panel textarea {
  min-height: 62px;
}

.form-panel .two-col {
  gap: 6px;
}

.form-panel .switch-row {
  gap: 8px;
  padding: 7px;
}

.form-panel .switch-row input {
  min-height: 24px;
}

.form-panel .primary-button,
.form-panel .ghost-button {
  min-height: 34px;
  padding: 0 10px;
}

.panel-title,
.list-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

form {
  display: grid;
  gap: 11px;
  margin-top: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #304039;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 92px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(36, 107, 219, 0.13);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.switch-row input {
  width: 46px;
  height: 26px;
  min-height: 26px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: #aab5af;
  position: relative;
  transition: background 0.2s ease;
}

.switch-row input::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.switch-row input:checked {
  background: var(--accent);
}

.switch-row input:checked::after {
  transform: translateX(20px);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.secondary-button {
  color: var(--accent);
  background: #e7f2ef;
  border-color: #b9d6ce;
}

.ghost-button {
  color: var(--muted);
  background: #fff;
  border-color: var(--line);
}

.danger-button {
  color: var(--accent-2);
  background: #fbebe7;
  border-color: #ecc7bd;
}

.list-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 36px);
  min-width: 0;
  overflow: hidden;
}

.list-tools {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  justify-content: flex-end;
}

.import-actions {
  position: relative;
}

.import-menu-trigger {
  position: relative;
  padding-right: 32px;
}

.import-menu-trigger::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
  transform: translateY(-35%);
  transition: transform .15s ease;
}

.import-menu-trigger[aria-expanded="true"]::after {
  transform: translateY(-65%) rotate(180deg);
}

.import-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 156px;
  padding: 5px;
  border: 1px solid #cbd8d4;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(23, 33, 29, .18);
}

.import-menu button {
  min-height: 34px;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.import-menu button:hover,
.import-menu button:focus-visible {
  background: #e8f3ef;
  outline: none;
}

.table-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  max-width: 100%;
}

table {
  width: max-content;
  border-collapse: collapse;
  min-width: 2600px;
  table-layout: fixed;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
  overflow-wrap: normal;
  word-break: normal;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #425049;
  background: #f9fbfa;
  font-size: 12px;
  box-shadow: 0 1px 0 var(--line);
}

.filter-row th {
  top: 43px;
  z-index: 2;
  padding-top: 0;
  background: #f9fbfa;
  box-shadow: 0 1px 0 var(--line);
}

.filter-row input,
.filter-row select {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 12px;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

td {
  color: #26342f;
}

th:nth-child(1),
td:nth-child(1) {
  position: sticky;
  left: 0;
  width: 190px;
  background: var(--surface);
  box-shadow: 2px 0 0 var(--line);
}

th:nth-child(1) {
  z-index: 4;
  background: #f9fbfa;
}

.filter-row th:nth-child(1) {
  z-index: 5;
}

th:nth-child(2),
td:nth-child(2) {
  width: 220px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 120px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 90px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 110px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 100px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 220px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 180px;
}

th:nth-child(9),
td:nth-child(9) {
  width: 190px;
}

th:nth-child(10),
td:nth-child(10) {
  width: 150px;
}

th:nth-child(11),
td:nth-child(11) {
  width: 110px;
}

th:nth-child(12),
td:nth-child(12) {
  width: 330px;
}

th:nth-child(13),
td:nth-child(13) {
  width: 90px;
}

th:nth-child(14),
td:nth-child(14) {
  width: 110px;
}

th:nth-child(15),
td:nth-child(15) {
  width: 90px;
}

th:nth-child(16),
td:nth-child(16) {
  width: 150px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.badge.opened {
  color: #0e624f;
  background: #ddf3ed;
}

.badge.pending {
  color: #955225;
  background: #f9eadb;
}

.store-list {
  display: grid;
  gap: 5px;
  min-width: 180px;
}

.store-item {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  border-radius: 6px;
  padding: 4px 7px;
  color: #20332d;
  background: #eaf3f0;
  line-height: 1.35;
  word-break: break-word;
}

.row-actions {
  white-space: nowrap;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.image-preview img,
.image-link img {
  display: block;
  width: 54px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid var(--line);
  object-fit: cover;
}

.image-link {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
}

.row-actions button + button {
  margin-left: 8px;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.image-modal.visible {
  display: flex;
}

.image-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 27, 24, 0.68);
}

.image-modal__content {
  position: relative;
  z-index: 1;
  width: min(100%, 980px);
  max-height: calc(100vh - 48px);
  padding: 44px 14px 14px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.image-modal__content img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 110px);
  margin: 0 auto;
  object-fit: contain;
}

.image-modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-weight: 700;
}

.empty-state {
  display: none;
  padding: 50px 16px;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

@media (max-width: 980px) {
  .workspace,
  .two-col {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .list-panel {
    position: static;
    display: block;
    height: auto;
  }
}

@media (min-width: 981px) and (max-width: 1280px) {
  .form-panel .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 10px, 1920px);
    padding: 10px 0;
  }

  .table-wrap {
    max-height: none;
  }

  .topbar,
  .list-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

  .stats div {
    flex: 1;
    min-width: 0;
  }

  .secondary-button {
    width: 100%;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  th:nth-child(1),
  td:nth-child(1),
  .filter-row th:nth-child(1) {
    position: static;
    box-shadow: none;
  }

  thead {
    display: none;
  }

  tr {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    padding: 7px 0;
    word-break: break-word;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .row-actions {
    white-space: normal;
  }
}

@media (max-width: 980px) {
  .workspace#licenseView {
    height: auto;
    overflow: visible;
  }

  .workspace#licenseView > .form-panel {
    height: auto;
    overflow: visible;
  }
}
