:root {
  --bg: #0f1115;
  --bg2: #161a23;
  --surface: #171a21;
  --card: rgba(255, 255, 255, 0.045);
  --card-hover: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.11);
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --faint: #6b7380;
  --accent: #3987e5;
  --accent-track: rgba(57, 135, 229, 0.18);
  --accent-glow: rgba(57, 135, 229, 0.45);
  /* status palette (fixed): good / warning / serious / critical */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  /* categorical: session / weekly / scoped, breakdown surfaces */
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --c4: #c98500;
  --radius: 16px;
  color-scheme: dark;
  font-family:
    ui-rounded,
    'SF Pro Rounded',
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
}
body {
  background: radial-gradient(1200px 700px at 15% -10%, var(--bg2), var(--bg));
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
h1,
h2,
h3 {
  margin: 0 0 0.4em;
  letter-spacing: -0.01em;
}
h3 {
  font-size: 0.95em;
  color: var(--muted);
  font-weight: 600;
  margin-top: 1em;
}
p {
  margin: 0.4em 0;
}
[hidden] {
  display: none !important;
}
a {
  color: var(--accent);
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.1em 0.4em;
  border-radius: 6px;
}
.hint {
  color: var(--muted);
  font-size: 0.9em;
}
.error {
  color: #ff8c9a;
  min-height: 1.3em;
  font-weight: 600;
  font-size: 0.92em;
}
.error:empty {
  min-height: 0;
  margin: 0;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 3em 1em;
  max-width: 520px;
  margin: 0 auto;
}

button {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65em 1.1em;
  transition:
    transform 0.08s ease,
    filter 0.15s ease;
}
button:hover:not(:disabled) {
  filter: brightness(1.2);
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 6px 20px var(--accent-glow);
}
button.bad {
  background: #7a1d2a;
  border-color: transparent;
}
button.ghost {
  background: transparent;
}
button.small {
  padding: 0.45em 0.9em;
  font-size: 0.9em;
}
button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
}
input,
textarea {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7em 0.9em;
  width: 100%;
  outline: none;
}
textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  resize: vertical;
}
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-track);
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  font-size: 0.9em;
  color: var(--muted);
  font-weight: 600;
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.6em;
  color: var(--text);
  font-weight: 500;
}
label.check input {
  width: auto;
}
.row {
  display: flex;
  gap: 0.6em;
  align-items: center;
  flex-wrap: wrap;
}
.row.end {
  justify-content: flex-end;
  margin-top: 0.4em;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0.7em 1.2em;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.logo {
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) 0 62%,
    var(--warning) 62% 78%,
    rgba(255, 255, 255, 0.15) 78% 100%
  );
  box-shadow: 0 0 10px var(--accent-glow);
}
.top-right {
  display: flex;
  align-items: center;
  gap: 0.5em;
}
.who {
  color: var(--muted);
  font-size: 0.9em;
  margin-right: 0.4em;
}

/* ---------- auth ---------- */
.auth .card {
  max-width: 440px;
  margin: 8vh auto;
  padding: 2em 1.6em;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.auth h1 {
  font-size: 1.9em;
}
.tabs {
  display: flex;
  gap: 0.4em;
  margin: 1.2em 0 1em;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 0.5em 0.2em;
  margin-bottom: -1px;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ---------- app ---------- */
.app {
  padding: 1.2em;
  max-width: 1400px;
  margin: 0 auto;
}
.summary {
  display: grid;
  grid-template-columns: minmax(260px, 1.6fr) repeat(
      auto-fit,
      minmax(150px, 1fr)
    );
  gap: 0.8em;
  margin-bottom: 1em;
}
.summary .tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9em 1.1em;
  min-height: 92px;
}
.summary .tile .k {
  color: var(--muted);
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.summary .tile .v {
  font-size: 1.7em;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 0.15em;
  line-height: 1.15;
}
.summary .tile .v.hero {
  font-size: 2.1em;
}
.summary .tile .s {
  color: var(--muted);
  font-size: 0.85em;
  margin-top: 0.2em;
}
.summary .tile.best {
  border-color: rgba(57, 135, 229, 0.5);
  background: linear-gradient(135deg, rgba(57, 135, 229, 0.16), var(--card));
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.8em;
  flex-wrap: wrap;
  margin-bottom: 1em;
}
.toolbar #updated {
  margin-left: auto;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.seg button {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0.45em 0.9em;
  font-size: 0.88em;
  color: var(--muted);
  font-weight: 600;
}
.seg button.active {
  background: var(--card-hover);
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1em;
}
.acct {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1em 1.1em;
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  transition: border-color 0.15s ease;
}
.acct:hover {
  border-color: rgba(255, 255, 255, 0.22);
}
.acct.best {
  border-color: rgba(57, 135, 229, 0.55);
}
.acct .head {
  display: flex;
  align-items: center;
  gap: 0.6em;
}
.acct .head h2 {
  font-size: 1.1em;
  margin: 0 0 0 -2px;
  padding-left: 2px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct .head h2 button {
  font: inherit;
  color: inherit;
  text-align: left;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 2px;
  margin-left: -2px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 700;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill::before {
  content: '';
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: currentColor;
}
.pill.ok {
  color: var(--good);
  border-color: rgba(12, 163, 12, 0.4);
}
.pill.stale {
  color: var(--warning);
  border-color: rgba(250, 178, 25, 0.4);
}
.pill.error,
.pill.auth_error {
  color: var(--critical);
  border-color: rgba(208, 59, 59, 0.4);
}
.pill.pending {
  color: var(--muted);
}
.pill.plan {
  color: var(--muted);
}
.pill.plan::before {
  display: none;
}
.sub {
  font-size: 0.8em;
  color: var(--muted);
  margin-top: -0.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td .sub {
  margin-top: 0.1em;
}
.detail .sub {
  margin: -0.3em 0 0.6em;
}
.acct .msg {
  font-size: 0.82em;
  color: #ff9aa6;
  line-height: 1.35;
}

.meter {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}
.meter .mh {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5em;
}
.meter .ml {
  font-size: 0.85em;
  color: var(--muted);
  font-weight: 600;
}
.meter .mv {
  font-size: 1.35em;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.meter .track {
  height: 8px;
  border-radius: 4px;
  background: var(--accent-track);
  overflow: hidden;
}
.meter.sev-normal .track {
  background: rgba(12, 163, 12, 0.18);
}
.meter.sev-normal .fill {
  background: var(--good);
}
.meter .fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  width: 0;
  transition: width 0.4s ease;
}
.meter .mf {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  font-size: 0.8em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.meter .mf .badge {
  font-weight: 700;
}
.meter.sev-warning .track {
  background: rgba(250, 178, 25, 0.2);
}
.meter.sev-warning .fill {
  background: var(--warning);
}
.meter.sev-warning .badge {
  color: var(--warning);
}
.meter.sev-serious .track {
  background: rgba(236, 131, 90, 0.2);
}
.meter.sev-serious .fill {
  background: var(--serious);
}
.meter.sev-serious .badge {
  color: var(--serious);
}
.meter.sev-critical .track {
  background: rgba(208, 59, 59, 0.22);
}
.meter.sev-critical .fill {
  background: var(--critical);
}
.meter.sev-critical .badge {
  color: var(--critical);
}
.meter.inactive .mv,
.meter.inactive .fill {
  opacity: 0.55;
}

.bd {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}
.bd .bdl {
  font-size: 0.78em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}
.bd .bar {
  display: flex;
  gap: 2px;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
}
.bd .bar span {
  height: 100%;
  min-width: 0;
}
.bd .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em 0.9em;
  font-size: 0.78em;
  color: var(--muted);
}
.bd .legend i {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border-radius: 2px;
  margin-right: 0.35em;
  vertical-align: -0.02em;
}
.k-claude_code {
  background: var(--c1);
}
.k-chat {
  background: var(--c2);
}
.k-cowork {
  background: var(--c3);
}
.k-other {
  background: var(--faint);
}

.spark {
  position: relative;
}
.spark .sl {
  font-size: 0.78em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2em;
}
.spark svg {
  display: block;
  width: 100%;
  height: 44px;
  overflow: visible;
}
.spark path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.spark .area {
  fill: var(--accent);
  opacity: 0.12;
  stroke: none;
}
.spark .hover {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.tip {
  position: absolute;
  pointer-events: none;
  background: #23283a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.3em 0.55em;
  font-size: 0.78em;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  z-index: 3;
  transform: translate(-50%, -110%);
  color: var(--text);
}
.tip b {
  font-variant-numeric: tabular-nums;
}

.acct .foot {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.8em;
  color: var(--muted);
  margin-top: auto;
}
.acct .foot .grow {
  flex: 1;
}

/* ---------- table ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9em;
}
th,
td {
  text-align: left;
  padding: 0.6em 0.8em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(0, 0, 0, 0.2);
}
td.num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
td .mini {
  display: inline-block;
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: var(--accent-track);
  vertical-align: middle;
  margin-right: 0.5em;
  overflow: hidden;
}
td .mini i {
  display: block;
  height: 100%;
  background: var(--accent);
}
td.sev-normal .mini i {
  background: var(--good);
}
td.sev-warning .mini i {
  background: var(--warning);
}
td.sev-serious .mini i {
  background: var(--serious);
}
td.sev-critical .mini i {
  background: var(--critical);
}
tr:last-child td {
  border-bottom: none;
}
tbody tr:hover td {
  background: var(--card);
}

/* ---------- dialogs ---------- */
dialog.dlg {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4em 1.5em;
  width: min(94vw, 520px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog.dlg.wide {
  width: min(96vw, 860px);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}
.howto {
  font-size: 0.88em;
  color: var(--muted);
}
.howto summary {
  cursor: pointer;
  font-weight: 600;
}
.howto ul {
  padding-left: 1.2em;
}
.howto li {
  margin: 0.3em 0;
}

.detail .dh {
  display: flex;
  align-items: center;
  gap: 0.6em;
  flex-wrap: wrap;
}
.detail .dh h2 {
  flex: 1;
  margin: 0;
}
.detail .grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8em 1.2em;
  margin: 0.8em 0;
}
.detail dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25em 0.8em;
  font-size: 0.88em;
}
.detail dt {
  color: var(--muted);
}
.detail dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.chart {
  position: relative;
  margin-top: 0.4em;
}
.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart .grid line {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}
.chart .axis text {
  fill: var(--faint);
  font-size: 11px;
}
.chart .series path {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.chart .cross {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.chart .legend {
  display: flex;
  gap: 1.2em;
  font-size: 0.82em;
  color: var(--muted);
  margin-bottom: 0.4em;
  flex-wrap: wrap;
}
.chart .legend i {
  display: inline-block;
  width: 0.9em;
  height: 3px;
  border-radius: 2px;
  margin-right: 0.4em;
  vertical-align: 0.2em;
}
.chart .tip div {
  display: flex;
  justify-content: space-between;
  gap: 1em;
}
.detail .actions {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
  margin-top: 1em;
}
.detail .danger {
  margin-top: 1em;
  padding-top: 0.8em;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 0.5em;
  align-items: center;
  flex-wrap: wrap;
}
.detail textarea {
  margin-top: 0.4em;
}
.range {
  margin-left: auto;
}

@media (max-width: 600px) {
  .app {
    padding: 0.8em;
  }
  .cards {
    grid-template-columns: 1fr;
  }
  .summary {
    grid-template-columns: 1fr 1fr;
  }
  .summary .tile.best {
    grid-column: 1 / -1;
  }
  .toolbar #updated {
    margin-left: 0;
    width: 100%;
  }
}
