:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #667085;
  --border: #e3e6eb;
  --primary: #2f6fed;
  --primary-hover: #2559c1;
  --amber-bg: #fdf1d6;
  --amber-text: #8a5a00;
  --green-bg: #dcf5e6;
  --green-text: #12703a;
  --neutral-bg: #eef0f3;
  --neutral-text: #444b57;
  --error-bg: #fde3e3;
  --error-text: #9a1c1c;
  --ok-text: #1a8a4a;
  --fail-text: #c22b2b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --border: #2b2f38;
    --primary: #5b8def;
    --primary-hover: #6f9bf3;
    --amber-bg: #3a2f10;
    --amber-text: #e6b955;
    --green-bg: #123522;
    --green-text: #5fd08c;
    --neutral-bg: #262a33;
    --neutral-text: #c4c9d4;
    --error-bg: #3a1414;
    --error-text: #ff8b8b;
    --ok-text: #5fd08c;
    --fail-text: #ff8b8b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.brand { white-space: nowrap; }
.brand span { font-weight: 400; color: var(--muted); }
.brand:hover { text-decoration: none; }
@media (max-width: 620px) {
  .topbar-inner { padding: 12px 16px; gap: 10px; }
  .brand span { display: none; }
  .nav { gap: 12px; flex-wrap: wrap; row-gap: 6px; justify-content: flex-end; }
}

.nav { display: flex; align-items: center; gap: 18px; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { color: var(--text); text-decoration: none; }
.nav-tenant {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 3px 10px;
  background: var(--neutral-bg);
  border-radius: 999px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link-btn:hover { color: var(--text); text-decoration: underline; }
.inline-form { display: inline; }

.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px;
  width: 100%;
  flex: 1;
}

h1 { margin: 0 0 6px; font-size: 1.6rem; }
h2 { margin: 0 0 14px; font-size: 1.05rem; }
.muted { color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}

.form-section { margin-bottom: 26px; }
.form-section:last-of-type { margin-bottom: 0; }

label { display: block; font-weight: 600; font-size: 0.88rem; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
  cursor: pointer;
}
.checkbox-row input { width: auto; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; margin-top: 20px; }
.btn-test { white-space: nowrap; font-size: 0.85rem; padding: 9px 14px; }
.btn:disabled { opacity: 0.6; cursor: default; }

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

.key-field { margin-bottom: 18px; }
.key-row { display: flex; gap: 10px; align-items: center; }
.key-row input { flex: 1; }
.test-result {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  min-height: 1.1em;
}
.test-ok { color: var(--ok-text); }
.test-fail { color: var(--fail-text); }

.auth-wrap {
  display: flex;
  justify-content: center;
  padding-top: 40px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { text-align: center; }
.auth-card .muted { text-align: center; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.btn-google:hover { border-color: var(--primary); }
.google-icon { width: 18px; height: 18px; flex-shrink: 0; }

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 18px 0;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.auth-divider span { padding: 0 12px; }

.badge-row { display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap; }
.badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-red { background: var(--error-bg); color: var(--error-text); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.stat-row { display: flex; gap: 28px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-size: 1.6rem; font-weight: 700; }

.mini-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.88rem; }
.mini-table th, .mini-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.mini-table th { color: var(--muted); font-weight: 600; }

.def-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.def-list dt { color: var(--muted); font-weight: 600; }
.def-list dd { margin: 0; }

.flash-stack { margin-bottom: 18px; }
.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.flash-success { background: var(--green-bg); color: var(--green-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------
   Onboarding / setup wizard
--------------------------------------------------------------------- */

.onboarding {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 640px;
}

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.step-header h2 { margin: 0; }

.step-number {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.step-optional {
  padding: 0;
}
.step-optional > summary {
  list-style: none;
  cursor: pointer;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 700;
}
.step-optional > summary::-webkit-details-marker { display: none; }
.step-optional > summary .step-number { background: var(--neutral-bg); color: var(--neutral-text); }
.step-optional[open] > summary { border-bottom: 1px solid var(--border); }
.step-optional .step-body { padding: 22px; }
.step-optional h3 { margin: 22px 0 4px; font-size: 0.95rem; }
.step-optional h3:first-child { margin-top: 0; }
.small { font-size: 0.85rem; margin-bottom: 12px; }

.big-input {
  width: 100%;
  padding: 16px 18px;
  font-size: 1.3rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.big-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.key-field { margin-bottom: 6px; }
.key-connected {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.replace-link { font-size: 0.85rem; }

.event-picker { margin-top: 14px; }
.event-picker label { margin-top: 0; }
.event-picker select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.btn-large { padding: 14px 18px; font-size: 1.05rem; }

.welcome-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 22px;
  margin-bottom: 20px;
}
.welcome-banner h1 { margin-bottom: 14px; }
.welcome-banner .badge-row { margin-bottom: 0; }

.radio-group { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 18px; }
.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 400;
  cursor: pointer;
  margin: 0;
}
.radio-row input { width: auto; margin-top: 3px; }

/* ---------------------------------------------------------------------
   Status: usage-at-cost expander
--------------------------------------------------------------------- */

.details-card { padding: 0; }
.details-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 22px;
  font-weight: 700;
  font-size: 1.05rem;
}
.details-card > summary::-webkit-details-marker { display: none; }
.details-card[open] > summary { border-bottom: 1px solid var(--border); }
.details-body { padding: 22px; }

.usage-day-table { margin-bottom: 22px; }
.usage-day-table:last-of-type { margin-bottom: 10px; }
.usage-day-table thead tr:first-child th {
  padding-top: 0;
  font-size: 0.95rem;
  color: var(--text);
  border-bottom: none;
}
.usage-day-total td { font-weight: 700; border-bottom: none; padding-top: 8px; }
.usage-note { margin: 4px 0 0; }

/* --- Review what we found (onboarding deep scan) ------------------------ */
#review-found h3 { margin: 22px 0 4px; font-size: 0.95rem; }
#review-found h3:first-child { margin-top: 0; }
#review-found input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.tag-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 16px;
  margin-top: 8px;
}
.tag-checkbox-grid .checkbox-row { margin: 0; }
.tag-checkbox-grid .badge { margin-left: 6px; font-size: 0.7rem; padding: 2px 8px; }

.workflow-list {
  margin: 8px 0 4px;
  padding-left: 20px;
  color: var(--text);
}
.workflow-list li { margin-bottom: 4px; }

/* ---------------------------------------------------------------------
   Setup hero + owner view-as
--------------------------------------------------------------------- */

.setup-hero { margin-bottom: 28px; }
.setup-hero h1 { font-size: 2rem; margin-bottom: 10px; }
.setup-hero-lede {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  margin: 0 0 10px;
  max-width: 640px;
}
.setup-hero .muted { max-width: 640px; }

.view-as-bar {
  background: var(--amber-bg);
  color: var(--amber-text);
  font-size: 0.88rem;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.view-as-exit { padding: 4px 12px; font-size: 0.82rem; }

.owner-table { width: 100%; }
.owner-table th { text-align: left; color: var(--muted); font-weight: 500; }
.owner-table th, .owner-table td { padding: 8px 10px 8px 0; }
.owner-table .badge { font-size: 0.75rem; }

/* ---------------------------------------------------------------------
   Analytics
--------------------------------------------------------------------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 800px) {
  .tile-grid { grid-template-columns: repeat(2, 1fr); }
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.tile-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.tile-value { font-size: 1.7rem; font-weight: 700; }
.tile-delta { font-size: 0.82rem; margin-top: 4px; }
.tile-delta.good { color: var(--ok-text); }
.tile-delta.bad { color: var(--fail-text); }
.tile-delta.flat { color: var(--muted); }

.trend-section { margin-bottom: 22px; }
.trend-section:last-child { margin-bottom: 0; }
.trend-section h3 { margin: 0 0 10px; font-size: 0.92rem; }
.bar-row {
  display: grid;
  grid-template-columns: 68px 1fr 56px;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 0.8rem;
}
.bar-row .bar-label { color: var(--muted); white-space: nowrap; }
.bar-track {
  background: var(--neutral-bg);
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}
.bar-fill {
  display: block;
  background: var(--primary);
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
}
.bar-row .bar-value { text-align: right; color: var(--text); }

.attention-list { list-style: none; margin: 0; padding: 0; }
.attention-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.attention-list li:last-child { border-bottom: none; }
.attention-ts { color: var(--muted); margin-right: 10px; }

.ntfy-store-links { display: flex; gap: 10px; margin: 10px 0 20px; flex-wrap: wrap; }
.ntfy-topic-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}
.ntfy-topic-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--neutral-bg);
  padding: 8px 12px;
  border-radius: 8px;
  flex: 1;
  word-break: break-all;
  font-size: 0.9rem;
}
.copy-btn { flex: none; }

/* --- First-login "connect your accounts" popup --------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 460px;
  width: 100%;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-card h2 { margin-top: 0; }
.modal-link-list {
  list-style: none;
  margin: 16px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-link-list a {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
.modal-link-list a:hover { background: var(--bg); }
.modal-guide {
  margin: 0 0 20px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}
.modal-guide li { margin-bottom: 4px; }
