/* RoofQuery back office.
   Same palette as the customer dashboard — deep blue sidebar, white cards on a
   soft grey field — so the two read as one product rather than two.

   The token block and the layout primitives are shared in spirit with
   dashboard/assets/app.css. They're a copy rather than an import because the
   two services ship as separate images with separate static roots; keep them
   roughly in step, but this file is free to diverge where the console needs
   denser tables than a customer ever should.

   What tells you which side you're on is the env badge pinned to the bottom of
   the sidebar: Stripe mode, provider, environment. That's the distinction that
   actually matters before you refund something. */

:root {
  --primary: #1668B8;
  --primary-dark: #12558F;
  --primary-darker: #0B3D6B;
  --primary-tint: #E8F1FA;
  --accent: #2FA8E0;

  /* Console chrome — the dashboard's sidebar colour, same on both sides. */
  --shell: #0B3D6B;
  --shell-deep: #0B3D6B;

  --text-body: #55606C;
  --text-dark: #1E2530;

  --bg-light: #F1F3F6;
  --bg-white: #ffffff;
  --border: #E2E7ED;
  --border-input: #D3D9E0;

  --green: #27AE60;
  --amber: #E08A2F;
  --red: #C0392B;

  --radius-btn: 10px;
  --radius-card: 12px;

  --font-main: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-heading: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

body {
  font-family: var(--font-main);
  font-size: 15px;
  background: var(--bg-light);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }
.hidden { display: none !important; }

/* ── Typography ─────────────────────────────────────────────── */
.h1 {
  font-family: var(--font-heading);
  font-size: 28px; font-weight: 800; color: var(--text-dark);
  letter-spacing: -.02em; margin: 0 0 4px;
}
.h2 {
  font-family: var(--font-heading);
  font-size: 17px; font-weight: 700; color: var(--text-dark);
  letter-spacing: -.01em; margin: 0 0 12px;
}
.h3 {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .9px;
  color: var(--text-body); margin: 20px 0 8px;
}
.sub { color: var(--text-body); font-size: 13px; margin: 0 0 18px; }
.mono { font-family: var(--mono); font-size: 12.5px; word-break: break-all; color: var(--text-dark); }
.muted { color: var(--text-body); opacity: .85; }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ── Layout ─────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 235px; flex-shrink: 0;
  background: var(--shell);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; align-self: flex-start; overflow-y: auto;
}
.brand {
  display: block;
  font-family: var(--font-heading);
  font-size: 23px; font-weight: 800; color: #fff;
  letter-spacing: -.02em; text-decoration: none;
  padding: 22px 20px 6px;
}
.account-label {
  font-family: var(--mono); font-size: 11.5px;
  color: rgba(255,255,255,.62);
  padding: 6px 20px 0; margin-bottom: 1.25rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.nav-section {
  font-size: 10px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase;
  color: rgba(255,255,255,.32); padding: 14px 20px 5px;
}
.nav-item {
  display: block; padding: 10px 20px;
  color: rgba(255,255,255,.72); font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  border-left: 3px solid transparent; transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(47,168,224,.16); border-left-color: var(--accent); color: #fff; }

/* Which Stripe account and which provider this console is wired to. Pinned to
   the bottom of the sidebar because "am I about to refund test money or real
   money" is the question you need answered without asking for it. */
.env-badge {
  margin-top: auto; padding: 14px 20px 18px;
  font-size: 10.5px; line-height: 1.7; letter-spacing: .04em;
  color: rgba(255,255,255,.5); border-top: 1px solid rgba(255,255,255,.08);
}
.env-badge b { color: #fff; font-weight: 700; }
.env-badge .danger { color: #FF9A8B; }

.main { flex: 1; min-width: 0; padding: 26px 28px 40px; }

.section { display: none; }
.section.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px; margin-bottom: 18px;
}
.card.tight { padding: 14px 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat-label {
  font-size: 10.5px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .9px; color: var(--text-body);
}
.stat-value {
  font-family: var(--font-heading);
  font-size: 32px; font-weight: 800; color: var(--text-dark);
  letter-spacing: -.03em; line-height: 1; margin-top: 8px;
}
.stat-note { font-size: 12px; color: var(--text-body); margin-top: 7px; }

/* ── Tables ─────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th {
  font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-body); padding: 0 8px 9px; text-align: left;
  border-bottom: 2px solid var(--bg-light);
}
td {
  padding: 10px 8px; border-bottom: 1px solid var(--bg-light);
  font-size: 13px; vertical-align: middle; color: var(--text-dark);
}
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--primary-tint); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

code {
  font-family: var(--mono); font-size: .85em;
  background: var(--bg-light); color: var(--text-dark);
  padding: .12em .4em; border-radius: 4px;
}
pre {
  background: var(--primary-darker); color: #E6EEF5;
  padding: 14px 16px; border-radius: var(--radius-btn);
  overflow: auto; font-size: 11.5px; line-height: 1.55;
  font-family: var(--mono); max-height: 340px;
}
pre code { background: transparent; color: inherit; padding: 0; }

/* ── Pills ──────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  white-space: nowrap;
}
.pill.live, .pill.ok { background: #E8F8F0; color: var(--green); }
.pill.test, .pill.warn { background: #FDF2E3; color: var(--amber); }
.pill.err { background: #FDECEA; color: var(--red); }
.pill.info { background: var(--primary-tint); color: var(--primary); }
.pill.mute { background: var(--bg-light); color: var(--text-body); }

/* ── Controls ───────────────────────────────────────────────── */
.btn {
  font-family: var(--font-main); font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  border: none; border-radius: var(--radius-btn); cursor: pointer;
  padding: 10px 17px; line-height: 1;
  background: var(--primary); color: #fff;
  display: inline-block; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary {
  background: var(--bg-light); color: var(--primary);
  border: 1px solid var(--border-input);
}
.btn.secondary:hover { background: var(--primary-tint); }
.btn.ghost { background: transparent; color: var(--text-body); }
.btn.ghost:hover { background: var(--bg-light); color: var(--primary); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #A93226; }
.btn.small { padding: 6px 11px; font-size: 11px; }

label {
  display: block;
  font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-body); margin: 16px 0 6px;
}
label:first-of-type { margin-top: 0; }

input, select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-input); border-radius: var(--radius-btn);
  font-size: 14px; font-family: inherit;
  color: var(--text-dark); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22,104,184,.18);
}
textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 12px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }

.empty { padding: 30px; text-align: center; color: var(--text-body); font-size: 13px; }

/* ── Key/value grid ─────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 20px; }
.kv .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-body); opacity: .75; }
.kv .v { font-size: 14px; color: var(--text-dark); font-weight: 600; word-break: break-word; }

/* ── Tabs (order detail) ────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 2px solid var(--bg-light); margin-bottom: 16px;
}
.tab {
  padding: 9px 13px; cursor: pointer;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-body); background: transparent; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab:hover { color: var(--text-dark); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Timeline (webhook + provider feeds) ────────────────────── */
.event {
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  padding: 11px 13px; margin-bottom: 8px;
}
.event.fail { border-color: #F2C4BE; background: #FEF7F6; }
.event-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.event-title { font-weight: 700; color: var(--text-dark); font-size: 13px; }
.event-time { font-size: 11.5px; color: var(--text-body); margin-left: auto; }
.event-body { margin-top: 8px; }
.event summary {
  cursor: pointer; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; color: var(--primary);
  margin-top: 8px;
}
.event details[open] summary { margin-bottom: 8px; }

/* ── Bar chart ──────────────────────────────────────────────── */
.chart {
  display: flex; align-items: flex-end; gap: 2px;
  height: 150px; padding-top: 10px;
}
.chart .bar { flex: 1; min-width: 2px; position: relative; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart .bar i {
  display: block; width: 100%; border-radius: 3px 3px 0 0;
  background: var(--primary); min-height: 2px;
}
.chart .bar.empty-day i { background: var(--border); }
.chart .bar:hover i { background: var(--accent); }
/* Native tooltip rather than a custom one — it survives every layout. */
.chart .bar { cursor: default; }
.chart-axis {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 11px; color: var(--text-body);
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(11,61,107,.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 1000;
}
.modal-bg.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius-card); padding: 24px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal.wide { max-width: 1040px; }

/* Receipt-style summary for anything that moves money. */
.confirm-lines {
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  padding: 4px 14px; margin-top: 1.25rem;
}
.confirm-line {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 10px 0; border-bottom: 1px solid var(--bg-light);
  font-size: 13.5px; color: var(--text-body);
}
.confirm-line:last-child { border-bottom: none; }
.confirm-line strong { color: var(--text-dark); font-weight: 700; text-align: right; }
.confirm-line.total { border-top: 2px solid var(--bg-light); }
.confirm-line.total strong {
  font-family: var(--font-heading); font-size: 22px; font-weight: 800; letter-spacing: -.02em;
}

/* Anything irreversible says so before it happens. */
.warn-box {
  border: 1px solid #F0D6A8; background: #FEF9F0;
  border-radius: var(--radius-btn); padding: 12px 14px;
  font-size: 12.5px; color: #8A6116; margin-top: 14px;
}

/* ── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 1100;
  max-width: min(400px, calc(100vw - 40px));
  opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast .inner {
  background: var(--primary-darker); color: #fff;
  padding: 12px 16px; border-radius: var(--radius-btn);
  font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#toast.ok .inner { background: var(--green); }
#toast.err .inner { background: var(--red); }
#toast.warn .inner { background: var(--amber); }

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 400px; background: #fff;
  border-radius: var(--radius-card); overflow: hidden;
  box-shadow: 0 10px 30px rgba(11,61,107,.15);
}
.login-head { background: var(--primary-darker); padding: 28px 24px; text-align: center; }
.login-head .brand { padding: 0; }
.login-body { padding: 28px; }
.login-body .h1 { font-size: 28px; margin-bottom: 6px; }
.err-text { color: var(--red); font-size: 12.5px; margin-top: 12px; display: none; }
.err-text.show { display: block; }

/* Turnstile's challenge. The slot is empty until the button is pressed, so the
   spacing only opens up once there's something to space. */
.turnstile-slot { display: flex; justify-content: center; margin: 28px 0 4px; }
.turnstile-slot:empty { margin: 0; }

/* ── Mobile ─────────────────────────────────────────────────── */
.mobile-bar { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 900px) {
  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 60;
    height: 54px; padding: 0 14px; background: var(--primary-darker);
  }
  .mobile-title {
    color: #fff; font-family: var(--font-heading);
    font-size: 17px; font-weight: 700; letter-spacing: -.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .menu-btn {
    flex-shrink: 0; width: 38px; height: 38px; padding: 9px 8px;
    display: flex; flex-direction: column; justify-content: space-between;
    background: transparent; border: none; cursor: pointer;
  }
  .menu-btn span {
    display: block; height: 2px; border-radius: 2px; background: #fff;
    transition: transform .2s, opacity .2s;
  }
  body.nav-open .menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  body.nav-open .menu-btn span:nth-child(2) { opacity: 0; }
  body.nav-open .menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 80;
    width: 268px; max-width: 84vw; height: 100dvh;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  body.nav-open .sidebar { transform: translateX(0); }

  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: rgba(11,61,107,.5);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .main { padding: 18px 16px 32px; }
  .card { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .modal { padding: 18px; }
  .modal.wide { max-width: 100%; }

  /* Record tables become cards, each cell carrying its own column name —
     sideways scrolling on a phone buries the status and the buttons. */
  .card table.table-cards { display: block; overflow: visible; }
  .table-cards thead { display: none; }
  .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    border: 1px solid var(--border); border-radius: var(--radius-btn);
    padding: 12px 14px; margin-bottom: 10px;
  }
  .table-cards tr:last-child { margin-bottom: 0; }
  .table-cards td {
    border: none; padding: 5px 0; text-align: left;
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  }
  .table-cards td::before {
    content: attr(data-label); flex-shrink: 0;
    font-size: 10.5px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase;
    color: var(--text-body); opacity: .75;
  }
  .table-cards td:not([data-label]) { display: block; }
  .table-cards td .mono { white-space: normal; word-break: break-all; text-align: right; }

  /* Plain data tables that aren't records just scroll. */
  .card table:not(.table-cards) { display: block; max-width: 100%; overflow-x: auto; }
  .card table:not(.table-cards) th { white-space: nowrap; }

  .kv { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 14px; }
  .chart { height: 110px; }
}
