/* ===== Algoura design system ===== */
:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f8fafc; --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e2e8f0; --line-2: #cbd5e1;
  --brand: #f26a21; --brand-600: #d95a15; --brand-50: #fff4ec; --brand-100: #ffe4d1;
  --navy: #0b1220; --navy-2: #131c33; --accent: #2563eb; --accent-50: #eff6ff;
  --ok: #15803d; --ok-50: #f0fdf4; --warn: #b45309; --warn-50: #fffbeb; --bad: #b91c1c; --bad-50: #fef2f2;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 8px 24px rgba(15,23,42,.06);
  --shadow-lg: 0 20px 60px rgba(15,23,42,.18);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -.01em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: ui-monospace, Menlo, monospace; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } .between { justify-content: space-between; } .grow { flex: 1; }
.right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none !important; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #ff8f4d, var(--brand)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px; box-shadow: 0 4px 12px rgba(242,106,33,.35); }
.brand .name { font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand .name small { display: block; font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; transition: .15s; white-space: nowrap; text-decoration: none !important; line-height: 1.2; }
.btn:hover { background: var(--brand-600); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand-600); background: var(--brand-50); }
.btn.soft { background: var(--brand-50); color: var(--brand-600); }
.btn.soft:hover { background: var(--brand-100); }
.btn.dark { background: var(--navy); } .btn.dark:hover { background: #1e293b; }
.btn.danger { background: var(--bad); } .btn.danger:hover { background: #991b1b; }
.btn.danger.ghost { background: #fff; color: var(--bad); border-color: #fecaca; } .btn.danger.ghost:hover { background: var(--bad-50); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.lg { padding: 14px 26px; font-size: 15px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn .cost { font-size: 11px; font-weight: 700; background: rgba(255,255,255,.22); padding: 2px 7px; border-radius: 999px; }
.btn.ghost .cost { background: var(--brand-50); color: var(--brand-600); }

/* Cards & layout bits */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 18px; }
.card h2 { font-size: 17px; margin-bottom: 14px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.card h3 { font-size: 12px; margin: 20px 0 10px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .09em; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card h3::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.card.flat { box-shadow: none; }
.section-note { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--muted); } .crumb b { color: var(--ink); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea { width: 100%; padding: 10px 13px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; outline: none; transition: .15s; font-size: 14px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(242,106,33,.15); }
.input.sm, .select.sm { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.textarea { min-height: 84px; resize: vertical; }
.help { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.switch { position: relative; width: 40px; height: 22px; background: var(--line-2); border-radius: 999px; cursor: pointer; transition: .15s; display: inline-block; vertical-align: middle; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: var(--ok); } .switch.on::after { left: 21px; }

/* Badges & chips */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.badge.green { background: var(--ok-50); color: var(--ok); } .badge.red { background: var(--bad-50); color: var(--bad); }
.badge.amber { background: var(--warn-50); color: var(--warn); } .badge.blue { background: var(--accent-50); color: var(--accent); }
.badge.gray { background: #f1f5f9; color: #475569; } .badge.orange { background: var(--brand-50); color: var(--brand-600); }
.badge.navy { background: var(--navy); color: #fff; }
.chip { display: inline-block; background: #f1f5f9; border-radius: 6px; padding: 2px 9px; font-size: 11.5px; color: #475569; }
.chip.link { color: var(--accent); cursor: pointer; } .chip.link:hover { background: var(--accent-50); }
.src-badge { font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 3px 9px; border-radius: 6px; }
.src-badge.primary { background: var(--accent-50); color: var(--accent); }
.src-badge.fallback { background: var(--brand-50); color: var(--brand-600); border: 1px dashed var(--brand); }
.credit-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--navy); color: #fff; border-radius: 999px; padding: 6px 14px 6px 10px; font-weight: 700; font-size: 13px; cursor: pointer; }
.credit-pill .coin { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(135deg, #fde68a, #f59e0b); display: inline-grid; place-items: center; font-size: 10px; color: #78350f; }
.credit-pill.low { background: var(--bad); }

/* Tables */
.tbl-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; background: var(--surface-2); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; border-bottom: 1px solid var(--line); font-weight: 700; }
td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfe; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 14px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.stat .val { font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--ink); letter-spacing: -.02em; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--brand); }

/* KV */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 26px; }
.kv { padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.kv .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.kv .v { font-size: 13.5px; font-weight: 600; margin-top: 2px; word-break: break-word; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px; }
.tab:hover { color: var(--ink); } .tab.active { color: var(--brand-600); border-bottom-color: var(--brand); }

/* Feedback */
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 34px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box, .info-box, .ok-box, .warn-box { border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; font-size: 13.5px; }
.error-box { background: var(--bad-50); border: 1px solid #fecaca; color: var(--bad); } .error-box b { display: block; margin-bottom: 2px; }
.info-box { background: var(--accent-50); border: 1px solid #bfdbfe; color: #1e40af; }
.warn-box { background: var(--warn-50); border: 1px solid #fde68a; color: var(--warn); }
.ok-box { background: var(--ok-50); border: 1px solid #bbf7d0; color: var(--ok); }
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .25s ease; max-width: 380px; }
.toast.charge { background: #14532d; } .toast.err { background: #7f1d1d; } .toast.ok { background: #14532d; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
#modal-bg { position: fixed; inset: 0; background: rgba(11,18,32,.55); backdrop-filter: blur(2px); z-index: 300; display: none; align-items: center; justify-content: center; padding: 20px; }
#modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 16px; padding: 26px; max-width: 560px; width: 100%; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto; animation: pop .2s ease; }
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin-bottom: 8px; font-size: 18px; }
.modal p { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
pre.raw { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 10px; overflow: auto; font-size: 12px; max-height: 480px; margin-top: 10px; }
details.rawtoggle summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 12px; user-select: none; }

/* Simple bar chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding: 6px 0 0; border-bottom: 1px solid var(--line); }
.bars .bar { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .9; }
.bars .bar:hover { opacity: 1; } .bars .bar.alt { background: var(--accent); }
.bars .bar .tip { display: none; position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; font-size: 11px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 5; }
.bars .bar:hover .tip { display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* Avatar */
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #1e293b, #475569); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 90; display: none; }
.menu.open { display: block; }
.menu a, .menu button { display: flex; width: 100%; text-align: left; background: none; border: none; padding: 9px 12px; border-radius: 8px; color: var(--ink); font-weight: 500; cursor: pointer; text-decoration: none !important; gap: 8px; align-items: center; }
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 6px 0; }
.menu .head { padding: 8px 12px; font-size: 12px; color: var(--muted); }
.menu .head b { display: block; color: var(--ink); font-size: 13px; }

@media (max-width: 720px) { .card { padding: 16px; } .container { padding: 0 16px; } .modal { padding: 20px; } }
