/* ============================================================================
   LIFT99 Dashboard — design system
   Tokens → base → components. Dark + light via [data-theme]. No external fonts.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;
  /* palette (dark) */
  --bg: #0a0d13;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #121826 0%, #0a0d13 60%);
  --surface-1: #11151d;
  --surface-2: #161b25;
  --surface-3: #1c2330;
  --hover: #1b212d;
  --row-hover: #121721;
  --border: #232b38;
  --border-strong: #303a4a;
  --text: #e9eef6;
  --text-muted: #9aa6b6;
  --text-faint: #6a7585;

  --accent: #5b7cfa;
  --accent-hover: #6e8bff;
  --accent-active: #4961e6;
  --accent-soft: #5b7cfa1f;
  --on-accent: #ffffff;

  --good: #3fb860;
  --good-soft: #1f3a2733;
  --good-border: #245c38;
  --warn: #e0a93b;
  --warn-soft: #4a3a1433;
  --warn-border: #5c4a1f;
  --bad: #f2545b;
  --bad-soft: #3a181b66;
  --bad-border: #6e2b30;

  /* type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* radii / shadow / motion */
  --r-sm: 7px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 6px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55);
  --ring: 0 0 0 3px var(--accent-soft);
  --ease: cubic-bezier(.4,0,.2,1);

  /* spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #ffffff 0%, #eef1f6 60%);
  --surface-1: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eef1f6;
  --hover: #eef1f6;
  --row-hover: #f5f7fb;
  --border: #e3e8ef;
  --border-strong: #cfd7e2;
  --text: #161b22;
  --text-muted: #56627280 0; /* overridden below */
  --text-muted: #5a6675;
  --text-faint: #8a95a3;

  --accent: #3a5bdc;
  --accent-hover: #314fc8;
  --accent-active: #2b48b8;
  --accent-soft: #3a5bdc1f;
  --on-accent: #ffffff;

  --good: #1a7f37; --good-soft: #e6f4ea; --good-border: #aee0bc;
  --warn: #9a6700; --warn-soft: #fdf3da; --warn-border: #ecd9a6;
  --bad: #cf222e; --bad-soft: #ffeceb; --bad-border: #f3c0c0;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow-md: 0 6px 20px rgba(16,24,40,.10);
  --shadow-lg: 0 24px 60px rgba(16,24,40,.18);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 24px 96px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-active));
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: -.5px; box-shadow: var(--shadow-sm);
}
.brand b { font-weight: 700; }
.brand .sub { color: var(--text-muted); font-weight: 500; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }
.userbox .who { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* segmented tabs */
.tabs { display: flex; gap: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px; }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer; color: var(--text-muted);
  font: inherit; font-weight: 600; font-size: 13px; padding: 7px 16px; border-radius: 8px; transition: .15s var(--ease);
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab.active { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.tab .count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--surface-3); color: var(--text-muted); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.tab.active .count { background: rgba(255,255,255,.22); color: var(--on-accent); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); transition: .14s var(--ease); white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:active { background: var(--accent-active); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); border-color: var(--border); }
.btn.good { background: var(--good-soft); border-color: var(--good-border); color: var(--good); }
.btn.danger { background: var(--bad-soft); border-color: var(--bad-border); color: var(--bad); }
.btn.sm { padding: 6px 11px; font-size: 12px; border-radius: var(--r-sm); }
.btn.lg { padding: 11px 18px; font-size: 14px; }
.btn.block { width: 100%; }
.btn .ic { width: 15px; height: 15px; flex: none; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
label.lbl { font-size: 12px; color: var(--text-muted); font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 9px 11px; transition: .14s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type=month] { font-family: var(--font-mono); }
textarea { resize: vertical; min-height: 150px; line-height: 1.55; }

/* ---------- cards / stats ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin: 2px 0 var(--sp-4); }
.toolbar .group { display: flex; gap: 10px; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); margin: var(--sp-5) 0; }
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 15px 17px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); opacity: .8; }
.stat.is-good::before { background: var(--good); } .stat.is-warn::before { background: var(--warn); }
.stat .k { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .v.sm { font-size: 18px; }

/* banner / callout */
.banner { display: flex; align-items: flex-start; gap: 9px; font-size: 12.5px; color: var(--text-muted); background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--warn); border-radius: var(--r-md); padding: 10px 14px; }
.banner.bad { border-left-color: var(--bad); }
.banner .ic { flex: none; margin-top: 1px; }

/* ---------- panel / table ---------- */
.panel { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); overflow: hidden; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr { transition: background .12s var(--ease); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
td.cust { white-space: normal; max-width: 280px; }
td .sub { color: var(--text-faint); font-size: 11.5px; margin-top: 2px; }

/* pills / status */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--r-full); font-size: 11.5px; font-weight: 550; border: 1px solid var(--border-strong); color: var(--text-muted); background: var(--surface-2); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.paid { color: var(--good); border-color: var(--good-border); background: var(--good-soft); }
.pill.unpaid, .pill.pending { color: var(--warn); border-color: var(--warn-border); background: var(--warn-soft); }
.pill.overdue { color: var(--bad); border-color: var(--bad-border); background: var(--bad-soft); }
.pill.tax { font-family: var(--font-mono); color: var(--text-muted); background: transparent; }
button.pill { cursor: pointer; transition: .14s var(--ease); }
button.pill:hover { filter: brightness(1.12); border-color: currentColor; }
.tags { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; }
.sent-ic { color: var(--text-faint); margin-left: 6px; }
.merit-done { color: var(--good); font-family: var(--font-mono); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.err-text { color: var(--bad); font-size: 12px; white-space: normal; }

/* status dropdown menu */
.menu { position: absolute; z-index: 70; min-width: 200px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 6px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 2px; animation: pop .12s var(--ease); }
.menu button { text-align: left; background: transparent; border: 0; padding: 9px 11px; border-radius: var(--r-sm); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.menu button:hover { background: var(--hover); }
.menu button.good { color: var(--good); }
.menu .note { font-size: 11px; color: var(--text-faint); padding: 7px 11px 3px; border-top: 1px solid var(--border); margin-top: 3px; }

/* ---------- email list ---------- */
.list-item { display: flex; gap: 13px; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--border); transition: background .12s var(--ease); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--row-hover); }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--on-accent); background: linear-gradient(135deg, var(--accent), var(--accent-active)); }
.email .body { flex: 1; min-width: 0; cursor: pointer; }
.email .from { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.email .from .unread { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.email .subj { margin-top: 1px; }
.email .snip { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email .meta { color: var(--text-faint); font-size: 11.5px; margin-top: 5px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.email .actions { display: flex; gap: 7px; flex: none; }
.acctbadge { font-size: 11px; padding: 2px 8px; border-radius: var(--r-full); background: var(--surface-3); border: 1px solid var(--border); color: var(--text-muted); }

/* ---------- tasks ---------- */
.task { display: flex; gap: 13px; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.task.done .title { text-decoration: line-through; color: var(--text-muted); }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; }
.task .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.check { width: 21px; height: 21px; border-radius: 6px; border: 1.5px solid var(--border-strong); cursor: pointer; flex: none; margin-top: 1px; display: grid; place-items: center; transition: .14s var(--ease); }
.check:hover { border-color: var(--accent); }
.check.on { background: var(--good); border-color: var(--good); }

/* segmented filter */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: 12.5px; font-weight: 550; padding: 6px 13px; border-radius: var(--r-sm); cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--on-accent); }

/* ---------- states: loading / empty ---------- */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 56px 24px; color: var(--text-muted); }
.empty .emoji { font-size: 30px; }
.empty .t { font-weight: 600; color: var(--text); }
.empty .d { font-size: 13px; color: var(--text-muted); max-width: 360px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); }
.skel-row { display: flex; gap: 13px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; vertical-align: -2px; opacity: .9; }
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 392px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 30px; box-shadow: var(--shadow-md); }
.login .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.login h2 { font-size: 19px; text-align: center; }
.login p { color: var(--text-muted); margin: 4px 0 22px; font-size: 13px; text-align: center; }
.login .field { margin-bottom: 14px; }
.login input { width: 100%; }
.login .switch { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--text-faint); }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 11px 16px; font-size: 13px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px; animation: toastin .2s var(--ease); }
.toast.good { border-color: var(--good-border); }
.toast.bad { border-color: var(--bad-border); color: var(--text); }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); }
.toast.good .dot { background: var(--good); } .toast.bad .dot { background: var(--bad); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4,6,10,.62); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
#modalBg { z-index: 110; } /* confirm dialog stacks above the mail/password modals */
.modal-bg.show { display: flex; animation: fade .15s var(--ease); }
.modal { background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: 24px; max-width: 460px; width: 100%; box-shadow: var(--shadow-lg); animation: modalin .18s var(--ease); }
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal p { color: var(--text-muted); margin: 0 0 18px; }
.modal .row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal .detail { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; margin: 0 0 18px; font-size: 13px; line-height: 1.6; }
.modal .field { margin-bottom: 12px; } .modal input { width: 100%; }
@keyframes fade { from { opacity: 0; } }
@keyframes modalin { from { opacity: 0; transform: translateY(10px) scale(.985); } }

/* mail viewer / composer modal */
.mail-modal { max-width: 760px; max-height: 88vh; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.mail-head { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.mail-head h3 { font-size: 16px; margin-bottom: 7px; line-height: 1.35; }
.mail-meta { color: var(--text-muted); font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; }
.mail-meta b { color: var(--text); }
.mail-body { flex: 1; overflow: auto; background: #fff; min-height: 240px; }
.mail-body iframe { width: 100%; border: 0; min-height: 360px; background: #fff; display: block; }
.mail-actions { display: flex; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.composer { padding: 18px 22px; display: flex; flex-direction: column; gap: 11px; overflow: auto; }
.composer input, .composer textarea, .composer select { width: 100%; }
.composer .crow { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 2px; }
.grow { flex: 1; }

/* ---------- theme toggle (fab) ---------- */
.theme-toggle { position: fixed; bottom: 18px; right: 18px; z-index: 90; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); font-size: 18px; cursor: pointer; box-shadow: var(--shadow-md); display: grid; place-items: center; transition: .15s var(--ease); }
.theme-toggle:hover { background: var(--hover); transform: translateY(-1px); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .wrap { padding: 16px 14px 90px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 10px; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  /* email/task rows: trailing actions drop to a full-width row beneath the content */
  .list-item, .task { flex-wrap: wrap; }
  .email .actions { flex-basis: 100%; justify-content: flex-end; margin-top: 2px; }
}

/* Invoices table → stacked cards on phones (9 columns can't fit a phone width) */
@media (max-width: 640px) {
  .panel:has(table) { border: 0; background: transparent; border-radius: 0; }
  .tablewrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); margin-bottom: 10px; box-shadow: var(--shadow-sm); overflow: hidden; }
  td { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: normal; text-align: right; min-height: 44px; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: var(--text-muted); font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; text-align: left; flex: none; }
  td.cust, td .sub { text-align: right; }
  .tags { margin-left: 0; }
  td[data-label="Merit"] .btn, td[data-label="Merit"] .merit-done { margin-left: auto; }
  /* loading / empty / error rows span the card and stay centered (no label) */
  td[colspan] { display: block; text-align: center; padding: 0; min-height: 0; }
  td[colspan]::before { content: none; }
}

@media (max-width: 480px) {
  .wrap { padding: 12px 11px 88px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .userbox .who { display: none; }
  .brand .sub { display: none; }
  .stat .v { font-size: 19px; } .stat .v.sm { font-size: 16px; }
  .modal { padding: 20px; }
  .theme-toggle { width: 40px; height: 40px; bottom: 14px; right: 14px; }
}
[hidden] { display: none !important; }
