:root {
  --ink: #17201e;
  --muted: #69736f;
  --paper: #f3f3ed;
  --sheet: #fffefa;
  --line: #d8dcd6;
  --line-dark: #b9c1bb;
  --accent: #137461;
  --accent-soft: #dceddf;
  --accent-ink: #0b493d;
  --banner-start: #0c4f43;
  --banner-end: #167762;
  --danger: #b84835;
  --shadow: 0 18px 50px rgba(37, 50, 45, .08);
  --display: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --body: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", "IBM Plex Mono", Consolas, monospace;
}

body[data-business="usd"] {
  --accent: #b46618;
  --accent-soft: #f5e4c7;
  --accent-ink: #70400f;
  --banner-start: #75400f;
  --banner-end: #ba6818;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent);
  font: 700 11px/1 var(--mono);
  letter-spacing: .12em;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(440px, 1.1fr) minmax(390px, .9fr);
}

.login-brand {
  display: flex;
  min-height: 100vh;
  padding: 54px clamp(48px, 7vw, 108px);
  flex-direction: column;
  justify-content: space-between;
  color: #f8faf6;
  background:
    radial-gradient(circle at 76% 21%, rgba(113, 210, 179, .22), transparent 27%),
    linear-gradient(145deg, #0c312a 0%, #154d42 100%);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 11px;
  font: 750 13px/1 var(--display);
  letter-spacing: .1em;
}

.brand-mark span {
  width: 15px;
  height: 15px;
  border: 4px solid #a7e0ca;
  border-radius: 50%;
}

.login-brand .eyebrow { color: #a7e0ca; }
.login-brand h1 {
  margin: 0;
  font: 680 clamp(48px, 5.8vw, 82px)/1.06 var(--display);
  letter-spacing: -.055em;
}

.login-brand p:not(.eyebrow) {
  max-width: 480px;
  margin: 28px 0 0;
  color: rgba(248, 250, 246, .67);
  font-size: 16px;
}

.login-brand small { color: rgba(248, 250, 246, .52); }

.login-panel {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 48px;
  background:
    linear-gradient(rgba(23, 32, 30, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 30, .04) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
}

.login-card {
  width: min(100%, 410px);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 4px 30px 4px 4px;
  background: rgba(255, 254, 250, .95);
  box-shadow: var(--shadow);
}

.login-card header { margin-bottom: 30px; }
.login-card h2 { margin: 0; font: 700 29px/1.2 var(--display); letter-spacing: -.03em; }

label, .field-block { display: grid; gap: 8px; }
.login-card label { margin-bottom: 18px; }
label > span, .field-label { color: #48524f; font-size: 12px; font-weight: 700; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--ink);
  background: var(--sheet);
  transition: border-color .16s, box-shadow .16s;
}

input, select { height: 44px; padding: 0 12px; }
textarea { min-height: 96px; padding: 11px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}

.button {
  display: inline-flex;
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s, background .15s, border-color .15s;
}

.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .44; cursor: not-allowed; transform: none; }
.button.primary { color: white; background: var(--accent); }
.button.primary:hover { background: var(--accent-ink); }
.button.ghost { border-color: var(--line); background: var(--sheet); }
.button.wide { width: 100%; justify-content: space-between; }
.form-error { min-height: 18px; margin: -5px 0 10px; color: var(--danger); font-size: 12px; }

.app-shell { min-height: 100vh; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  min-height: 72px;
  padding: 0 clamp(22px, 4vw, 58px);
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, .94);
  backdrop-filter: blur(14px);
}

.brand-lockup, .user-menu { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 15px;
  height: 15px;
  border: 4px solid var(--accent);
  border-radius: 50%;
}

.brand-lockup div, .user-menu div { display: grid; gap: 2px; }
.brand-lockup strong { font: 760 14px/1 var(--display); }
.brand-lockup small, .user-menu small { color: var(--muted); font-size: 10px; }

.main-nav { display: flex; justify-content: center; gap: 4px; }
.main-nav button {
  padding: 9px 13px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.main-nav button:hover, .main-nav button.active { color: var(--ink); background: #ebece7; }
.user-menu { justify-content: flex-end; text-align: right; }
.user-menu strong { font-size: 12px; }

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  place-items: center;
  background: transparent;
  cursor: pointer;
}

.icon-button.large { width: 38px; height: 38px; font-size: 23px; }
.workspace { width: min(100%, 1540px); margin: 0 auto; padding: 44px clamp(22px, 4vw, 58px) 80px; }
.view { display: none; }
.view.active-view { display: block; }

.ledger-header, .simple-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 28px;
}

.ledger-header {
  padding: clamp(24px, 3.2vw, 42px);
  border-radius: 16px;
  color: white;
  background:
    radial-gradient(circle at 86% 0%, rgba(255, 255, 255, .16), transparent 36%),
    linear-gradient(130deg, var(--banner-start), var(--banner-end));
  box-shadow: 0 20px 46px color-mix(in srgb, var(--accent) 22%, transparent);
}

.ledger-header .eyebrow { color: rgba(255, 255, 255, .68); }
.ledger-header .subcopy { color: rgba(255, 255, 255, .72); }
.ledger-header .button.primary { color: var(--accent-ink); background: white; }
.ledger-header .button.primary:hover { background: rgba(255, 255, 255, .9); }

.ledger-header h1, .simple-header h1 {
  margin: 0;
  font: 700 clamp(31px, 3.4vw, 48px)/1.05 var(--display);
  letter-spacing: -.05em;
}

.subcopy, .simple-header p:last-child { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.ledger-actions { display: flex; align-items: center; gap: 12px; }
.business-tabs {
  display: flex;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 10px;
  background: rgba(0, 0, 0, .13);
}
.business-tabs button {
  display: flex;
  height: 35px;
  padding: 0 13px;
  border: 0;
  border-radius: 7px;
  align-items: center;
  gap: 7px;
  color: rgba(255, 255, 255, .67);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.business-tabs button.active { color: var(--accent-ink); background: white; box-shadow: 0 2px 8px rgba(23, 32, 30, .14); }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.ledger-summary {
  display: grid;
  grid-template-columns: max-content max-content 1fr;
  min-height: 90px;
  margin-bottom: 12px;
  padding: 18px 22px;
  align-items: center;
  gap: 36px;
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  background: var(--sheet);
}

.ledger-summary > div { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 5px; }
.ledger-summary small { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.ledger-summary strong { margin-top: 5px; font: 730 28px/1 var(--display); }
.ledger-summary span { color: var(--muted); font-size: 11px; }
.ledger-summary p {
  justify-self: end;
  margin: 0;
  padding: 7px 10px;
  border-radius: 100px;
  color: var(--muted);
  background: #f0f1ec;
  font-size: 11px;
}

.ledger-summary p.connected { color: var(--accent-ink); background: var(--accent-soft); }
.filter-bar {
  display: flex;
  min-height: 62px;
  padding: 10px 16px;
  align-items: center;
  gap: 22px;
  border: 1px solid var(--line);
  background: var(--sheet);
}

.filter-group { display: flex; align-items: center; gap: 3px; }
.filter-group > span, .sort-control > span { margin-right: 5px; color: var(--muted); font-size: 11px; font-weight: 650; }
.filter-group button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  cursor: pointer;
}

.filter-group button:hover, .filter-group button.active { color: var(--accent-ink); background: var(--accent-soft); }
.sort-control { display: flex; margin-left: auto; align-items: center; gap: 3px; }
.sort-control select { width: 132px; height: 32px; padding: 0 8px; border: 0; background: #f0f1ec; font-size: 11px; }

.table-sheet {
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1050px; border-collapse: collapse; }
th {
  height: 43px;
  padding: 0 13px;
  border-bottom: 1px solid var(--line-dark);
  color: var(--muted);
  background: #f4f5f0;
  text-align: left;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .04em;
}

td { padding: 14px 13px; border-bottom: 1px solid #e7e9e4; font-size: 12px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 34%, white); }
tbody tr.is-used { color: #8b928f; background: #fafaf7; }
.code-cell { display: flex; min-width: 270px; align-items: center; gap: 9px; }
.code-cell code { font: 650 11px/1.4 var(--mono); word-break: break-all; }
.copy-button {
  max-width: 300px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: 650 11px/1.4 var(--mono);
  text-align: left;
  cursor: pointer;
  word-break: break-all;
}

.copy-button:hover { color: var(--accent); }
.amount-cell { white-space: nowrap; font: 750 13px/1 var(--mono); }
.cell-stack { display: grid; gap: 3px; }
.cell-stack small, .date-cell small { color: var(--muted); }
.date-cell { white-space: nowrap; font-size: 11px; }
.badge {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 100px;
  align-items: center;
  color: #48524f;
  background: #eceee9;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.badge.available { color: var(--accent-ink); background: var(--accent-soft); }
.badge.used { color: #6e7471; background: #e6e7e3; }
.badge.trial { color: #275b7a; background: #dcebf3; }
.badge.paid { color: #79531a; background: #f3e7cc; }
.badge.muted { color: #777c79; background: #eeefeb; }
.sync-button, .small-button, .text-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--sheet);
  font-size: 10px;
  cursor: pointer;
}

.sync-button { padding: 6px 8px; }
.small-button { height: 31px; padding: 0 11px; }
.small-button:disabled { opacity: .35; cursor: default; }
.text-button { padding: 6px 9px; color: var(--accent); }
.table-empty, .page-empty { padding: 48px 18px; color: var(--muted); text-align: center; }
.table-empty { display: grid; gap: 7px; }
.table-empty span { font-size: 11px; }
.pagination { display: flex; min-height: 54px; padding: 0 16px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); background: #fafaf7; }
.pagination span { color: var(--muted); font-size: 11px; }
.pagination div { display: flex; gap: 7px; }

.record-list, .settings-grid { display: grid; gap: 12px; }
.record-row, .case-row, .settings-section {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--sheet);
}

.record-row, .case-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.record-row h3, .case-row h3, .settings-section h2 { margin: 0; font: 700 16px/1.2 var(--display); }
.record-row p, .case-row p, .muted-copy { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-section header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.settings-section header small { color: var(--muted); font-size: 10px; }
.settings-list { display: grid; gap: 7px; }
.settings-row, .audit-row { display: flex; padding: 11px 12px; align-items: center; justify-content: space-between; gap: 14px; border-radius: 7px; background: #f2f3ee; font-size: 11px; }
.settings-row div, .audit-row div { display: grid; gap: 3px; }
.settings-row small, .audit-row small { color: var(--muted); }

dialog {
  width: min(94vw, 660px);
  max-height: 90vh;
  padding: 0;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  background: transparent;
  box-shadow: 0 32px 90px rgba(18, 27, 24, .25);
}

dialog::backdrop { background: rgba(20, 28, 25, .54); backdrop-filter: blur(4px); }
.modal-sheet { max-height: 90vh; overflow-y: auto; background: var(--sheet); }
.modal-sheet > header { position: sticky; z-index: 2; top: 0; display: flex; padding: 24px 26px 18px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--sheet); }
.modal-sheet h2 { margin: 0; font: 700 23px/1.2 var(--display); }
.modal-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 24px 26px 27px; }
.modal-form .full, .modal-context, .modal-actions, .created-result { grid-column: 1 / -1; }
.modal-context { display: flex; padding: 12px 14px; align-items: center; justify-content: space-between; border-radius: 8px; color: var(--accent-ink); background: var(--accent-soft); font-size: 12px; }
.choice-tabs, .preset-line { display: flex; gap: 7px; flex-wrap: wrap; }
.choice-tabs button, .preset-line button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sheet);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.choice-tabs button.active, .preset-line button.active { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.fixed-amount { padding: 15px; border-radius: 8px; color: var(--accent-ink); background: var(--accent-soft); font: 750 20px/1 var(--mono); }
.paid-amount-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.money-input { position: relative; display: block; }
.currency-mark { position: absolute; z-index: 1; top: 12px; left: 12px; color: var(--muted); font-weight: 600; }
.money-input input { padding-left: 27px; }
.date-field input { cursor: pointer; }
.date-field small { color: var(--muted); font-size: 10px; }
.field-hint { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.modal-actions { display: flex; padding-top: 6px; justify-content: flex-end; gap: 8px; }
.created-result { padding: 15px; border: 1px solid var(--accent); border-radius: 9px; background: var(--accent-soft); }
.created-result textarea { margin-top: 10px; font-family: var(--mono); font-size: 11px; }

.toast-region { position: fixed; z-index: 80; right: 22px; bottom: 22px; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 15px; border-radius: 8px; color: white; background: #20312d; box-shadow: var(--shadow); font-size: 12px; }
.toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .app-header { grid-template-columns: 170px 1fr auto; padding-inline: 20px; }
  .user-menu div { display: none; }
  .ledger-header { align-items: flex-start; flex-direction: column; }
  .ledger-actions { width: 100%; justify-content: space-between; }
  .filter-bar { align-items: flex-start; flex-wrap: wrap; }
  .sort-control { margin-left: 0; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-panel { padding: 22px; }
  .app-header { position: static; display: flex; min-height: auto; padding: 15px 16px; flex-wrap: wrap; justify-content: space-between; }
  .main-nav { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .workspace { padding: 30px 16px 60px; }
  .ledger-actions { align-items: stretch; flex-direction: column; }
  .business-tabs { width: 100%; }
  .business-tabs button { flex: 1; justify-content: center; }
  .ledger-summary { grid-template-columns: 1fr 1fr; gap: 16px; }
  .ledger-summary p { grid-column: 1 / -1; justify-self: stretch; text-align: center; }
  .filter-group { width: 100%; overflow-x: auto; }
  .modal-form { grid-template-columns: 1fr; padding-inline: 18px; }
  .modal-form > * { grid-column: 1 !important; }
  .paid-amount-grid { grid-template-columns: 1fr; }
}
