:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #f0f2ec;
  --surface-accent: #f4f8dc;
  --text: #20231d;
  --muted: #6b7165;
  --faint: #949a8e;
  --line: #dde1d8;
  --line-strong: #c7ccc1;
  --accent: #9ab62d;
  --accent-strong: #617715;
  --warning: #a56b12;
  --danger: #b63c37;
  --success: #387b4b;
  --shadow: 0 1px 2px rgba(25, 32, 19, 0.05), 0 8px 24px rgba(25, 32, 19, 0.04);
  --radius-input: 6px;
  --radius-card: 8px;
  --radius-modal: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: 3px solid rgba(154, 182, 45, 0.35); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--text); color: white; padding: 10px 14px; border-radius: 6px; }
.skip-link:focus { top: 12px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f1f3ed; }
.login-panel { width: min(420px, 100%); background: var(--surface); border: 1px solid rgba(199, 204, 193, 0.8); border-radius: var(--radius-modal); box-shadow: var(--shadow); padding: 32px; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 16px; font-weight: 720; background: var(--text); color: white; border-radius: 8px; padding: 6px 10px; }
.brand-logo { width: 128px; height: 38px; object-fit: contain; object-position: left center; flex: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px 7px 7px 3px; background: var(--text); position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 7px; height: 7px; border-radius: 50%; background: #c5dd55; right: 4px; top: 4px; }
.login-panel h1 { margin: 42px 0 8px; font-size: 28px; letter-spacing: 0; }
.login-panel > p { color: var(--muted); margin: 0 0 28px; }

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 650; color: #494e45; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; border: 1px solid var(--line-strong); border-radius: var(--radius-input); background: white; color: var(--text); padding: 10px 12px; }
.field textarea { resize: vertical; min-height: 80px; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #9da595; }
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; margin: 0 0 8px; }
.button { min-height: 44px; border: 1px solid transparent; border-radius: var(--radius-input); padding: 9px 15px; font-weight: 680; color: var(--text); background: var(--surface-soft); }
.button.primary { background: var(--text); color: white; width: 100%; }
.button.secondary { background: white; border-color: var(--line-strong); }
.button.danger { color: var(--danger); background: #fff5f4; border-color: #f0cfcc; }
.button.small { min-height: 36px; padding: 6px 11px; font-size: 13px; }
.button:active { transform: scale(0.98); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: #eef0ea; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.sidebar .brand { padding: 4px 8px 24px; gap: 8px; }
.sidebar .brand span { font-size: 13px; color: #d4dbcf; white-space: nowrap; }
.role-label { margin: 8px 10px 6px; font-size: 12px; color: var(--faint); }
.nav { display: grid; gap: 3px; }
.nav button { position: relative; min-height: 44px; border: 0; border-radius: 6px; background: transparent; color: #565c51; padding: 10px 12px 10px 17px; text-align: left; font-weight: 620; }
.nav button[aria-current="page"] { background: rgba(154, 182, 45, 0.13); color: var(--accent-strong); }
.nav button[aria-current="page"]::before { content: ""; position: absolute; left: 6px; top: 13px; bottom: 13px; width: 3px; border-radius: 3px; background: var(--accent); }
.sidebar-user { margin-top: auto; border-top: 1px solid var(--line); padding: 16px 8px 0; }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { font-size: 12px; color: var(--muted); margin-top: 3px; }
.logout { border: 0; background: transparent; color: var(--muted); padding: 12px 0 4px; min-height: 44px; }

.main { min-width: 0; padding: 24px; }
.topbar { min-height: 56px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.topbar h1 { font-size: 25px; margin: 0 0 5px; letter-spacing: 0; }
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }
.sync-state { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.active { background: var(--success); }
.dot.warning { background: var(--warning); }

.metrics { display: grid; grid-template-columns: minmax(230px, 1.35fr) repeat(3, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric { min-height: 128px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 17px; box-shadow: 0 1px 1px rgba(25, 32, 19, 0.02); }
.metric.hero { background: var(--surface-accent); border-color: #dce7aa; }
.metric-label { color: var(--muted); font-size: 13px; font-weight: 620; }
.metric-value { margin: 17px 0 7px; font-size: 28px; font-weight: 760; font-variant-numeric: tabular-nums; }
.metric.hero .metric-value { color: var(--accent-strong); font-size: 36px; }
.metric-note { font-size: 12px; color: var(--faint); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 0.9fr); gap: 16px; align-items: start; }
.content-grid > * { min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: 0 1px 1px rgba(25, 32, 19, 0.02); }
.panel-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 17px; border-bottom: 1px solid var(--line); }
.panel-header h2 { font-size: 15px; margin: 0; }
.panel-header p { font-size: 12px; color: var(--muted); margin: 3px 0 0; }
.panel-body { padding: 17px; }
.table-wrap { overflow-x: auto; scrollbar-gutter: stable; }
.table-footer { display: flex; justify-content: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.table-footer .button { min-width: 112px; }
.table-footer.pager { align-items: center; justify-content: space-between; gap: 16px; }
.pager-status { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pager-actions { display: flex; gap: 8px; }
.pager-actions .button { min-width: 88px; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th { color: var(--muted); font-size: 12px; font-weight: 620; text-align: left; white-space: nowrap; padding: 11px 14px; background: #fafbf8; border-bottom: 1px solid var(--line); }
td { height: 46px; padding: 9px 14px; border-bottom: 1px solid #eceee9; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
td.number, th.number { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background-color 120ms ease, box-shadow 120ms ease; }
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }

.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar button { min-height: 38px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 7px 12px; color: var(--muted); }
.toolbar button[aria-pressed="true"] { color: var(--accent-strong); background: var(--surface-accent); border-color: #dce7aa; }
.section-stack { display: grid; gap: 16px; }
.section-stack > * { min-width: 0; }
.detail-intro { margin-bottom: 18px; }
.detail-breakdown { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.detail-breakdown + .panel, .detail-intro ~ .panel { margin-bottom: 16px; }
.split-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; grid-column: 1 / -1; }
.form-actions .button.primary { width: auto; }
.notice { border: 1px solid #ead7b2; background: #fffaf0; color: #7b581f; border-radius: 7px; padding: 12px 14px; font-size: 13px; }
.money { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.tab-actions { display: flex; gap: 6px; }
.invite-panel { margin-bottom: 16px; }
.invite-row { display: flex; gap: 10px; align-items: center; }
.invite-row input { flex: 1; min-width: 0; min-height: 44px; border: 1px solid var(--line-strong); border-radius: var(--radius-input); background: white; color: var(--text); padding: 10px 12px; }
.invite-row .button.primary { width: auto; flex: none; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 360px; border-radius: 8px; background: var(--text); color: white; padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; }

@media (hover: hover) and (pointer: fine) {
  .nav button:hover, .toolbar button:hover { background: rgba(255, 255, 255, 0.65); color: var(--text); }
  tbody tr:hover { background: #fafbf8; box-shadow: inset 3px 0 var(--accent); }
  .button:hover { filter: brightness(0.97); }
}

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
}

@media (min-width: 761px) and (max-width: 1180px) {
  .main { padding: 20px; }
  .content-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr); }
  th, td { padding-left: 10px; padding-right: 10px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { padding: 4px 6px 12px; }
  .role-label, .sidebar-user { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav button { padding: 8px 13px; }
  .brand-logo { width: 112px; height: 34px; }
  .nav button[aria-current="page"]::before { left: 13px; right: 13px; top: auto; bottom: 3px; width: auto; height: 3px; }
  .main { padding: 18px 14px 28px; }
  .topbar { min-height: auto; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .detail-breakdown { grid-template-columns: 1fr; }
  .metric { min-height: 112px; }
  .split-form { grid-template-columns: 1fr; }
  .form-actions { grid-column: auto; }
  .table-footer.pager { align-items: stretch; flex-direction: column; }
  .pager-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .pager-actions .button { width: 100%; }
  .invite-row { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
  .login-shell { padding: 14px; background: var(--bg); }
  .login-panel { padding: 24px 20px; }
  .metrics { grid-template-columns: 1fr; }
  .topbar { display: block; }
  .sync-state { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

.notice-action { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.notice-action .button { flex: none; }
.table-input { min-height: 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-input); background: white; color: var(--text); padding: 6px 9px; font-size: 13px; }
input.table-input[type="number"] { width: 112px; text-align: right; font-variant-numeric: tabular-nums; }
.input-suffix { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--muted); }
.pricing-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; border-bottom: 1px solid var(--line); }
.pricing-tools .toolbar { margin: 0; }
.pricing-tools .search { flex: 1; min-width: 180px; min-height: 38px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-bar { position: sticky; bottom: 12px; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: var(--radius-card); background: var(--text); color: white; box-shadow: var(--shadow); font-size: 13px; }
.save-bar .button.primary { width: auto; background: #c5dd55; color: var(--text); }
@media (max-width: 760px) {
  .notice-action { flex-direction: column; align-items: stretch; }
  .save-bar { flex-direction: column; align-items: stretch; }
}

/* Shared building blocks */
.sub { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--faint); }
.badge { display: inline-block; white-space: nowrap; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 650; background: var(--surface-soft); color: var(--muted); vertical-align: middle; }
.badge.success { background: #edf5df; color: var(--success); }
.badge.warning { background: #fff4df; color: var(--warning); }
.badge.danger { background: #fff0ee; color: var(--danger); }
.text-danger { color: var(--danger); font-weight: 650; }
.money.negative { color: var(--danger); }
.money.strong { font-size: 15px; }
.rule { color: var(--muted); font-size: 12px; }
.nav-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 8px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: white; font-size: 12px; font-weight: 700; vertical-align: 1px; }
.topbar-side { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.metric { display: flex; flex-direction: column; }
.metric-action { align-self: flex-start; margin-top: auto; }
.metric .metric-note + .metric-action { margin-top: 12px; }
.button.primary.metric-action, .inline-form .button.primary { width: auto; }
.button.ghost-danger { color: var(--danger); background: white; border-color: #f0cfcc; }
.row-actions { display: inline-flex; gap: 6px; flex-wrap: nowrap; }
.actions-cell { white-space: nowrap; }
.link-button { border: 0; background: none; padding: 0 2px; color: var(--accent-strong); font-size: 12px; font-weight: 650; text-decoration: underline; min-height: 0; }
.inline-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0 14px; }
.inline-form .field { flex: 1 1 200px; }
.inline-form > .button { margin-bottom: 16px; min-width: 96px; }
.input-with-button { display: flex; gap: 8px; }
.input-with-button input { flex: 1; min-width: 0; }
.input-with-button .button { min-height: 44px; }
.withdraw-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.withdraw-layout .panel:first-child { max-width: 860px; }
.breakdown { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); }
.breakdown div { padding: 12px 17px; border-left: 1px solid var(--line); }
.breakdown div:first-child { border-left: 0; }
.breakdown span { display: block; font-size: 12px; color: var(--muted); }
.breakdown strong { display: block; margin-top: 4px; font-size: 17px; font-variant-numeric: tabular-nums; }
.detail-intro h2 { display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; min-height: 44px; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.panel-header .toolbar { margin: 0; }
td.primary-cell strong { font-weight: 680; }

@media (max-width: 1100px) {
  .breakdown { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .breakdown div:nth-child(3) { border-left: 0; }
  .breakdown div:nth-child(n + 3) { border-top: 1px solid var(--line); }
}

/* Phones: each table row becomes a card with labelled values. */
@media (max-width: 760px) {
  .data-table { min-width: 0; }
  .data-table thead { display: none; }
  .data-table tbody tr { display: flex; flex-direction: column; padding: 12px 16px; border-bottom: 1px solid #eceee9; }
  .data-table td .cell { min-width: 0; overflow-wrap: anywhere; }
  .data-table tbody tr:last-child { border-bottom: 0; }
  .data-table td { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; height: auto; padding: 3px 0; border: 0; text-align: right; }
  .data-table td::before { content: attr(data-label); flex: none; color: var(--faint); font-size: 12px; text-align: left; }
  .data-table td.primary-cell { display: block; order: -1; padding-bottom: 6px; text-align: left; font-size: 14px; }
  .data-table td.primary-cell::before { content: none; }
  .data-table td.actions-cell { justify-content: flex-end; padding-top: 8px; }
  .data-table td.actions-cell::before { content: none; }
  .data-table td .input-suffix { justify-content: flex-end; }
  .data-table td.actions-cell .cell { width: 100%; display: flex; justify-content: flex-end; }
  .panel-header { flex-wrap: wrap; }
  .topbar-side { justify-content: flex-start; }
  .breakdown strong { font-size: 15px; }
  .inline-form > .button { width: 100%; }
}

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 12px; white-space: nowrap; }
@media (max-width: 760px) {
  .chips { justify-content: flex-end; }
}

/* Pricing: one card per model family, groups as columns */
.family-list { display: grid; gap: 12px; padding: 14px 18px 18px; }
.family-card { border: 1px solid var(--line); border-radius: var(--radius-card); background: white; min-width: 0; }
.family-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbf7; border-radius: var(--radius-card) var(--radius-card) 0 0; }
.family-head strong { word-break: break-all; }
.family-tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.table-input.compact { min-height: 30px; padding: 3px 6px; font-size: 12px; }
.matrix-scroll { overflow-x: auto; }
.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.matrix tbody tr:last-child th, .matrix tbody tr:last-child td { border-bottom: 0; }
.matrix thead th { font-size: 12px; font-weight: 650; color: var(--muted); min-width: 132px; }
.matrix thead th:first-child, .matrix tbody th { min-width: 96px; width: 96px; }
.matrix .sub { display: block; margin-top: 3px; font-size: 11.5px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.matrix .variant { font-weight: 700; }
.matrix input.table-input[type="number"] { width: 92px; }
.muted-cell { color: var(--line-strong); }
.table-input.is-missing { border-color: var(--danger); background: #fdf3f2; }
.pricing-tools .check { white-space: normal; min-width: 0; }
@media (max-width: 760px) {
  .family-list { padding: 10px; }
  .family-head { padding: 10px; }
}
.unpaid-note { display: grid; gap: 8px; padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius-card); font-size: 13px; }
.unpaid-note .chips { justify-content: flex-start; }
.payout-fields { display: contents; }
.payout-choice { grid-column: 1 / -1; display: grid; gap: 8px; margin: 0 0 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-input); }
.payout-choice legend { padding: 0 4px; font-size: 13px; font-weight: 650; }
.payout-choice .check { white-space: normal; color: var(--text); }

/* Activation codes */
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; letter-spacing: 0.04em; white-space: nowrap; }
.code-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.code-tools .toolbar { margin: 0; }
.code-tools select.table-input { min-height: 38px; }
.created-codes { display: grid; gap: 10px; margin-top: 4px; }
.created-codes .row-actions { justify-self: start; }
.created-codes .row-actions .button { width: auto; white-space: nowrap; }
.row-actions a.button { white-space: nowrap; }
#code-form + .form-error:empty { display: none; }
.created-codes textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--line-strong); border-radius: var(--radius-input); padding: 10px 12px; background: var(--surface-accent); resize: vertical; }
a.button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
