/* Self-hosted Public Sans — the same face NewAPI's new theme uses.
   Chinese glyphs fall back to system CJK fonts, identical to NewAPI. */
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/public-sans-viet.woff2') format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/public-sans-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Public Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/public-sans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #0a0a0a;
  --muted: #f5f5f5;
  --muted-foreground: #606060;
  --subtle-foreground: #8a8a8a;
  --border: #e8e8e8;
  --primary: #3ea4ec;
  --primary-hover: #168fe2;
  --primary-foreground: #ffffff;
  --primary-soft: #e8f4fe;
  --ring: #42a6ff;
  --success: #009767;
  --success-soft: #e6f7ef;
  --warning: #cd8900;
  --warning-soft: #fff8e8;
  --destructive: #dc2626;
  --destructive-soft: #fef1f1;
  --radius: 16px;
  --font-sans: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-family: var(--font-sans);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--background); }
body { min-width: 320px; margin: 0; background: var(--background); color: var(--foreground); font-size: 14px; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(62, 164, 236, .25); outline-offset: 2px; }
.app-shell { min-height: 100vh; }

.boot-screen { min-height: 100vh; display: grid; place-content: center; gap: 14px; color: var(--muted-foreground); text-align: center; }
.boot-mark { width: 36px; height: 36px; margin: auto; display: grid; place-items: center; border-radius: 12px; background: var(--primary); color: #fff; font: 700 13px var(--font-mono); }

/* ── Login: mirrors NewAPI's sign-in page ─────────────────────────── */
.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 500px) minmax(320px, 380px); align-items: center; justify-content: center; gap: clamp(60px, 10vw, 160px); padding: 40px; background: var(--background); }
.folio { margin: 0 0 14px; color: var(--primary); font-size: 13px; font-weight: 600; }
.login-intro h1 { max-width: 520px; margin: 0 0 20px; font-size: clamp(34px, 4.5vw, 52px); font-weight: 700; line-height: 1.12; letter-spacing: -1.3px; }
.login-intro p:last-child { max-width: 380px; margin: 0; color: var(--muted-foreground); font-size: 16px; line-height: 1.7; }
.login-sheet { display: grid; gap: 16px; width: 100%; max-width: 416px; }
.sheet-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 20px; font-weight: 500; }
.sheet-title span:last-child { color: var(--subtle-foreground); font: 13px var(--font-mono); }
.field { display: grid; gap: 7px; margin: 0; }
.field span { font-size: 14px; font-weight: 500; }
.field input, .field select { width: 100%; height: 32px; border: 1px solid var(--border); border-radius: 16px; padding: 0 10px; background: transparent; color: var(--foreground); font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(62, 164, 236, .13); }
.field small, .check-row small { color: var(--subtle-foreground); font-size: 11px; line-height: 1.5; }
.primary-btn { width: 100%; height: 32px; border: 0; border-radius: 16px; background: var(--primary); color: var(--primary-foreground); font-size: 14px; font-weight: 500; transition: background .15s; }
.primary-btn:hover { background: var(--primary-hover); }
.primary-btn:disabled { opacity: .55; cursor: wait; }
.form-error { min-height: 18px; margin: 0; color: var(--destructive); font-size: 12px; }

/* ── App chrome ───────────────────────────────────────────────────── */
.topbar { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1280px) / 2)); border-bottom: 1px solid var(--border); background: var(--background); }
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 600; }
.brand-mark { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; background: var(--primary); color: #fff; font: 700 12px var(--font-mono); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.sync-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted-foreground); font-size: 13px; }
.sync-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.user-name { max-width: 140px; overflow: hidden; color: var(--muted-foreground); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.ghost-btn, .action-btn { height: 32px; padding: 0 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--background); color: var(--muted-foreground); font-size: 14px; font-weight: 500; transition: border-color .15s, color .15s, background .15s; }
.ghost-btn:hover, .action-btn:hover { border-color: #bcdcf6; background: var(--primary-soft); color: var(--primary-hover); }
.action-btn.primary { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.action-btn.primary:hover { background: var(--primary-hover); }
.action-btn:disabled { opacity: .55; cursor: wait; }

.page-shell { width: min(100% - 48px, 1240px); margin: auto; padding: 28px 0 72px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.page-heading h1 { margin: 0 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.page-heading p:not(.folio) { margin: 0; color: var(--muted-foreground); font-size: 13px; }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* ── Overview stats: flat white cards, 1px border, 16px radius ────── */
.usage-statement { display: grid; grid-template-columns: minmax(320px, 1.35fr) 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.usage-main, .statement-note, .statement-reset { min-height: 150px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); }
.usage-figure { display: flex; align-items: baseline; gap: 8px; margin: 14px 0 6px; }
.usage-figure strong { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.usage-figure strong small { font-size: 22px; font-weight: 600; }
.usage-figure span { color: var(--muted-foreground); font-size: 13px; }
.usage-total { margin: 12px 0; color: var(--muted-foreground); font: 12px var(--font-mono); }
.usage-total i { margin: 0 4px; color: var(--subtle-foreground); font-style: normal; }
.usage-bar { height: 6px; overflow: hidden; border-radius: 999px; background: #e9f1f8; }
.usage-bar i { display: block; min-width: 2px; height: 100%; border-radius: inherit; background: var(--primary); }
.statement-note strong, .statement-reset time { display: block; margin: 26px 0 6px; font-size: 24px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.statement-reset time { color: var(--primary-hover); }
.statement-note span, .statement-reset span { display: block; color: var(--muted-foreground); font-size: 13px; }

/* ── Server list: bordered table-like rows ────────────────────────── */
.servers-section, .customers-section, .notice-section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); overflow: hidden; }
.section-head, .customers-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.section-head h2, .customers-head h2, .notice-section h2 { margin: 0 0 3px; font-size: 17px; font-weight: 600; }
.section-head p:not(.folio), .customers-head p:not(.folio), .notice-section p:not(.folio) { margin: 0; color: var(--muted-foreground); font-size: 12px; }
.legend { display: flex; gap: 14px; color: var(--muted-foreground); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 6px; border-radius: 3px; background: var(--primary); }
.legend .remaining i { background: #dde5ec; }
.server-list { display: grid; }
.server-row { display: grid; grid-template-columns: minmax(160px, .9fr) minmax(200px, 1.35fr) 130px; align-items: center; gap: 22px; min-height: 82px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.server-row:last-child { border-bottom: 0; }
.server-row.admin-row { grid-template-columns: minmax(150px, .8fr) minmax(190px, 1.15fr) 124px minmax(150px, .75fr); }
.server-row:hover { background: #fafafa; }
.server-identity { min-width: 0; }
.server-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.server-title strong { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.server-identity > span { display: block; margin-top: 5px; overflow: hidden; color: var(--subtle-foreground); font: 12px var(--font-mono); text-overflow: ellipsis; white-space: nowrap; }
.status-badge { padding: 2px 8px; border-radius: 999px; background: var(--success-soft); color: var(--success); font-size: 12px; }
.traffic-cell { display: grid; gap: 7px; }
.bar-meta { display: flex; justify-content: space-between; color: var(--muted-foreground); font: 11px var(--font-mono); }
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: #edf1f4; }
.progress > i { display: block; min-width: 2px; height: 100%; border-radius: inherit; background: var(--primary); }
.progress.warning > i { background: var(--warning); }
.progress.critical > i { background: var(--destructive); }
.traffic-cell > strong { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.reset-cell { display: grid; gap: 4px; }
.cell-label { color: var(--subtle-foreground); font-size: 11px; }
.reset-cell time { font-size: 13px; font-weight: 500; }
.assignment-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.assignment-list { display: flex; flex-wrap: wrap; gap: 4px; }
.assignment-chip { display: inline-block; max-width: 90px; overflow: hidden; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-hover); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.assignment-empty { color: var(--subtle-foreground); font-size: 12px; }
.text-btn { border: 0; padding: 0; background: transparent; color: var(--primary-hover); font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }

/* ── Alerts ───────────────────────────────────────────────────────── */
.notice-section { display: grid; grid-template-columns: 200px 1fr; gap: 24px; margin-top: 16px; padding: 18px; }
.alert-list { display: grid; gap: 8px; }
.alert { padding: 10px 12px; border: 1px solid #f5d0d0; border-radius: 12px; background: var(--destructive-soft); }
.alert strong { font-size: 13px; font-weight: 600; }
.alert div { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--muted-foreground); font: 11px var(--font-mono); }
.all-clear { padding: 10px 12px; border: 1px solid #c9e7d8; border-radius: 12px; background: var(--success-soft); color: var(--muted-foreground); font-size: 12px; line-height: 1.6; }
.all-clear strong { color: var(--success); }

/* ── Client directory table ───────────────────────────────────────── */
.customers-section { margin-top: 16px; }
.users-table-wrap { overflow-x: auto; }
.users-table, .data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th, .users-table td, .data-table th, .data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.users-table tr:last-child td { border-bottom: 0; }
.users-table th, .data-table th { color: var(--muted-foreground); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.users-table tbody tr:hover { background: #fafafa; }
.user-cell { display: flex; align-items: center; gap: 9px; }
.user-avatar { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary-hover); font: 600 12px var(--font-mono); }
.assigned-count { color: var(--primary-hover); font: 600 13px var(--font-mono); }
.account-status { color: var(--success); font-size: 12px; }
.data-table { display: none; border-top: 1px solid var(--border); }
.data-table.open { display: table; }
.data-table td { color: var(--muted-foreground); font-family: var(--font-mono); font-size: 12px; }
.empty { padding: 40px 18px; color: var(--muted-foreground); text-align: center; font-size: 13px; }
.empty.compact, .users-empty { padding: 24px 14px; }

/* ── Dialogs ──────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(10, 10, 10, .35); }
.modal { width: min(100%, 440px); max-height: calc(100vh - 40px); overflow-y: auto; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); box-shadow: 0 18px 50px rgba(10, 10, 10, .14); }
.modal h2 { margin: 0 34px 8px 0; font-size: 18px; font-weight: 600; }
.modal-description { margin: 0 0 18px; color: var(--muted-foreground); font-size: 13px; line-height: 1.6; }
.modal-close { position: absolute; top: 12px; right: 12px; border: 0; background: transparent; color: var(--subtle-foreground); font-size: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.modal-note { padding: 12px; border-radius: 12px; background: var(--primary-soft); color: var(--muted-foreground); font-size: 13px; line-height: 1.6; }
.check-list { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.check-row:last-child { border-bottom: 0; }
.check-row:has(input:checked) { background: var(--primary-soft); }
.check-row span { display: grid; gap: 2px; }
.check-row strong { font-size: 13px; font-weight: 600; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 22px; transform: translate(-50%, 12px); padding: 9px 14px; border-radius: 10px; background: var(--foreground); color: #fff; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; box-shadow: 0 8px 24px rgba(10, 10, 10, .18); font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .usage-statement { grid-template-columns: 1fr 1fr; }
  .usage-main { grid-column: 1 / -1; }
  .server-row.admin-row { grid-template-columns: minmax(140px,.8fr) minmax(180px,1.1fr) 110px; }
  .assignment-cell { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .topbar { padding: 0 16px; }
  .sync-state, .user-name { display: none; }
  .page-shell { width: min(100% - 28px, 1240px); padding-top: 20px; }
  .page-heading { display: grid; grid-template-columns: 1fr; align-items: start; }
  .hero-actions { justify-content: flex-start; }
  .usage-statement { grid-template-columns: 1fr; }
  .usage-main { grid-column: auto; }
  .usage-main, .statement-note, .statement-reset { min-height: auto; }
  .notice-section { grid-template-columns: 1fr; gap: 14px; }
  .server-row, .server-row.admin-row { grid-template-columns: minmax(0,1fr) 116px; gap: 12px; }
  .traffic-cell { grid-column: 1 / -1; grid-row: 2; }
  .reset-cell { text-align: right; }
  .assignment-cell { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .legend { display: none; }
  .login-screen { grid-template-columns: 1fr; gap: 40px; padding: 28px; }
  .login-intro h1 { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
