/* ===== Design tokens ===== */
:root {
  --bg: #f5f6f8;
  --bg-2: #eef0f4;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --ink: #0b0d12;
  --ink-2: #393e4b;
  --muted: #858b99;
  --faint: #b7bcc7;
  --line: rgba(11, 13, 18, .075);
  --line-2: rgba(11, 13, 18, .13);
  --accent: #4f5bff;
  --accent-ink: #ffffff;
  --accent-2: #12c2b5;
  --accent-soft: rgba(79, 91, 255, .09);
  --accent-glow: rgba(79, 91, 255, .28);
  --ok: #0f9f6e;
  --ok-soft: rgba(15, 159, 110, .1);
  --warn: #c98100;
  --warn-soft: rgba(201, 129, 0, .1);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .1);
  --shadow-1: 0 1px 2px rgba(11, 13, 18, .04), 0 1px 1px rgba(11, 13, 18, .03);
  --shadow-2: 0 1px 2px rgba(11, 13, 18, .04), 0 8px 24px -6px rgba(11, 13, 18, .1);
  --shadow-3: 0 24px 64px -12px rgba(11, 13, 18, .28), 0 2px 6px rgba(11, 13, 18, .06);
  --r-xs: 6px;
  --r-sm: 9px;
  --r: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
  --nav-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07080b;
    --bg-2: #0d0f14;
    --surface: #111318;
    --surface-2: #15181e;
    --ink: #eef0f5;
    --ink-2: #c3c8d3;
    --muted: #7c8392;
    --faint: #4a505d;
    --line: rgba(255, 255, 255, .07);
    --line-2: rgba(255, 255, 255, .13);
    --accent: #7680ff;
    --accent-soft: rgba(118, 128, 255, .13);
    --accent-glow: rgba(118, 128, 255, .35);
    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, .12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .12);
    --danger: #ff6b6f;
    --danger-soft: rgba(255, 107, 111, .12);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -6px rgba(0, 0, 0, .5);
    --shadow-3: 0 24px 64px -12px rgba(0, 0, 0, .7), 0 0 0 1px rgba(255, 255, 255, .06);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07080b; --bg-2: #0d0f14; --surface: #111318; --surface-2: #15181e; --ink: #eef0f5; --ink-2: #c3c8d3;
  --muted: #7c8392; --faint: #4a505d; --line: rgba(255,255,255,.07); --line-2: rgba(255,255,255,.13);
  --accent: #7680ff; --accent-soft: rgba(118,128,255,.13); --accent-glow: rgba(118,128,255,.35);
  --ok: #34d399; --ok-soft: rgba(52,211,153,.12); --warn: #fbbf24; --warn-soft: rgba(251,191,36,.12);
  --danger: #ff6b6f; --danger-soft: rgba(255,107,111,.12);
  --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -6px rgba(0,0,0,.5);
  --shadow-3: 0 24px 64px -12px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.06);
  color-scheme: dark;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "tnum";
  min-height: 100vh; min-height: 100dvh;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
img, svg { display: block; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.mono { font-family: var(--mono); font-feature-settings: "zero" 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }
.icon.fill { fill: currentColor; stroke: none; }

/* ===== Buttons ===== */
.btn {
  --h: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--h); padding: 0 16px;
  border-radius: 11px; font-weight: 550; font-size: 14px; letter-spacing: .01em; white-space: nowrap;
  transition: transform .15s var(--ease), background .2s, box-shadow .2s, color .2s, border-color .2s, opacity .2s;
  user-select: none; -webkit-user-select: none; position: relative;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--bg); box-shadow: 0 1px 0 rgba(255,255,255,.12) inset, 0 6px 16px -6px rgba(11,13,18,.4); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 86%, var(--accent)); }
.btn-accent { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 20px -8px var(--accent-glow); }
.btn-accent:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--line); color: var(--ink); }
.btn-outline { border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.btn-outline:hover:not(:disabled) { border-color: color-mix(in srgb, var(--ink) 25%, transparent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { --h: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { --h: 48px; padding: 0 24px; font-size: 15px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: var(--h); padding: 0; }
.btn .spin { width: 16px; height: 16px; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--bg) transparent var(--bg) transparent; animation: spin .7s linear infinite;
}
.btn-outline.loading::after, .btn-ghost.loading::after { border-color: var(--ink) transparent var(--ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Inputs ===== */
.field { display: grid; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--surface); outline: none; transition: border-color .2s, box-shadow .2s, background .2s; font-size: 15px;
}
.textarea { height: auto; padding: 10px 14px; resize: vertical; min-height: 80px; }
.input::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.input.sm, .select.sm { height: 34px; font-size: 13.5px; border-radius: 9px; padding: 0 10px; }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23858b99' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 112px; }
.input-group .suffix { position: absolute; right: 5px; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 38px; }

/* Checkbox / switch */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13.5px; }
.check input { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 0; border-radius: 6px; border: 1.5px solid var(--line-2);
  background: var(--surface); display: grid; place-items: center; transition: all .15s; cursor: pointer; flex: none; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 9px; height: 5px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.check input:indeterminate { background: var(--accent); border-color: var(--accent); }
.check input:indeterminate::after { content: ""; width: 8px; height: 2px; background: #fff; border-radius: 2px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 20px; margin: 0; background: var(--line-2); position: relative; transition: background .2s; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .25s var(--ease-spring); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

/* ===== Cards / misc ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px; font-size: 12.5px; font-weight: 550;
  background: var(--line); color: var(--ink-2); white-space: nowrap; }
.chip .icon { width: 14px; height: 14px; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.sm { height: 22px; padding: 0 8px; font-size: 11.5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-2); color: var(--muted); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--line); position: relative; gap: 2px; }
.seg button { position: relative; z-index: 1; height: 32px; padding: 0 16px; border-radius: 9px; font-size: 13.5px; font-weight: 550; color: var(--muted); transition: color .2s; display: inline-flex; gap: 6px; align-items: center; }
.seg button[aria-selected="true"] { color: var(--ink); }
.seg .seg-thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-2); transition: left .3s var(--ease), width .3s var(--ease); }
.seg .count { font-size: 11.5px; color: var(--faint); font-weight: 500; }

/* Tooltip (info icon + tooltip pattern) */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translate(-50%, 4px);
  background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 500; line-height: 1.45; padding: 6px 10px; border-radius: 8px;
  white-space: pre; max-width: 260px; width: max-content; pointer-events: none; opacity: 0; transition: opacity .15s, transform .15s; z-index: 50; text-align: left;
}
[data-tip][data-tip-wrap]::after { white-space: normal; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .25s; }
[data-tip-pos="bottom"]::after { bottom: auto; top: calc(100% + 8px); }
[data-tip-pos="left"]::after { left: auto; right: 0; transform: translate(0, 4px); }
[data-tip-pos="left"]:hover::after { transform: translate(0, 0); }
.info { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: var(--faint); cursor: help; vertical-align: middle; }
.info:hover { color: var(--muted); }
.info .icon { width: 15px; height: 15px; }
@media (hover: none) { [data-tip]::after { display: none; } }

/* ===== Toast ===== */
.toasts { position: fixed; z-index: 1000; left: 50%; top: 18px; transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 16px 10px 12px; border-radius: 14px; background: var(--ink); color: var(--bg);
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-3); animation: toast-in .35s var(--ease-spring); pointer-events: auto; }
.toast .icon { width: 18px; height: 18px; }
.toast.ok .icon { color: #34d399; }
.toast.err .icon { color: #ff7a7e; }
.toast.out { animation: toast-out .25s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(.97); } }

/* ===== Modal ===== */
.overlay { position: fixed; inset: 0; z-index: 500; background: rgba(8, 9, 12, .42); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px; animation: fade-in .2s var(--ease); }
.overlay.out { animation: fade-out .2s var(--ease) forwards; }
.modal { width: min(440px, 100%); background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-3); border: 1px solid var(--line);
  animation: pop-in .35s var(--ease-spring); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-head h3 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.modal-body { padding: 18px 22px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
.overlay.out .modal { animation: pop-out .2s var(--ease) forwards; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }
@media (max-width: 560px) {
  .overlay { place-items: end center; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 22px 22px 0 0; animation: sheet-in .4s var(--ease); padding-bottom: env(safe-area-inset-bottom); }
  .overlay.out .modal { animation: sheet-out .25s var(--ease) forwards; }
  @keyframes sheet-in { from { transform: translateY(100%); } }
  @keyframes sheet-out { to { transform: translateY(100%); } }
}

/* ===== Skeleton / empty ===== */
.skel { background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 40%, transparent) 50%, var(--line) 75%); background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { display: grid; place-items: center; gap: 12px; padding: 56px 20px; color: var(--muted); text-align: center; }
.empty .icon { width: 32px; height: 32px; color: var(--faint); stroke-width: 1.4; }

/* ===== Table ===== */
.table-wrap { overflow: auto; border-radius: var(--r); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-weight: 550; color: var(--muted); font-size: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }

.fade-up { animation: fade-up .5s var(--ease) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
