/* BalasEmail dashboard — brand palette: blue #2563EB → indigo #4F46E5 → violet #7C3AED, accent green #34D399. */
:root {
  color-scheme: light;
  --bg: #f4f5fb;
  --panel: #ffffff;
  --panel-2: #f8f8fe;
  --border: #e6e7f2;
  --text: #161a2e;
  --muted: #646a85;
  --faint: #9aa0b8;
  --brand-1: #2563eb;
  --brand-2: #4f46e5;
  --brand-3: #7c3aed;
  --brand-grad: linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 50%, var(--brand-3) 100%);
  --accent: #4f46e5;
  --accent-soft: #eeedfd;
  --mint: #34d399;
  --ok: #0f8a5f;  --ok-soft: #e2f6ee;
  --warn: #a35a00; --warn-soft: #fdf0dc;
  --bad: #c42d3c;  --bad-soft: #fde7ea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 26, 46, .05), 0 8px 24px -12px rgba(79, 70, 229, .18);

  /* Chart tokens — validated with the dataviz palette checker (light surface). */
  --chart-surface: #ffffff;
  --s1: #4f46e5;  /* indigo  */
  --s2: #d97706;  /* amber   */
  --s3: #0284c7;  /* sky     */
  --s4: #059669;  /* green   */
  --st-good: #059669; --st-warn: #d97706; --st-bad: #dc2626; --st-neutral: #9aa0b8;
  --grid: #eceef6;

  --side-bg: linear-gradient(180deg, #1b1846 0%, #251f63 55%, #2d1f6e 100%);
  --side-text: #c9c8ef;
  --side-muted: #8885c4;
  --side-active: rgba(255, 255, 255, .12);
  font-family: Inter, "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1120; --panel: #161a2b; --panel-2: #1b2033; --border: #272d45; --text: #e8eaf6; --muted: #a2a7c4; --faint: #6f7596;
    --accent: #a5a6ff; --accent-soft: #262b52;
    --ok: #4fd1a1; --ok-soft: #12322a; --warn: #f5b552; --warn-soft: #3a2b12; --bad: #ff8590; --bad-soft: #3d1a22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --chart-surface: #161a2b;
    --s1: #8b7cff; --s2: #c07e08; --s3: #1593cf; --s4: #0fa06f;
    --st-good: #0fa06f; --st-warn: #c07e08; --st-bad: #e5484d; --st-neutral: #6f7596;
    --grid: #252b42;
    --side-bg: linear-gradient(180deg, #0c0b26 0%, #15123d 60%, #1b1350 100%);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 14px; letter-spacing: -.01em; }
p.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side-bg); color: var(--side-text); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 800; font-size: 18px; letter-spacing: -.02em; padding: 2px 10px 18px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; display: block; box-shadow: 0 6px 16px -6px rgba(124, 58, 237, .7); }
.brand .accent { color: var(--accent); }
.side .brand { color: #fff; }
.side .brand .accent { color: #b4b0ff; }
.nav-group { color: var(--side-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; padding: 16px 12px 6px; }
.nav a { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; color: var(--side-text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 650; }
.nav a.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--mint); }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.side-foot { margin-top: auto; padding: 14px 8px 4px; border-top: 1px solid rgba(255, 255, 255, .08); }
.me-card { display: flex; gap: 10px; align-items: center; padding: 6px 4px 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--brand-grad); flex: none; }
.me-card .name { color: #fff; font-weight: 600; font-size: 13px; line-height: 1.2; }
.me-card .org { color: var(--side-muted); font-size: 12px; }
.side-foot a { color: var(--side-text); text-decoration: none; font-size: 13px; padding: 6px 4px; display: inline-block; }
.side-foot a:hover { color: #fff; }
main { padding: 30px 36px 64px; max-width: 1240px; width: 100%; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 6px; }
.role-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 650; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.role-pill.super { background: var(--brand-grad); color: #fff; }

/* ---------- hero ---------- */
.hero { position: relative; overflow: hidden; border-radius: 18px; padding: 26px 28px; margin-bottom: 18px; color: #fff; background: var(--brand-grad); box-shadow: 0 18px 40px -22px rgba(79, 70, 229, .8); }
.hero::after { content: ""; position: absolute; right: -60px; top: -80px; width: 280px; height: 280px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 70%); }
.hero h1 { font-size: 26px; color: #fff; }
.hero p { margin: 0; color: rgba(255, 255, 255, .85); max-width: 640px; }
.hero .actions { margin-top: 18px; position: relative; z-index: 1; }
.hero .btn-light { background: #fff; color: var(--brand-2); border-color: #fff; }
.hero .btn-ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .35); }
.hero .dot-live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgba(52, 211, 153, .25); margin-right: 8px; vertical-align: middle; }

/* ---------- cards & stats ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .help { margin: 0; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.span-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stat { position: relative; display: flex; flex-direction: column; gap: 2px; }
.stat .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stat .chip { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; background: var(--accent-soft); }
.stat .chip.c1 { background: linear-gradient(135deg, #e0e7ff, #ede9fe); }
.stat .chip.c2 { background: linear-gradient(135deg, #fef3c7, #ffedd5); }
.stat .chip.c3 { background: linear-gradient(135deg, #e0f2fe, #dbeafe); }
.stat .chip.c4 { background: linear-gradient(135deg, #d1fae5, #dcfce7); }
@media (prefers-color-scheme: dark) { .stat .chip.c1, .stat .chip.c2, .stat .chip.c3, .stat .chip.c4 { background: var(--panel-2); } }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 550; margin-top: 10px; }
.stat .value { font-size: 28px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.stat .hint { color: var(--muted); font-size: 12px; }
.stat .spark { display: block; }
.delta { font-size: 12px; font-weight: 650; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover td { background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; border: 1px solid var(--border); }
a.badge { text-decoration: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); 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.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

/* ---------- forms & buttons ---------- */
form .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
form .full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 110px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; min-height: 260px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 4px var(--accent-soft); }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
button { font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 8px 15px; border-radius: 10px; cursor: pointer; font-weight: 600; transition: transform .1s, box-shadow .15s, border-color .15s; }
button:hover { border-color: var(--brand-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--brand-grad); border-color: transparent; color: #fff; box-shadow: 0 8px 18px -10px rgba(79, 70, 229, .9); }
button.primary:hover { box-shadow: 0 10px 22px -10px rgba(79, 70, 229, 1); }
button.danger { color: var(--bad); }
button.ghost { background: transparent; }
button.sm { white-space: nowrap; padding: 4px 10px; font-size: 12px; border-radius: 8px; }
button:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.callout { border-radius: 10px; padding: 11px 13px; background: var(--accent-soft); color: var(--text); margin-bottom: 14px; font-size: 13px; }
.callout.warn { background: var(--warn-soft); }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--panel-2); border: 1px dashed var(--border); padding: 8px 10px; border-radius: 8px; word-break: break-all; }
.samples { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.samples a { font-weight: 600; font-size: 13px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; font-size: 12px; border-radius: 8px; }
.seg button.on { background: var(--panel); box-shadow: var(--shadow); color: var(--accent); }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; min-height: 26px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-body { position: relative; }
.chart-body svg { display: block; overflow: visible; }
.chart svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart svg .axis { fill: var(--muted); font-size: 11px; }
.chart svg .line, svg.spark .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart svg .area { opacity: .1; }
.chart svg .dot, svg.spark .dot { stroke: var(--chart-surface); stroke-width: 2; }
.chart svg .cross { stroke: var(--faint); stroke-width: 1; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 150px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; box-shadow: 0 12px 28px -10px rgba(22, 26, 46, .35); font-size: 12px; }
.tip-title { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 7px; }
.tip-name { color: var(--muted); flex: 1; }
.tip-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-table table { font-size: 13px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 10px; padding: 5px 0; }
.hbar-label { color: var(--text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 16px; }
.hbar-fill { height: 16px; border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; font-size: 13px; }
.stack-bar { display: flex; gap: 2px; height: 18px; border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.stack-seg { height: 100%; min-width: 4px; }
.stack-legend { gap: 6px 16px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art { position: relative; overflow: hidden; background: var(--brand-grad); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art::before, .auth-art::after { content: ""; position: absolute; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 70%); }
.auth-art::before { width: 420px; height: 420px; right: -120px; top: -120px; }
.auth-art::after { width: 360px; height: 360px; left: -140px; bottom: -160px; }
.auth-art > * { position: relative; z-index: 1; }
.auth-art .brand { color: #fff; font-size: 22px; padding: 0; }
.auth-art .brand .accent { color: #d9d6ff; }
.auth-art h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.03em; margin: 0 0 14px; max-width: 460px; }
.auth-art p { color: rgba(255, 255, 255, .85); max-width: 440px; margin: 0; }
.auth-art ul { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 10px; max-width: 440px; }
.auth-art li { display: flex; gap: 10px; align-items: flex-start; color: rgba(255, 255, 255, .92); }
.auth-art li::before { content: "✓"; flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: rgba(52, 211, 153, .25); color: #a7f3d0; }
.auth-art .foot { color: rgba(255, 255, 255, .7); font-size: 12px; }
.auth-form { display: grid; place-items: center; padding: 32px 24px; }
.auth-form .card { width: 100%; max-width: 420px; padding: 30px; }
.auth-form h1 { font-size: 22px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 11px; margin: 16px 0 18px; border: 1px solid var(--border); }
.tabs button { flex: 1; border: 0; background: transparent; }
.tabs button.on { background: var(--panel); box-shadow: var(--shadow); color: var(--accent); }
.auth-form form .fields { grid-template-columns: 1fr; }
.auth-form button.primary { width: 100%; padding: 11px; }
.auth-form .actions { display: block; }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: 380px; z-index: 20; }
#toast .t { background: #161a2e; color: #fff; padding: 11px 15px; border-radius: 10px; margin-top: 8px; box-shadow: 0 10px 24px rgba(0, 0, 0, .2); }
#toast .t.err { background: #c42d3c; }

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.span-2-1, .grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; z-index: 5; padding: 10px 12px 8px; }
  .side .brand { padding: 0 4px 8px; font-size: 16px; }
  .nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-group, .side-foot, .nav .ico { display: none; }
  .nav a { white-space: nowrap; flex: none; }
  .nav a.active::before { display: none; }
  main { padding: 20px 16px; }
  .topbar { flex-direction: column; }
  .grid.cols-2, form .fields { grid-template-columns: 1fr; }
  .grid.cols-4 { gap: 10px; }
  .stat .value { font-size: 22px; }
  .stat .spark { display: none; }
  .hbar { grid-template-columns: 96px 1fr 48px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 24px; }
  .auth-art h2 { font-size: 24px; }
  .auth-art ul, .auth-art .foot { display: none; }
}
