:root {
  color-scheme: light;
  --ink: #172b2a;
  --muted: #6d7e7b;
  --accent: #137463;
  --accent-dark: #0b594c;
  --accent-soft: #e9f5f0;
  --line: #dce8e4;
  --surface: #ffffff;
  --page: #f4f8f6;
  --warning: #8b5b21;
  --warning-bg: #fff8eb;
  --danger: #ac493c;
  --shadow: 0 16px 42px rgba(23, 63, 54, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.6 "Segoe UI", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button, input, select { border-radius: 9px; }
input:not([type="checkbox"]), select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 12px;
}
input:not([type="checkbox"]):focus, select:focus { border-color: var(--accent); outline: 3px solid rgba(19, 116, 99, .15); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(19, 116, 99, .3); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { max-width: 1240px; min-height: 100vh; margin: 0 auto; padding: 28px 30px 48px; }
.login-view { display: grid; min-height: calc(100vh - 76px); place-items: center; }
.login-card { width: min(100%, 420px); padding: 42px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 48px; height: 48px; margin-bottom: 24px; place-items: center; border-radius: 14px; background: var(--accent); color: #fff; font-size: 24px; font-weight: 700; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
.login-card h1 { margin-bottom: 6px; font-size: 28px; letter-spacing: -.02em; }
.subtle { color: var(--muted); }
.stack-form { display: grid; gap: 16px; margin-top: 28px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }
.wide { width: 100%; margin-top: 4px; }

.admin-view { width: 100%; }
.topbar, .panel-heading, .toolbar, .pagination, .topbar-actions, .toolbar-actions, .actions, .withdraw-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar { margin-bottom: 22px; }
.page-title { margin: 0; font-size: 30px; letter-spacing: -.03em; }
.topbar-actions { justify-content: flex-end; }
.user-chip { padding: 6px 11px; border: 1px solid var(--line); border-radius: 30px; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; }

.button { border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 9px 14px; font-size: 13px; font-weight: 600; transition: background .15s, border-color .15s, transform .15s; }
.button:hover:not(:disabled) { border-color: #a8c8bd; background: var(--accent-soft); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { border-color: var(--accent-dark); background: var(--accent-dark); }
.button.ghost { background: transparent; }
.button.small { padding: 5px 9px; font-size: 12px; }
.message { min-height: 24px; margin: 12px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.error, .error { color: var(--danger); }
.global-message { min-height: 0; margin: 0 0 14px; color: var(--accent-dark); }
.global-message.error { padding: 10px 13px; border-radius: 9px; background: #fff1ef; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 25px; }
.stat-card { min-width: 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; margin-top: 2px; font-size: 28px; font-variant-numeric: tabular-nums; }
.stat-card.available { border-color: #cfe8dc; background: #eef9f3; }
.stat-card.available strong { color: var(--accent); }
.stat-card.used strong { color: #876b2d; }
.stat-card.reserved strong { color: #7a668e; }

.tabs { display: flex; gap: 3px; margin-bottom: 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; background: transparent; padding: 12px 24px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.tab:hover { color: var(--accent); }
.tab.active, .tab[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }
.tab-panel { padding: 26px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 5px 18px rgba(23, 63, 54, .03); }
.panel-heading { margin-bottom: 21px; }
.panel-heading.compact { margin-bottom: 12px; }
.panel-heading h2 { margin: 0; font-size: 20px; }
.panel-heading h3 { margin: 0; font-size: 16px; }

.filter-grid, .form-grid, .settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.inventory-search { grid-template-columns: minmax(240px, 1fr) auto; align-items: end; }
.filter-actions { display: flex; align-items: end; gap: 8px; padding-top: 21px; }
.inventory-search .filter-actions { padding-top: 0; }
.filter-actions .button { flex: 1; }
.toolbar { margin: 25px 0 13px; padding-top: 18px; border-top: 1px solid var(--line); }
.selection-summary { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.selection-summary strong { color: var(--accent-dark); }
.selection-summary span { color: var(--muted); font-size: 12px; }
.inventory-export-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 15px; flex-wrap: wrap; margin: 16px 0 8px; padding-top: 15px; border-top: 1px solid var(--line); }
.inventory-export-toolbar > div:first-child { display: flex; flex-direction: column; gap: 4px; }
.inventory-export-controls { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.inline-field { min-width: 190px; }
.inventory-export-controls .inline-field { margin: 0; }
#inventoryExportCount { width: 145px; }
#inventoryExportMessage { margin: 0 0 10px; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; min-width: 830px; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
th { background: #f7faf8; color: var(--muted); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdfc; }
th:first-child, td:first-child { width: 44px; text-align: center; }
th:nth-child(2) { width: 22%; }
th:nth-child(3), th:nth-child(4) { width: 15%; }
th:nth-child(5) { width: 14%; }
th:nth-child(6) { width: 9%; }
td.credential { font-family: Consolas, "Courier New", monospace; }
.masked { color: #9aa9a5; letter-spacing: .08em; }
.status { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; white-space: nowrap; }
.status.available { background: #e7f6ed; color: #167155; }
.status.used { background: #fff5db; color: #89641f; }
.status.reserved { background: #f2ebf8; color: #765184; }
.history-note { margin: 8px 0 13px; font-size: 12px; }
.history-list + .empty-state { margin-top: 8px; }
.empty-state { padding: 28px; color: var(--muted); text-align: center; }
.pagination { justify-content: flex-start; margin-top: 14px; color: var(--muted); font-size: 12px; }
.pagination #nextPageButton { order: 2; }
.pagination #pageSummary { order: 1; min-width: 90px; text-align: center; }
.pagination #previousPageButton { order: 0; }
.page-size { display: flex; align-items: center; gap: 6px; margin-left: auto; white-space: nowrap; }
.page-size select, .history-limit select { width: auto; padding: 6px 8px; }

.notice { margin-bottom: 21px; padding: 12px 15px; border: 1px solid #f0debb; border-radius: 10px; background: var(--warning-bg); color: var(--warning); font-size: 12px; }
.notice strong { display: block; margin-bottom: 2px; }
.dropzone { padding: 37px 20px; border: 1.5px dashed #b8d1c5; border-radius: 12px; background: #f8fbf9; text-align: center; transition: background .15s, border-color .15s; }
.dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.drop-title { margin-bottom: 5px; font-size: 16px; font-weight: 700; }
.file-preview { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; }
.summary-line { margin-bottom: 10px; color: var(--accent-dark); font-weight: 700; }
.plain-list { margin: 0 0 15px; padding: 0; list-style: none; }
.plain-list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.compact-list { max-height: 220px; overflow: auto; }
.compact-list li { display: block; font-family: Consolas, "Courier New", monospace; font-size: 12px; }

.export-options { display: flex; align-items: end; gap: 18px; flex-wrap: wrap; margin: 21px 0 16px; }
.check-label { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; color: var(--ink); font-size: 13px; }
.custom-count-field { width: min(100%, 260px); }
.column-order { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #fbfdfc; color: var(--muted); font-size: 12px; }
.column-button { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 5px 10px; color: var(--muted); font-size: 12px; }
.column-button.selected { border-color: #9bc8b8; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.withdraw-actions { justify-content: flex-start; margin-top: 22px; }
.selected-preview { margin-top: 27px; padding-top: 20px; border-top: 1px solid var(--line); }
.selected-preview h3 { margin-bottom: 4px; font-size: 15px; }

.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 28px; }
.setting-card { padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; }
.setting-card h3 { margin-bottom: 6px; font-size: 15px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.history-section { padding-top: 20px; border-top: 1px solid var(--line); }
.history-limit { flex-direction: row; align-items: center; }
.history-card { padding: 15px 0; border-bottom: 1px solid var(--line); }
.history-card:first-child { padding-top: 2px; }
.history-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.history-meta strong { color: var(--accent-dark); }
.history-meta time { color: var(--muted); font-size: 12px; }
.history-details { margin: 6px 0 9px; color: var(--muted); font-size: 12px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 860px) {
  .filter-grid, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .app-shell { padding: 17px 13px 32px; }
  .login-card { padding: 28px 22px; }
  .tab-panel { padding: 18px 15px; }
  .filter-grid, .form-grid, .settings-grid, .inventory-search { grid-template-columns: 1fr; }
  .filter-actions, .inventory-search .filter-actions { padding-top: 3px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .page-title { font-size: 26px; }
  .stat-card { padding: 13px; }
  .stat-card strong { font-size: 23px; }
  .tabs { margin-right: -15px; margin-left: -15px; padding: 0 6px; }
  .tab { padding: 11px 13px; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .button { flex: 1; }
  .inventory-export-toolbar { align-items: stretch; }
  .inventory-export-controls { align-items: stretch; width: 100%; }
  .inventory-export-controls .inline-field { flex: 1; min-width: 0; }
  .inventory-export-controls .button { flex: 1; }
  .pagination { gap: 7px; }
  .page-size { width: 100%; margin-left: 0; }
  .export-options { align-items: stretch; flex-direction: column; gap: 4px; }
  .custom-count-field { width: 100%; margin-top: 6px; }
  .withdraw-actions .button { width: 100%; }
}
