:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2530;
  --muted: #6b7684;
  --line: #e3e7ec;
  --accent: #2b6cb0;
  --accent-soft: #ebf3fb;
  --pos: #1f8a4c;
  --neg: #c0392b;
  --warn-bg: #fdecec;
  --warn-ink: #8a1f1f;
  --info-bg: #eef4fb;
  --info-ink: #204a7a;
  --ok-bg: #edf7f0;
  --ok-ink: #1f6b3d;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

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

/* Layout ---------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  height: 52px;
}
.brand { font-weight: 700; letter-spacing: -0.01em; }
.nav { display: flex; gap: 0.25rem; flex: 1; }
.nav-link {
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
}
.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }
.topbar .session { color: var(--muted); font-size: 0.85rem; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.6rem; }
.subtle { color: var(--muted); }

/* Banners --------------------------------------------------------------- */
.banner {
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--line);
}
.banner-ok { background: var(--ok-bg); color: var(--ok-ink); }
.banner-info { background: var(--info-bg); color: var(--info-ink); }
.banner-error { background: var(--warn-bg); color: var(--warn-ink); font-weight: 600; }

.notice-inline {
  background: var(--info-bg);
  color: var(--info-ink);
  border: 1px solid #cfe0f2;
  border-radius: var(--radius);
  padding: 0.5rem 0.8rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.85rem;
}

.flash { padding: 0.6rem 1rem; font-size: 0.88rem; }
.flash-notice { background: var(--ok-bg); color: var(--ok-ink); }
.flash-alert { background: var(--warn-bg); color: var(--warn-ink); }

/* Panels & tables ------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 0.4rem 0.6rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--bg); }
tfoot td, tr.totals td { font-weight: 700; border-top: 2px solid var(--line); }
td.num, th.num { text-align: right; }
.u { color: var(--ink); }
.eur { color: var(--muted); font-size: 0.82rem; }

/* Deltas & attainment --------------------------------------------------- */
.delta-pos { color: var(--pos); }
.delta-neg { color: var(--neg); }
.attain-good { color: var(--pos); font-weight: 600; }
.attain-bad { color: var(--neg); }

/* Badges ---------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-muted { background: #eef0f2; color: var(--muted); }
.badge-tier_1 { background: #e6f0ff; color: #1e50a0; }
.badge-tier_2 { background: #eaf6ec; color: #256b3b; }
.badge-tier_3 { background: #f3eefe; color: #6b46c1; }
.badge-reactivation { background: #fef3e2; color: #b45309; }
.badge-upsell { background: #e6f0ff; color: #1e50a0; }

/* Forms & buttons ------------------------------------------------------- */
.btn {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-secondary { background: #fff; color: var(--accent); }
.btn-danger { background: #fff; color: var(--neg); border-color: var(--neg); }
.btn-small { padding: 0.2rem 0.5rem; font-size: 0.78rem; }

form.inline-filters { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 0.2rem; }
.field label { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
input, select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.8rem; }
.errors { color: var(--neg); margin-bottom: 0.8rem; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

/* Week navigation (weekly view) ------------------------------------------ */
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.panel-head h2 { margin: 0; }
.week-nav { display: flex; gap: 0.4rem; align-items: center; }
.week-nav-form { display: inline-flex; }
.btn-disabled { opacity: 0.4; pointer-events: none; }
th .th-sub { display: block; font-weight: 400; text-transform: none; letter-spacing: 0; }
td.week-selected, th.week-selected { background: var(--accent-soft); }

/* Commercial plan --------------------------------------------------------- */
.plan-table thead th {
  background: #ee8a1d;
  color: #fff;
  border-bottom: none;
}
.plan-table thead th:first-child { text-transform: uppercase; font-weight: 700; }
.plan-table .plan-objective td { color: var(--muted); font-style: italic; }
.plan-table .plan-cvr td { color: var(--muted); font-size: 0.82rem; }
.plan-table .plan-row-muted td { color: var(--muted); font-style: italic; }
.plan-table .plan-total { font-weight: 700; background: var(--accent-soft); }
.field-check { display: flex; gap: 0.35rem; align-items: center; padding: 0.45rem 0; }
.field-check label { font-size: 0.85rem; color: var(--ink); font-weight: 500; }

.chart-wrap { margin: 0.5rem 0 1rem; }
.metric-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.metric-tabs .btn.active { background: var(--accent); color: #fff; }

/* Overview KPI cards ------------------------------------------------------ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 0.8rem;
}
.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-units {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}
.stat-amount {
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}
.stat-delta { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.stat-delta.good { color: var(--pos); }
.stat-delta.bad { color: var(--neg); }
/* Long names truncate with an ellipsis; the title attribute shows the full
   text on hover. */
td.cell-clip { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

.cell-link { color: inherit; }
.cell-link:hover { color: var(--accent); }
.status-success { color: var(--pos); font-weight: 600; }
.status-failed { color: var(--neg); font-weight: 600; }
.status-running { color: var(--accent); font-weight: 600; }

/* --- Client metrics ------------------------------------------------------ */
.subnav { margin-bottom: 1rem; }
.subnav .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
/* Wide tables (MRR matrix, client roster) scroll inside their panel. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Churned clients in the MRR evolution matrix, like the sheet's red rows. */
.row-churned td { background: #fdecec; }
.row-rollup td { font-weight: 700; border-top: 2px solid var(--border); }
/* Season months that haven't happened yet. */
th.col-future, td.col-future, tr.col-future td { color: var(--muted); }

/* Auth pages (sign in, password reset) ------------------------------------ */
.auth-card {
  max-width: 380px;
  margin: 3rem auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.auth-card h1 { font-size: 1.2rem; }
.auth-card input { width: 100%; padding: 0.55rem 0.6rem; }
.auth-card .btn { width: 100%; padding: 0.55rem 0.85rem; }
.auth-links { text-align: center; font-size: 0.85rem; }
.auth-error { color: var(--neg); font-size: 0.88rem; }
.auth-notice { color: var(--pos); font-size: 0.88rem; }

/* Mobile ------------------------------------------------------------------ */
@media (max-width: 820px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 0.55rem 0.75rem 0;
    gap: 0.5rem;
  }
  .topbar .session { margin-left: auto; }
  /* The nav drops to its own row and swipes horizontally, edge to edge. */
  .nav {
    order: 3;
    flex-basis: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -0.75rem;
    padding: 0 0.75rem 0.55rem;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { white-space: nowrap; flex-shrink: 0; }

  .container { padding: 0.75rem; }
  h1 { font-size: 1.25rem; }
  .panel { padding: 0.75rem; }
  .banner { padding: 0.5rem 0.75rem; }

  /* 16px inputs stop iOS Safari from zooming the page on focus. */
  input, select { font-size: 16px; }

  /* Comfortable tap targets. */
  .btn { padding: 0.5rem 0.9rem; }
  .btn-small { padding: 0.35rem 0.6rem; }
  .nav-link { padding: 0.45rem 0.7rem; }

  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  td.cell-clip { max-width: 140px; }
  .auth-card { margin: 1.5rem auto; }
}
