/* Arka Admin Dashboard — billing & usage. Also copied to /portal/portal.css.
   The :root palette below is SPLICED IN AT BUILD TIME from brand.css (see
   build.ts#copyWithBrandTokens) — edit it there, not here. */

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-card: #161616;
  --border-subtle: #222222;
  --border-accent: #333333;
  --text-primary: #f0f0f0;
  --text-secondary: #999999;
  --text-muted: #666666;
  --accent: #8b0000;
  --accent-hover: #6b0000;
  --accent-glow: rgba(139, 0, 0, 0.15);
  /* The brand red lightened until it stays legible as small text or an icon
     directly on --bg-primary (4.2:1 vs 2.0:1 for --accent). Fills, where the
     foreground is white, keep using --accent. */
  --accent-text: #cb454a;
  --gradient-start: #8b0000;
  --gradient-end: #b22234;

  /* The wash a ghost control paints on hover, and the scrim behind a modal.
     Both are a function of the ground, which is why they are tokens rather
     than the literal rgba() the shell pages used to repeat. */
  --hover-wash: rgba(255, 255, 255, 0.03);
  --scrim: rgba(0, 0, 0, 0.75);

  /* Status. Destructive actions (delete a project, a failed request) and the
     one success note on /auth/. Not brand — a red button here means damage,
     not Arka. --danger-ink is what reads on a --danger FILL. */
  --danger: #ff6b6b;
  --danger-hover: #e05555;
  --danger-wash: rgba(255, 107, 107, 0.4);
  --danger-ink: #1a0000;
  --success: #69db7c;

  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Light. Same names, same contracts, different values — a page swaps ground
   and ink by setting data-theme, never by knowing a hex. The fills
   (--accent, the gradient pair) do NOT flip: white on #8b0000 is 10.4:1 either
   way, and the brand is the brand. --accent-text does flip, because its
   contract is "the brand red made legible as ink on --bg-primary" and on a
   near-white ground that is the true #8b0000 (9.5:1), not the lightened one. */
:root[data-theme="light"] {
  --bg-primary: #fafaf9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --border-subtle: #e7e5e4;
  --border-accent: #d6d3d1;
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #78716c;
  --accent-text: #8b0000;

  --hover-wash: rgba(0, 0, 0, 0.04);
  --scrim: rgba(0, 0, 0, 0.45);

  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-wash: rgba(185, 28, 28, 0.35);
  --danger-ink: #ffffff;
  --success: #2f7d32;
}

:root {
  /* dashboard-only status tokens; the brand palette comes from brand.css */
  --ok: #2e7d32;
  --warn: #b8860b;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.topbar-logo img {
  width: 22px;
  height: 22px;
}

.topbar-title {
  color: var(--text-secondary);
  font-size: 14px;
  border-left: 1px solid var(--border-accent);
  padding-left: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 14px;
}

.topbar-right a,
.topbar-right button {
  color: var(--text-secondary);
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.topbar-right a:hover,
.topbar-right button:hover {
  color: var(--text-primary);
}

/* ---- Layout ---- */
.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 28px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

select,
input[type="month"],
input[type="text"] {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  min-width: 180px;
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-accent);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ---- Cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 22px;
}

.card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card .value {
  font-size: 30px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.card .value.accent {
  color: #ff6b6b;
}

.card .sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
}

.section h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

/* ---- Quota bars ---- */
.quota {
  margin-bottom: 18px;
}

.quota:last-child {
  margin-bottom: 0;
}

.quota-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 6px;
}

.quota-head .used {
  font-family: var(--font-mono);
}

.bar {
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.3s ease;
}

.bar-fill.over {
  background: var(--warn);
}

/* ---- Chart ---- */
.chart {
  width: 100%;
  height: 180px;
}

.chart .axis {
  stroke: var(--border-accent);
  stroke-width: 1;
}

.chart .label {
  fill: var(--text-muted);
  font-size: 9px;
  font-family: var(--font-mono);
}

.legend {
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* ---- Invoice ---- */
.invoice-total {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 6px 0 18px;
}

.invoice-total .amount {
  font-size: 40px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.lines {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.lines td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.lines td:last-child {
  text-align: right;
  font-family: var(--font-mono);
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

/* ---- Table ---- */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-accent);
}

table.data td {
  padding: 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
}

.pill {
  display: inline-block;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-glow);
  color: #ff6b6b;
  font-family: var(--font-sans);
}

/* ---- States ---- */
.notice {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
}

.notice h2 {
  color: var(--text-primary);
  margin-bottom: 10px;
}

.keybox {
  background: var(--bg-secondary);
  border: 1px solid var(--warn);
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
}

.keybox code {
  font-family: var(--font-mono);
  font-size: 14px;
  word-break: break-all;
  color: #ffd479;
}

.keybox .warn {
  color: var(--warn);
  font-size: 13px;
  margin-top: 8px;
}

.muted {
  color: var(--text-muted);
}

.error-banner {
  background: rgba(139, 0, 0, 0.15);
  border: 1px solid var(--accent);
  color: #ff9b9b;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
}

.info-banner {
  background: rgba(46, 125, 50, 0.12);
  border: 1px solid var(--ok);
  color: #9fd4a2;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.info-banner .link {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
}

/* ---- Inputs the console added (search, email, date, textarea) ---- */
input[type="email"],
input[type="search"],
input[type="date"],
textarea {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  min-width: 180px;
}

textarea {
  width: 100%;
  resize: vertical;
  line-height: 1.5;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  padding-bottom: 10px;
}

.check input {
  accent-color: var(--accent);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 24px;
}

.tabs:empty {
  display: none;
}

.tab {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

/* ---- KPI tiles ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 18px;
}

.kpi .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi .value {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.kpi .value.accent {
  color: #ff6b6b;
}

.kpi .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.kpi-link:hover {
  border-color: var(--border-accent);
}

/* ---- Tables: clickable rows, overflow, cell helpers ---- */
.scroll {
  overflow-x: auto;
}

tr.table-link {
  cursor: pointer;
}

tr.table-link:hover td {
  background: var(--bg-secondary);
}

tr.table-link a {
  color: var(--text-primary);
}

table.data td.sans {
  font-family: var(--font-sans);
}

table.data td.actions-cell {
  white-space: nowrap;
  text-align: right;
}

table.data td.actions-cell .btn {
  margin-left: 6px;
}

table.data td.result {
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
}

.tiny {
  font-size: 12px;
}

.mono {
  font-family: var(--font-mono);
}

.grow {
  flex: 1;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row h2 {
  margin-bottom: 0;
}

.row + * {
  margin-top: 18px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.two-col .section {
  margin-bottom: 24px;
}

.code {
  font-family: var(--font-mono);
}

.code.ok {
  color: var(--ok);
}

.code.err,
.err {
  color: #ff9b9b;
}

/* ---- Status pills ---- */
.pill.draft {
  background: rgba(184, 134, 11, 0.18);
  color: #ffd479;
}

.pill.finalized,
.pill.running,
.pill.open {
  background: rgba(78, 121, 167, 0.22);
  color: #9cc2ea;
}

.pill.sent {
  background: rgba(78, 121, 167, 0.35);
  color: #c6dcf3;
}

.pill.paid,
.pill.done,
.pill.active {
  background: rgba(46, 125, 50, 0.2);
  color: #9fd4a2;
}

.pill.void,
.pill.failed,
.pill.suspended {
  background: rgba(139, 0, 0, 0.3);
  color: #ff9b9b;
}

.pill.dismissed,
.pill.muted-pill,
.pill.kind {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.badge.info {
  background: rgba(78, 121, 167, 0.22);
  color: #9cc2ea;
}

.badge.warn {
  background: rgba(184, 134, 11, 0.18);
  color: #ffd479;
}

.badge.critical {
  background: rgba(139, 0, 0, 0.35);
  color: #ff9b9b;
}

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

/* ---- Account header ---- */
.account-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0 4px;
}

.account-title h1 {
  font-size: 24px;
  font-weight: 700;
}

/* ---- Draft queue ---- */
.queue-item {
  border: 1px solid var(--border-accent);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: var(--bg-secondary);
}

.queue-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
}

.queue-head .amount {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.queue-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.queue-actions .check {
  padding-bottom: 0;
}

.sub-h {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.narrative {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* ---- Insights ---- */
.insight {
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--border-accent);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 10px;
  background: var(--bg-secondary);
}

.insight.info {
  border-left-color: #4e79a7;
}

.insight.warn {
  border-left-color: var(--warn);
}

.insight.critical {
  border-left-color: var(--accent);
}

.insight-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.insight-body {
  white-space: pre-wrap;
  font-size: 14px;
  color: var(--text-secondary);
  margin: 6px 0;
}

/* ---- Agent ---- */
.seg {
  display: inline-flex;
  border: 1px solid var(--border-accent);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

.live {
  font-size: 13px;
  color: #9fd4a2;
  padding-bottom: 10px;
}

.answer {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
}

/* ---- Customer dashboard (/portal/): plan picker, change plan, key,
   quickstart, Allowed websites. ---- */
.account-sub {
  margin-bottom: 22px;
  font-size: 14px;
}

.lead {
  color: var(--text-secondary);
  margin-bottom: 18px;
  max-width: 720px;
}

.choose .choose-heading {
  font-size: 22px;
  text-transform: none;
  letter-spacing: -0.2px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 8px 0 4px;
}

.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 20px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-accent);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.plan-card:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.plan-card.is-selected {
  border-color: var(--accent-text);
  box-shadow: 0 0 0 1px var(--accent-text);
}

.plan-card.is-current,
.plan-card:disabled {
  cursor: default;
  opacity: 0.7;
}

/* On the card's top edge, like the landing cards' badge, so a badged card's
   name lines up with its neighbours'. */
.plan-badge {
  position: absolute;
  top: -10px;
  left: 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: #ff9b9b;
}

.plan-name {
  font-size: 16px;
  font-weight: 700;
}

.plan-price {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.plan-allowance {
  font-size: 13px;
  color: var(--text-secondary);
}

.plan-blurb {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-lg {
  padding: 12px 22px;
  font-size: 15px;
}

.fineprint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
  max-width: 760px;
}

.fineprint a,
.lead a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  cursor: pointer;
}

.change-panel {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}

.change-panel h3,
.confirm-box h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.confirm-box {
  margin-top: 16px;
  padding: 16px 18px;
  border: 1px solid var(--warn);
  border-radius: 10px;
  background: var(--bg-secondary);
}

.confirm-box p {
  margin-bottom: 8px;
  font-size: 14px;
}

.confirm-box .actions {
  margin-top: 12px;
}

pre.snippet {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 6px 0 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.step {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.origin-list {
  list-style: none;
  margin: 8px 0 14px;
}

.origin-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.origin-list code {
  font-family: var(--font-mono);
  font-size: 14px;
}

.origin-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.form-row input[type="text"] {
  flex: 1;
  min-width: 240px;
}

.field-error {
  color: #ff9b9b;
  font-size: 13px;
  margin-top: 8px;
}

.field-note {
  color: #9fd4a2;
  font-size: 13px;
  margin-top: 8px;
}

.usage-reset {
  margin-bottom: 18px;
  font-size: 13px;
}

@media print {
  .topbar,
  .tabs,
  .controls,
  .actions,
  .queue-actions {
    display: none;
  }
}
