/* =====================================================================
   Cadence — admin dashboard styles
   Reuses the landing-page brand: warm neutrals, forest-green accent,
   matte finish (soft neutral shadows, no glows). Light + dark themes
   are driven by prefers-color-scheme.
   ===================================================================== */

/* ---------- Design tokens ----------
   LIGHT is the default (matches the real Cadence app screen). The DARK
   override below reuses the landing site's warm-dark palette.            */
:root {
  --bg:        #FDFBF7;  /* warm cream */
  --surface:   #FFFFFF;  /* card */
  --surface-2: #F6F2EA;  /* elevated / hover */
  --text:      #2D3748;  /* ink */
  --muted:     #718096;  /* muted */
  --accent:    #2F855A;  /* forest — fills w/ white text */
  --accent-2:  #38A169;  /* brighter green */
  --accent-ink:#2F855A;  /* readable green text on light */
  --border:    #EBE6DC;  /* warm hairline */
  --tint:      #F3EFE7;  /* subtle tint */
  --green-tint:#EDF7F1;  /* green surface (badges/highlights) */
  --green-line:#CFE7DA;  /* green hairline */

  /* Semantic status colors (text on their tinted background) */
  --ok-tint:   #EDF7F1;  --ok-line:   #CFE7DA;  --ok-ink:   #1F6B44;
  --warn-tint: #FCEFD6;  --warn-line: #F0DCB4;  --warn-ink: #8A5410;
  --bad-tint:  #FCE9E7;  --bad-line:  #F3CFCB;  --bad-ink:  #A23A2E;
  --info-tint: #E7F0FE;  --info-line: #CFE0FA;  --info-ink: #2C5FBF;

  --radius-sm: 12px;
  --radius:    16px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(45, 55, 72, .08);
  --shadow:    0 8px 24px rgba(45, 55, 72, .12);
  --shadow-md: 0 18px 46px rgba(45, 55, 72, .16);

  --focus:     rgba(47, 133, 90, .45);
  --ease:      cubic-bezier(.22, 1, .36, 1);
  --topbar-h:  62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #16130D;
    --surface:   #201C14;
    --surface-2: #29241A;
    --text:      #F3EEE3;
    --muted:     #A79D89;
    --accent:    #276749;
    --accent-2:  #33885B;
    --accent-ink:#5FBE90;
    --border:    #342F22;
    --tint:      #1C1810;
    --green-tint:#1B271F;
    --green-line:#2B5E43;

    --ok-tint:   #16271D;  --ok-line:   #2B5E43;  --ok-ink:    #6FCE9C;
    --warn-tint: #2A2212;  --warn-line: #5A481F;  --warn-ink:  #E7C078;
    --bad-tint:  #2A1815;  --bad-line:  #5A2E28;  --bad-ink:   #EC8C7E;
    --info-tint: #16202E;  --info-line: #2C466E;  --info-ink:  #7FB0F0;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 8px 24px rgba(0, 0, 0, .45);
    --shadow-md: 0 18px 46px rgba(0, 0, 0, .55);
  }
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden; /* page body never scrolls sideways */
}
h1, h2, h3 { line-height: 1.2; letter-spacing: -.02em; margin: 0; font-weight: 700; }
p { margin: 0; }
button { font: inherit; }
input, select { font: inherit; color: inherit; }
svg { display: block; }

/* Accessible focus ring — visible in both themes */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="tab"]:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Screen-reader-only helper */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* =====================================================================
   BRAND MARK
   ===================================================================== */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__logo { width: 30px; height: 30px; display: block; flex: none; }
.brand__logo svg { width: 100%; height: 100%; }
.brand__word { font-weight: 700; font-size: 1.15rem; letter-spacing: -.02em; }
.brand__tag {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--green-tint);
  border: 1px solid var(--green-line);
  padding: 2px 8px;
  border-radius: 999px;
}

/* =====================================================================
   BUTTONS
   ===================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: .95rem;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .15s var(--ease), background .2s var(--ease),
              box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.btn--sm { padding: 7px 14px; font-size: .88rem; }
.btn--block { width: 100%; }

.btn--primary {
  color: #fff;
  background: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: var(--accent-2); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn--primary:active { transform: translateY(0); }

.btn--ghost {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
.btn--ghost:hover { border-color: var(--green-line); background: var(--surface-2); transform: translateY(-1px); }

.btn:disabled,
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* Small table-row action button */
.btn--row { padding: 5px 12px; font-size: .82rem; border-radius: 999px; }

/* =====================================================================
   FORM FIELDS
   ===================================================================== */
.field { display: grid; gap: 6px; }
.field__label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
}
.field__input {
  width: 100%;
  padding: 11px 13px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.field__input::placeholder { color: var(--muted); opacity: .8; }
.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
.field__input:read-only {
  background: var(--tint);
  color: var(--muted);
  cursor: default;
}
.field__input--code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .4em;
  text-align: center;
  font-size: 1.15rem;
}
.field__select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
  cursor: pointer;
}

/* =====================================================================
   LOGIN VIEW
   ===================================================================== */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: clamp(26px, 5vw, 38px);
}
.login__brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login__eyebrow {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  margin-bottom: 6px;
}
.login__lead { color: var(--muted); font-size: .95rem; margin-bottom: 22px; }
.login__form { display: grid; gap: 16px; }
.login__code-row { display: grid; gap: 16px; }
.login__error { color: var(--bad-ink); font-size: .9rem; font-weight: 500; min-height: 1.2em; }
.login__error:empty { min-height: 0; }

/* =====================================================================
   APP SHELL + TOPBAR
   ===================================================================== */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--topbar-h);
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: clamp(16px, 3vw, 28px);
}
.topbar__account { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__email {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 500;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tab strip */
.tabs {
  display: flex;
  gap: 4px;
  max-width: 1200px;
  margin-inline: auto;
  padding: 0 clamp(16px, 3vw, 28px);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 600;
  font-size: .95rem;
  padding: 13px 14px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .18s var(--ease), border-color .18s var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--accent-ink);
  border-bottom-color: var(--accent);
}

/* =====================================================================
   CONTENT + PANELS
   ===================================================================== */
.content {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding: clamp(20px, 3vw, 32px) clamp(16px, 3vw, 28px) 64px;
}
.panel { display: block; }

.panel__toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.field--search { flex: 1 1 260px; max-width: 420px; }
.panel__count { color: var(--muted); font-size: .9rem; font-weight: 500; }

/* =====================================================================
   OVERVIEW — STAT TILES
   ===================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow-sm);
}
.stat-tile--accent {
  background: var(--green-tint);
  border-color: var(--green-line);
}
.stat-tile__label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
}
.stat-tile__value {
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat-tile--accent .stat-tile__value { color: var(--accent-ink); }

/* =====================================================================
   OVERVIEW — CHART CARDS
   ===================================================================== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}
.chart-card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  box-shadow: var(--shadow-sm);
}
.chart-card__title {
  font-size: .98rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 14px;
}
/* Empty <svg> containers — responsive, fixed height, drawn by the JS */
.chart {
  display: block;
  width: 100%;
  height: 180px;
  overflow: visible;
}

/* =====================================================================
   TABLES
   ===================================================================== */
/* Tables scroll horizontally inside their own container on narrow screens */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: .92rem;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--tint);
  padding: 12px 16px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table__empty {
  text-align: center;
  color: var(--muted);
  padding: 34px 16px;
}
/* Primary identifier cell */
.table td:first-child { font-weight: 600; }

/* =====================================================================
   DIALOG (Grant plan)
   ===================================================================== */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.dialog::backdrop {
  background: rgba(20, 16, 10, .5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.dialog__form { display: grid; gap: 16px; padding: clamp(22px, 4vw, 30px); }
.dialog__title { font-size: 1.25rem; }
.dialog__error { color: var(--bad-ink); font-size: .9rem; font-weight: 500; min-height: 1.2em; }
.dialog__error:empty { min-height: 0; }
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* =====================================================================
   BADGES (status pills) — toggled by JS
   ===================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .01em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--muted);
  background: var(--tint);
  border: 1px solid var(--border);
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge--active  { color: var(--ok-ink);   background: var(--ok-tint);   border-color: var(--ok-line); }
.badge--trial   { color: var(--info-ink);  background: var(--info-tint); border-color: var(--info-line); }
.badge--pending { color: var(--warn-ink);  background: var(--warn-tint); border-color: var(--warn-line); }
.badge--expired { color: var(--bad-ink);   background: var(--bad-tint);  border-color: var(--bad-line); }

/* =====================================================================
   TOAST (status / error region)
   ===================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  font-size: .92rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
}
/* JS adds a modifier/visible state; support common patterns without ids */
.toast:not(:empty) {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.is-error { border-left-color: var(--bad-ink); }

/* =====================================================================
   LOADING BAR
   ===================================================================== */
.loading {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 70;
  background: transparent;
  overflow: hidden;
  opacity: 0;
  transition: opacity .2s var(--ease);
}
.loading.is-busy { opacity: 1; }
.loading__bar {
  display: block;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 0 3px 3px 0;
  transform: translateX(-100%);
}
.loading.is-busy .loading__bar {
  animation: loading-slide 1.1s var(--ease) infinite;
}
@keyframes loading-slide {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(130%); }
  100% { transform: translateX(320%); }
}

/* =====================================================================
   UTILITY CLASSES (toggled by JS)
   ===================================================================== */
.hidden { display: none; }

/* Off-screen holder for the shared SVG gradient. A paint server referenced from
   a display:none subtree is not reliably resolved, so it must stay rendered
   (but zero-sized) rather than hidden. */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Secondary text inside a table cell, and numerals that should align. */
.muted { color: var(--muted); }
.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.is-busy { cursor: progress; }
/* On a button, .is-busy dims and blocks interaction */
button.is-busy { opacity: .7; pointer-events: none; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 560px) {
  .topbar__email { max-width: 40vw; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .panel__toolbar { align-items: stretch; }
}

/* =====================================================================
   REDUCED MOTION
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .001ms; animation-duration: .001ms; animation-iteration-count: 1; }
}
