/* intelligence.hoq.app — self-contained shell + dashboard.
   Follows the Hoq theme convention: :root is LIGHT (the base), html[data-theme=dark]
   overrides, and the toggle stamps data-theme on <html> against the shared
   `tiko-theme` localStorage key — so this page agrees with every other Hoq surface. */
:root {
  --bg: #eef3f3;
  --surface: #ffffff;
  --panel: #ffffff;
  --inset: #f4f7f7;
  --line: #e2e9e9;
  --line2: #d3dcdc;
  --text: #12201f;
  --muted: #5b6d70;
  --hover: rgba(15, 157, 143, .07);
  --accent: #0f9d8f;
  --accent-bright: #0b7c70;
  --accent-ink: #ffffff;
  --bad: #c0392b;
  --ok: #177d51;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 40, .05), 0 16px 36px -20px rgba(20, 40, 40, .16);
  --glow: rgba(15, 157, 143, .06);
}
html[data-theme=dark] {
  --bg: #0b1114;
  --surface: #0f171b;
  --panel: #0f171b;
  --inset: #142126;
  --line: #1e2b30;
  --line2: #2b444c;
  --text: #e7eef0;
  --muted: #8fa3a8;
  --hover: rgba(47, 212, 190, .08);
  --accent: #2fd4be;
  --accent-bright: #2fd4be;
  --accent-ink: #062b26;
  --bad: #f87f8e;
  --ok: #4ad4a0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 36px -20px rgba(0, 0, 0, .65);
  --glow: rgba(47, 212, 190, .09);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[hidden] { display: none !important; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }

/* ---- top bar ---- */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 30;
}
.topbar .spacer { flex: 1; }
.topbar .brand { font-size: 15px; letter-spacing: -.01em; }
.tb-div { width: 1px; height: 20px; background: var(--line2); }
.who { font-size: 12.5px; color: var(--muted); max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line2);
  background: var(--inset); color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:hover { border-color: var(--accent); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  font: inherit; font-size: 13px; font-weight: 550;
  border: 1px solid var(--line2); border-radius: 9px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost { padding: 6px 11px; font-size: 12.5px; color: var(--muted); background: transparent; }
.btn--ghost:hover { color: var(--bad); border-color: var(--bad); }
.btn--lg { font-size: 15px; padding: 12px 22px; }

/* ---- sign-in gate ---- */
.boot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.gate {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, var(--glow), transparent 60%), var(--bg);
}
.gate-card { text-align: center; max-width: 440px; padding: 32px; }
.gate-card .mark { font-size: 38px; color: var(--accent); }
.gate-card h1 { margin: 14px 0 8px; font-size: 24px; letter-spacing: -.02em; }
.gate-card p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

/* ---- app switcher (ported from Hoq\Apps\AppRegistry::styles) ---- */
.app-switch { position: relative; display: inline-block; }
.brand-btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .5rem; margin: -.3rem -.5rem;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--text);
  font: inherit; font-weight: 700; font-size: 1rem; letter-spacing: -.01em; cursor: pointer;
}
.brand-btn:hover { border-color: var(--line); background: var(--surface); }
.brand-mark { line-height: 1; }
.brand-caret { width: 11px; height: 11px; opacity: .55; flex: none; }
.app-menu-head {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .62rem;
  text-transform: uppercase; letter-spacing: .15em; color: var(--muted); padding: .4rem .55rem .5rem;
}
.app-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40; width: min(21rem, 86vw); padding: .4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.app-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: .15rem .7rem; align-items: center;
  padding: .55rem .6rem; border-radius: 10px; text-decoration: none; color: var(--text);
}
.app-item:hover, .app-item.current { background: var(--hover); }
.app-item svg { grid-row: span 2; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .8; }
.app-item.current .app-name:after { content: " ·"; opacity: .6; }
.app-item.soon { opacity: .5; cursor: default; }
.app-name { font-weight: 600; font-size: .9rem; }
.app-tag { grid-column: 2; font-size: .75rem; color: var(--muted); line-height: 1.3; }
.app-soon { grid-row: span 2; font-size: .65rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---- dashboard ---- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 26px 20px 60px; }
.hero { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; margin-bottom: 22px; }
.bal {
  flex: 1 1 240px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 20px 22px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.bal .lbl { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.bal .amt { font-size: 38px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
/* Money is always 6dp. The cents are the number; the tail is precision, dimmed and
   smaller, so the eye reads $5.00 while the decimal still aligns down a column. */
.frac { opacity: .45; font-size: .62em; font-weight: 500; letter-spacing: 0; }
.bal--low .amt { color: var(--bad); }
.bal .warn { margin-top: 6px; font-size: 12.5px; color: var(--bad); }
.topup { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.btn--amt { padding: 7px 12px; font-variant-numeric: tabular-nums; }
.topup-err { margin: 8px 0 0; font-size: 12.5px; color: var(--bad); }
.stats { flex: 2 1 420px; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stat .lbl { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stat .val { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11.5px; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: baseline; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card.empty { padding: 34px 20px; text-align: center; }
.card.empty h2 { margin: 0 0 6px; font-size: 16px; }
.card.empty p { margin: 0; color: var(--muted); font-size: 13.5px; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 18px 20px 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.bar-fill { width: 100%; max-width: 26px; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; }
.bar:hover .bar-fill { opacity: 1; }
.bar-day { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 20px; border-bottom: 1px solid var(--line); }
td { padding: 10px 20px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--inset); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 650; } .dim { color: var(--muted); } .pos { color: var(--ok); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; background: var(--inset); color: var(--muted); }
.chip--cache { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.newkey { display: flex; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.newkey input { flex: 1; padding: 9px 12px; border: 1px solid var(--line2); border-radius: 9px; background: var(--inset); color: var(--text); font: inherit; font-size: 13.5px; }
.keyout { padding: 14px 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.keyout code { display: block; padding: 9px 12px; margin-top: 7px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; word-break: break-all; }
.keyout .note { font-size: 12.5px; color: var(--muted); }

@media (max-width: 640px) {
  .hero { flex-direction: column; }
  .chart { height: 90px; }
  th, td { padding: 9px 12px; }
  .wrap { padding: 18px 12px 40px; }
}

/* ---- tags ----------------------------------------------------------------
   A tag is recognised by its colour before its name, which is the whole reason
   colour is stored on it: twenty tags in a list are unreadable as plain text.
   Each hue is defined once here as a pair (ink, wash) so light and dark stay in
   step, and the bar fill reuses the same ink. */
.tag {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .2em .6em .2em .5em; border-radius: 999px;
  font-size: .78rem; line-height: 1.6; white-space: nowrap;
  background: var(--tag-wash); color: var(--tag-ink);
  border: 1px solid color-mix(in srgb, var(--tag-ink) 22%, transparent);
}
.tag i { width: .5em; height: .5em; border-radius: 50%; background: var(--tag-ink); flex: none; }
.tag-x {
  border: 0; background: none; cursor: pointer; padding: 0 0 0 .15em;
  color: inherit; opacity: .55; font-size: 1.05em; line-height: 1;
}
.tag-x:hover { opacity: 1; }

.tag--slate  { --tag-ink: #5b6d70; --tag-wash: color-mix(in srgb, #5b6d70 12%, transparent); }
.tag--indigo { --tag-ink: #5b5bd6; --tag-wash: color-mix(in srgb, #5b5bd6 12%, transparent); }
.tag--teal   { --tag-ink: #0f9d8f; --tag-wash: color-mix(in srgb, #0f9d8f 12%, transparent); }
.tag--amber  { --tag-ink: #b7791f; --tag-wash: color-mix(in srgb, #b7791f 14%, transparent); }
.tag--rose   { --tag-ink: #c2255c; --tag-wash: color-mix(in srgb, #c2255c 12%, transparent); }
.tag--violet { --tag-ink: #8b5cf6; --tag-wash: color-mix(in srgb, #8b5cf6 13%, transparent); }
.tag--lime   { --tag-ink: #4d7c0f; --tag-wash: color-mix(in srgb, #4d7c0f 13%, transparent); }
.tag--cyan   { --tag-ink: #0e7490; --tag-wash: color-mix(in srgb, #0e7490 12%, transparent); }
html[data-theme=dark] .tag--slate  { --tag-ink: #9fb3b7; }
html[data-theme=dark] .tag--indigo { --tag-ink: #a5a5f5; }
html[data-theme=dark] .tag--teal   { --tag-ink: #2fd4be; }
html[data-theme=dark] .tag--amber  { --tag-ink: #e9b949; }
html[data-theme=dark] .tag--rose   { --tag-ink: #f78fb0; }
html[data-theme=dark] .tag--violet { --tag-ink: #c4a7fb; }
html[data-theme=dark] .tag--lime   { --tag-ink: #a3d955; }
html[data-theme=dark] .tag--cyan   { --tag-ink: #5fc9e8; }

.tagnew { display: flex; gap: .5rem; margin-bottom: .9rem; }
.tagnew input { flex: 1; }

.tags { display: flex; flex-direction: column; gap: .7rem; }
.tagrow-head { display: flex; align-items: center; gap: .6rem; }
.tagrow-meta { color: var(--muted); font-size: .78rem; }
.tagrow-spend { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.tag-del {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  opacity: 0; transition: opacity .15s; font-size: 1.1em; line-height: 1; padding: 0 .1em;
}
.tagrow:hover .tag-del, .tag-del:focus-visible { opacity: .7; }
.tag-del:hover { opacity: 1; color: var(--bad); }

/* Named tagbar, NOT bar: the daily chart already owns .bar/.bar-fill for its
   vertical columns (max-width 26px, centred), and reusing the name gave every
   tag a little centred dash instead of a track. A collision like that does not
   error — it just renders wrong.

   The bar is a ranking, not a scale — it is relative to the biggest tag, which
   is what "where is the money going" actually asks. */
.tagbar { height: 4px; border-radius: 999px; background: var(--inset); margin-top: .35rem; overflow: hidden; }
.tagbar-fill { display: block; height: 100%; border-radius: 999px; background: var(--tag-ink, var(--accent)); }
.tagbar--slate { --tag-ink: #5b6d70; } .tagbar--indigo { --tag-ink: #5b5bd6; }
.tagbar--teal { --tag-ink: #0f9d8f; } .tagbar--amber { --tag-ink: #b7791f; }
.tagbar--rose { --tag-ink: #c2255c; } .tagbar--violet { --tag-ink: #8b5cf6; }
.tagbar--lime { --tag-ink: #4d7c0f; } .tagbar--cyan { --tag-ink: #0e7490; }

/* ---- keys ---------------------------------------------------------------- */
.keys { display: flex; flex-direction: column; }
.keyrow {
  display: grid; grid-template-columns: minmax(8rem, 1fr) minmax(0, 2fr) auto auto;
  align-items: center; gap: .9rem; padding: .75rem 0;
  border-top: 1px solid var(--line);
}
.keyrow:first-child { border-top: 0; }
.keyrow-main { display: flex; flex-direction: column; min-width: 0; }
.keyname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.keydate { font-size: .74rem; }
.keytags { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.keyspend { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.keyspend .dim { font-size: .74rem; }
.keyrevoke { padding: .3rem .7rem; font-size: .8rem; }

.picker { position: relative; }
.tag-add {
  border: 1px dashed var(--line2); background: none; color: var(--muted);
  border-radius: 999px; padding: .18em .6em; font-size: .76rem; cursor: pointer;
}
.tag-add:hover { color: var(--text); border-color: var(--muted); }
.picker-menu {
  position: absolute; z-index: 20; top: calc(100% + .35rem); left: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: .35rem; min-width: 11rem;
  max-height: 15rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: .15rem;
}
.picker-opt { border: 0; background: none; text-align: left; padding: .25rem; cursor: pointer; border-radius: 8px; }
.picker-opt:hover { background: var(--hover); }

@media (max-width: 640px) {
  .keyrow { grid-template-columns: 1fr auto; row-gap: .5rem; }
  .keytags { grid-column: 1 / -1; }
  .keyspend { align-items: flex-start; }
}
