/* =====================================================================
   MyDoller — shared design system (accounts / my / cp)
   Light + dark, mobile-first, no external fonts or CDNs.
   ===================================================================== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --border: #e3e5ef;
  --text: #151827;
  --text-2: #4a5068;
  --text-3: #6b7189;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --good: #15803d;   --good-soft: #e8f7ee;
  --warn: #b45309;   --warn-soft: #fff4e5;
  --bad: #b91c1c;    --bad-soft: #fdecec;
  --chart-mark: #4f46e5;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a24; --surface-2: #1f2330; --border: #2b3040;
    --text: #eef0f6; --text-2: #b4b9cc; --text-3: #8b91a8;
    --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #23264a; --on-primary: #0f1117;
    --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2e230c; --bad: #f87171; --bad-soft: #321516;
    --chart-mark: #6366f1;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a24; --surface-2: #1f2330; --border: #2b3040;
  --text: #eef0f6; --text-2: #b4b9cc; --text-3: #8b91a8;
  --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #23264a; --on-primary: #0f1117;
  --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2e230c; --bad: #f87171; --bad-soft: #321516;
  --chart-mark: #6366f1;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  min-height: 100vh; overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--text-2); } .faint { color: var(--text-3); font-size: .88em; }
.mono { font-family: var(--mono); font-size: .9em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* brand */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-weight: 900; font-size: 17px; }

/* layout */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.cols-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flat { box-shadow: none; }
.card h2 { font-size: 1.05rem; }

/* buttons */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=number], input[type=search], input[type=url], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; min-height: 42px; }
textarea { min-height: 96px; resize: vertical; }
.field + .field { margin-top: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; width: 18px; height: 18px; }
.otp { letter-spacing: .5em; font-family: var(--mono); font-size: 1.3rem; text-align: center; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad  { background: var(--bad-soft);  color: var(--bad);  border-color: transparent; }
.badge.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* notices */
.notice { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--primary-soft); color: var(--text); border: 1px solid transparent; }
.notice.good { background: var(--good-soft); } .notice.warn { background: var(--warn-soft); } .notice.bad { background: var(--bad-soft); }
.notice strong { display: block; margin-bottom: 2px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.topbar .container { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 800; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* tabs (scrollable on phones) */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--text-2);
  padding: 12px 12px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); background: var(--surface-2); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* stat tiles */
.stat { padding: 16px; }
.stat .label { color: var(--text-2); font-size: .85rem; font-weight: 600; }
.stat .value { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--text-3); font-size: .8rem; }

/* tool tiles */
.tool { display: flex; flex-direction: column; gap: 10px; }
.tool-head { display: flex; gap: 12px; align-items: center; }
.tool-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 900; font-size: 20px; flex: none; overflow: hidden; }
.tool-icon img { width: 100%; height: 100%; object-fit: cover; }
.tool .desc { color: var(--text-2); font-size: .9rem; flex: 1; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); max-width: 520px; width: 100%; max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); z-index: 90; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 91; overflow-y: auto; padding: 18px 16px 40px; box-shadow: -10px 0 40px rgba(0,0,0,.25); }

/* toast */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 600; font-size: .92rem; }
.toast.bad { background: var(--bad); color: #fff; } .toast.good { background: var(--good); color: #fff; }

/* chart */
.chart { width: 100%; height: 180px; display: block; }
.chart .bar { fill: var(--chart-mark); }
.chart .bar:hover, .chart .hit:hover + .bar { opacity: .8; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart-tip { position: fixed; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 7px; font-size: .82rem; font-weight: 600; z-index: 300; }

/* auth page */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: .85rem; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.google-btn svg { width: 18px; height: 18px; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-page { min-height: 70vh; display: grid; place-items: center; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: .92rem; }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

footer.site { color: var(--text-3); font-size: .85rem; padding: 28px 0 40px; text-align: center; }
footer.site a { color: var(--text-2); }

@media (max-width: 640px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 15px; }
  .kv { grid-template-columns: 110px 1fr; }
  .hide-sm { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
