/* ============================================================
   ATS Holidays — design system
   Mobile-first. Breakpoints: base = phone, >=768px tablet, >=1024px desktop.

   Philosophy: this is a tool people use all day to read numbers. Clarity beats
   decoration — restrained colour, strong typographic hierarchy, soft elevation
   instead of hard borders, and motion only where it explains a change.
   ============================================================ */

/* ---------- tokens ---------- */

:root {
  color-scheme: light dark;

  /* Neutrals — a warm-cool grey ramp, not pure grey */
  --c-bg:            #f7f8fa;
  --c-bg-sunken:     #eef0f4;
  --c-surface:       #ffffff;
  --c-surface-2:     #fbfcfd;
  --c-border:        #e3e7ec;
  --c-border-strong: #ccd3db;

  --c-text:          #10151b;
  --c-text-muted:    #5d6875;
  --c-text-subtle:   #8a94a1;

  /* One accent, used sparingly */
  --c-accent:        #2563eb;
  --c-accent-hover:  #1d4ed8;
  --c-accent-soft:   #eff4ff;
  --c-accent-ring:   rgba(37, 99, 235, 0.32);

  --c-success:       #0f7b45;
  --c-success-soft:  #e7f6ee;
  --c-warning:       #9a6206;
  --c-warning-soft:  #fdf3e0;
  --c-danger:        #c0332b;
  --c-danger-soft:   #fdeceb;

  /* Back-compat aliases (older markup references these) */
  --color-bg: var(--c-bg);
  --color-surface: var(--c-surface);
  --color-border: var(--c-border);
  --color-text: var(--c-text);
  --color-text-muted: var(--c-text-muted);
  --color-primary: var(--c-accent);
  --color-primary-dark: var(--c-accent-hover);
  --color-danger: var(--c-danger);
  --color-danger-bg: var(--c-danger-soft);
  --color-warning: var(--c-warning);
  --color-warning-bg: var(--c-warning-soft);
  --color-success: var(--c-success);
  --color-success-bg: var(--c-success-soft);

  /* Elevation — layered and soft, never a hard drop shadow */
  --sh-1: 0 1px 2px rgba(16, 21, 27, .04), 0 1px 3px rgba(16, 21, 27, .06);
  --sh-2: 0 2px 4px rgba(16, 21, 27, .04), 0 6px 16px rgba(16, 21, 27, .07);
  --sh-3: 0 8px 24px rgba(16, 21, 27, .10), 0 2px 6px rgba(16, 21, 27, .06);

  /* Space scale */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --nav-height: 60px;
  --sidebar-width: 236px;
  --gap: var(--s-3);
  --touch-target: 44px;

  /* Motion — short, eased, never bouncy */
  --ease: cubic-bezier(.32, .72, .32, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
}

/* Dark palette.
   Declared twice on purpose, and the two blocks MUST stay in sync:
     1. the media query covers visitors with JavaScript off, who never get a
        data-theme attribute at all;
     2. the attribute selector covers an explicit choice from the toggle, and
        must beat the system preference in both directions.
   :not([data-theme="light"]) is what lets an explicit "light" win over a
   system that prefers dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg:            #0d1014;
    --c-bg-sunken:     #090b0e;
    --c-surface:       #14181e;
    --c-surface-2:     #191e25;
    --c-border:        #242b34;
    --c-border-strong: #333c47;

    --c-text:          #e8ecf1;
    --c-text-muted:    #9aa5b2;
    --c-text-subtle:   #6c7885;

    --c-accent:        #5b93f7;
    --c-accent-hover:  #7aa9fa;
    --c-accent-soft:   #16233c;
    --c-accent-ring:   rgba(91, 147, 247, 0.38);

    --c-success:       #3fbd77;
    --c-success-soft:  #10251a;
    --c-warning:       #dda644;
    --c-warning-soft:  #2a2011;
    --c-danger:        #ef6b60;
    --c-danger-soft:   #2c1614;

    --sh-1: 0 1px 2px rgba(0,0,0,.30), 0 1px 3px rgba(0,0,0,.24);
    --sh-2: 0 2px 4px rgba(0,0,0,.30), 0 6px 16px rgba(0,0,0,.34);
    --sh-3: 0 8px 24px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.30);
  }
}

/* Explicit dark — chosen from the toggle. Keep in sync with the block above. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --c-bg:            #0d1014;
  --c-bg-sunken:     #090b0e;
  --c-surface:       #14181e;
  --c-surface-2:     #191e25;
  --c-border:        #242b34;
  --c-border-strong: #333c47;

  --c-text:          #e8ecf1;
  --c-text-muted:    #9aa5b2;
  --c-text-subtle:   #6c7885;

  --c-accent:        #5b93f7;
  --c-accent-hover:  #7aa9fa;
  --c-accent-soft:   #16233c;
  --c-accent-ring:   rgba(91, 147, 247, 0.38);

  --c-success:       #3fbd77;
  --c-success-soft:  #10251a;
  --c-warning:       #dda644;
  --c-warning-soft:  #2a2011;
  --c-danger:        #ef6b60;
  --c-danger-soft:   #2c1614;

  --sh-1: 0 1px 2px rgba(0,0,0,.30), 0 1px 3px rgba(0,0,0,.24);
  --sh-2: 0 2px 4px rgba(0,0,0,.30), 0 6px 16px rgba(0,0,0,.34);
  --sh-3: 0 8px 24px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.30);
}

/* Explicit light needs only to pin color-scheme; the :root defaults above
   already carry the light palette. */
:root[data-theme="light"] { color-scheme: light; }

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

html { -webkit-text-size-adjust: 100%; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Inter var", Inter, ui-sans-serif, system-ui, -apple-system,
               "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  font-variant-numeric: tabular-nums;
}

/* ---------- typography ---------- */

h1, h2, h3, h4 {
  margin: 0 0 var(--s-3);
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--c-text);
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; letter-spacing: -0.015em; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }

p { margin: 0 0 var(--s-3); }
small { font-size: .82rem; color: var(--c-text-muted); }

a {
  color: var(--c-accent);
  text-decoration: none;
  transition: color var(--dur-1) var(--ease);
}
a:hover { color: var(--c-accent-hover); text-decoration: underline; text-underline-offset: 2px; }

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .86em;
  background: var(--c-bg-sunken);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: .1em .38em;
}

/* ---------- app shell ---------- */

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3);
  height: var(--nav-height);
  padding: 0 var(--s-4);
  background: color-mix(in srgb, var(--c-surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.app-header__title { font-weight: 620; letter-spacing: -0.02em; }

.app-header__menu-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 1.05rem;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.app-header__menu-btn:hover { background: var(--c-bg-sunken); border-color: var(--c-border-strong); }

.app-main {
  flex: 1;
  padding: var(--s-4);
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- cards ---------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-4);
  box-shadow: var(--sh-1);
  transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
  animation: rise var(--dur-3) var(--ease) both;
}
.card:hover { box-shadow: var(--sh-2); }

/* Stagger the first few cards so a page assembles rather than snapping in. */
.card:nth-of-type(1) { animation-delay: 0ms; }
.card:nth-of-type(2) { animation-delay: 40ms; }
.card:nth-of-type(3) { animation-delay: 80ms; }
.card:nth-of-type(4) { animation-delay: 120ms; }
.card:nth-of-type(n+5) { animation-delay: 150ms; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: var(--touch-target);
  padding: 0 var(--s-4);
  border-radius: var(--radius);
  border: 1px solid var(--c-accent);
  background: var(--c-accent);
  color: #fff;
  font-family: inherit;
  font-size: .92rem;
  font-weight: 550;
  letter-spacing: -0.01em;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  transition: background var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease),
              transform var(--dur-1) var(--ease),
              opacity var(--dur-1) var(--ease);
}
.btn:hover { background: var(--c-accent-hover); border-color: var(--c-accent-hover); text-decoration: none; box-shadow: var(--sh-2); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--c-accent-ring); }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn--secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border-strong);
}
.btn--secondary:hover { background: var(--c-bg-sunken); border-color: var(--c-border-strong); color: var(--c-text); }

.btn--danger { background: var(--c-danger); border-color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger); border-color: var(--c-danger); filter: brightness(.92); }

.btn .icon { width: 1.05em; height: 1.05em; flex: none; }

/* ---------- forms ---------- */

.form-group { margin-bottom: var(--s-4); }

label {
  display: block;
  margin-bottom: var(--s-2);
  font-size: .86rem;
  font-weight: 550;
  color: var(--c-text);
  letter-spacing: -0.01em;
}
label small { font-weight: 400; }

.form-control {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--s-2) var(--s-3);
  font-family: inherit;
  font-size: .95rem;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.form-control::placeholder { color: var(--c-text-subtle); }
.form-control:hover { border-color: var(--c-text-subtle); }
.form-control:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-ring);
}
textarea.form-control { min-height: 90px; line-height: 1.55; resize: vertical; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235d6875' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  background-size: 15px;
  padding-right: var(--s-6);
}
input[type="checkbox"], input[type="radio"] {
  width: 17px; height: 17px;
  accent-color: var(--c-accent);
  vertical-align: -3px;
  margin-right: var(--s-1);
  cursor: pointer;
}
label:has(input[type="checkbox"]), label:has(input[type="radio"]) { font-weight: 450; cursor: pointer; }

.field-error {
  margin-top: var(--s-2);
  font-size: .84rem;
  color: var(--c-danger);
}

/* ---------- flash messages ---------- */

.flash {
  display: flex; align-items: flex-start; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius);
  margin-bottom: var(--s-4);
  font-size: .9rem;
  border: 1px solid transparent;
  animation: slide-in var(--dur-3) var(--ease) both;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.flash--success { background: var(--c-success-soft); border-color: color-mix(in srgb, var(--c-success) 26%, transparent); color: var(--c-success); }
.flash--error   { background: var(--c-danger-soft);  border-color: color-mix(in srgb, var(--c-danger) 26%, transparent);  color: var(--c-danger); }
.flash--warning { background: var(--c-warning-soft); border-color: color-mix(in srgb, var(--c-warning) 26%, transparent); color: var(--c-warning); }

/* ---------- badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.6;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge--success { background: var(--c-success-soft); color: var(--c-success); border-color: color-mix(in srgb, var(--c-success) 22%, transparent); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: color-mix(in srgb, var(--c-warning) 22%, transparent); }
.badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger);  border-color: color-mix(in srgb, var(--c-danger) 22%, transparent); }

/* ---------- tables ---------- */

.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.rate-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .88rem;
}
.rate-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--c-surface-2);
  padding: var(--s-3);
  text-align: left;
  font-size: .74rem;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-text-muted);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.rate-table tbody td {
  padding: var(--s-3);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
  text-align: center;
}
.rate-table tbody tr { transition: background var(--dur-1) var(--ease); }
.rate-table tbody tr:hover td { background: var(--c-accent-soft); }
.rate-table tbody tr:last-child td { border-bottom: 0; }

.rate-cell--saving { opacity: .5; }
.rate-cell--warning { color: var(--c-warning); font-weight: 600; }
.rate-cell__input {
  width: 100%;
  min-width: 70px;
  padding: 4px 6px;
  font: inherit;
  text-align: center;
  border: 1px solid var(--c-accent);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  outline: none;
  box-shadow: 0 0 0 3px var(--c-accent-ring);
}
[data-editable-cell] { cursor: cell; transition: background var(--dur-1) var(--ease); }
[data-editable-cell]:hover { background: color-mix(in srgb, var(--c-accent) 10%, transparent); }

/* ---------- bottom tab bar (mobile) ---------- */

.tab-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  display: flex;
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--c-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-nav a, .tab-nav__btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  min-height: var(--nav-height);
  text-decoration: none;
  color: var(--c-text-muted);
  font-size: .69rem;
  font-weight: 500;
  letter-spacing: .01em;
  position: relative;
  transition: color var(--dur-1) var(--ease);
}
.tab-nav__btn { background: none; border: 0; cursor: pointer; font-family: inherit; }
.tab-nav a:hover, .tab-nav__btn:hover { color: var(--c-text); }

.tab-nav a.is-active { color: var(--c-accent); }
.tab-nav a.is-active::before {
  content: "";
  position: absolute; top: 0; left: 50%;
  width: 26px; height: 2px;
  transform: translateX(-50%);
  background: var(--c-accent);
  border-radius: 0 0 3px 3px;
  animation: tab-in var(--dur-2) var(--ease) both;
}
@keyframes tab-in { from { width: 0; opacity: 0; } to { width: 26px; opacity: 1; } }

.tab-nav__icon { font-size: 1.15rem; line-height: 1; }
.tab-nav .icon { width: 20px; height: 20px; }

/* ---------- sidebar ---------- */

.sidebar { display: none; }

/* Mobile: slide-out overlay */
.sidebar.is-open {
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  width: min(84vw, 300px);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: var(--s-3);
  overflow-y: auto;
  box-shadow: var(--sh-3), 0 0 0 100vmax rgba(6, 9, 13, .5);
  animation: slide-from-left var(--dur-3) var(--ease);
}
@keyframes slide-from-left { from { transform: translateX(-100%); } to { transform: none; } }

.sidebar a, .sidebar.is-open a {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 9px var(--s-3);
  border-radius: var(--radius);
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.sidebar a:hover, .sidebar.is-open a:hover {
  background: var(--c-bg-sunken);
  color: var(--c-text);
  text-decoration: none;
}
.sidebar a.is-active, .sidebar.is-open a.is-active {
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-weight: 570;
}
.sidebar a.is-active::before {
  content: "";
  position: absolute; left: 0; top: 50%;
  width: 3px; height: 17px;
  transform: translateY(-50%);
  border-radius: 0 3px 3px 0;
  background: var(--c-accent);
}
.sidebar .icon { width: 17px; height: 17px; flex: none; opacity: .85; }
.sidebar a.is-active .icon { opacity: 1; }

.sidebar__brand {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-4);
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--c-text);
}
.sidebar__mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--c-accent), color-mix(in srgb, var(--c-accent) 55%, #22d3ee));
  color: #fff;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: -.03em;
  box-shadow: var(--sh-1);
}

.sidebar__section {
  padding: var(--s-4) var(--s-3) var(--s-2);
  font-size: .68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--c-text-subtle);
}

/* Collapsible group */
.nav-group { margin-bottom: 2px; }
.nav-group > summary {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 9px var(--s-3);
  border-radius: var(--radius);
  color: var(--c-text-muted);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.nav-group > summary:hover { background: var(--c-bg-sunken); color: var(--c-text); }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after {
  content: "";
  margin-left: auto;
  width: 14px; height: 14px;
  background: currentColor;
  opacity: .5;
  transition: transform var(--dur-2) var(--ease);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E") center/contain no-repeat;
}
.nav-group[open] > summary::after { transform: rotate(180deg); }
.nav-group > summary.is-active { color: var(--c-accent); }
.nav-group__item { padding-left: 42px !important; font-size: .87rem; }
.nav-group[open] .nav-group__item { animation: rise var(--dur-2) var(--ease) both; }

/* ---------- stat tiles (dashboard) ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s-3);
}
.stat {
  padding: var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.stat__label {
  display: flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--c-text-muted);
  margin-bottom: var(--s-2);
}
.stat__value { font-size: 1.7rem; font-weight: 650; letter-spacing: -0.03em; line-height: 1.1; }
.stat__meta { font-size: .8rem; color: var(--c-text-subtle); margin-top: 3px; }

/* A stat tile that is also a link. Reads as a tile, behaves as a link. */
.stat--link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease),
              transform var(--dur-2) var(--ease);
}
.stat--link:hover {
  border-color: var(--c-border-strong);
  box-shadow: var(--sh-2);
  transform: translateY(-1px);
}
.stat--link:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.stat--link .stat__meta { color: var(--c-accent); }

/* ---------- live sync indicator ---------- */

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .85rem;
  color: var(--c-text-muted);
  white-space: nowrap;
}

/* A dot rather than a spinner: this ticks every few seconds all day, and a
   spinning thing in the corner of a work screen is exhausting. */
.sync-status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-text-subtle);
  flex: none;
}
.sync-status--busy::before { background: var(--c-accent); animation: sync-pulse 1s var(--ease) infinite; }
.sync-status--ok::before   { background: var(--c-success); }
.sync-status--warn         { color: var(--c-warning); }
.sync-status--warn::before { background: var(--c-warning); }

@keyframes sync-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .35; transform: scale(.75); }
}

@media (prefers-reduced-motion: reduce) {
  .sync-status--busy::before { animation: none; }
}

/* ---------- plain-English option list ---------- */

.mail-filter {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--s-4);
  margin: 0 0 var(--s-4);
  background: var(--c-bg-sunken);
}

.mail-filter legend {
  padding: 0 var(--s-2);
  font-weight: 620;
  letter-spacing: -0.01em;
}

/* A whole row is the click target, not just the 13px box. */
.opt {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}
.opt:hover { background: var(--c-surface); }

.opt input[type="checkbox"] {
  width: 18px; height: 18px;
  margin: 1px 0 0;
  flex: none;
  accent-color: var(--c-accent);
  cursor: pointer;
}

.opt span { display: block; }
.opt strong { display: block; font-weight: 560; }
.opt small {
  display: block;
  margin-top: 2px;
  color: var(--c-text-muted);
  line-height: 1.45;
}

/* Restates the choices as a sentence, so the effect is legible without
   knowing Gmail's syntax. */
.mail-filter__summary {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  margin: var(--s-3) 0 0;
  padding: var(--s-3);
  border-radius: var(--radius);
  background: var(--c-success-soft);
  color: var(--c-text);
  font-size: .9rem;
}
.mail-filter__summary .icon {
  flex: none;
  width: 16px; height: 16px;
  margin-top: 2px;
  color: var(--c-success);
}

.mail-filter__adv { margin-top: var(--s-4); }
.mail-filter__adv summary {
  cursor: pointer;
  font-size: .88rem;
  color: var(--c-text-muted);
  padding: var(--s-2) 0;
}
.mail-filter__adv summary:hover { color: var(--c-text); }
.mail-filter__adv[open] summary { margin-bottom: var(--s-1); }

/* ---------- theme toggle ---------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  background: var(--c-bg-sunken);
  position: relative;
  flex: none;
}

.theme-toggle__btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--c-text-subtle);
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color var(--dur-2) var(--ease);
}
.theme-toggle__btn:hover { color: var(--c-text-muted); }
.theme-toggle__btn[aria-pressed="true"] { color: var(--c-accent); }
.theme-toggle__btn .icon { width: 16px; height: 16px; }
.theme-toggle__btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 1px; }

/* The moving pill sits behind the two icons and slides between them. */
.theme-toggle__thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--c-surface);
  box-shadow: var(--sh-1);
  transition: transform var(--dur-3) var(--ease);
  z-index: 0;
}
/* Mirrors the palette selectors exactly, so the thumb is on the right side
   from the very first paint — including for a system-dark visitor who has
   never touched the toggle, and with JavaScript off. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__thumb { transform: translateX(32px); }
}
:root[data-theme="dark"]  .theme-toggle__thumb { transform: translateX(32px); }
:root[data-theme="light"] .theme-toggle__thumb { transform: none; }

/* Repaint the whole page smoothly when the theme flips. app.js adds this class
   for the length of the crossfade only — leaving it on permanently would make
   every ordinary hover fade over 240ms. The reduced-motion block at the bottom
   of this file overrides it, so those users get an instant swap. */
.theme-changing,
.theme-changing *:not(.theme-toggle__thumb) {
  transition: background-color var(--dur-3) var(--ease),
              border-color var(--dur-3) var(--ease),
              color var(--dur-3) var(--ease) !important;
}

/* On the sign-in screen there is no header to sit in, so pin it to the corner. */
.auth-body .theme-toggle {
  position: fixed;
  top: var(--s-4);
  right: var(--s-4);
  z-index: 50;
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Visible to screen readers, not to eyes. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- icons ---------- */

.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; fill: none;
        stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- misc ---------- */

hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--s-5) 0; }

details > summary { cursor: pointer; }

::selection { background: var(--c-accent-ring); }

/* Scrollbars — visible enough to grab, quiet enough to ignore */
* { scrollbar-width: thin; scrollbar-color: var(--c-border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--c-border-strong); border-radius: 6px; border: 3px solid var(--c-bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--c-text-subtle); }

/* Keyboard focus, everywhere */
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- tablet ---------- */

@media (min-width: 768px) {
  body { font-size: 15px; }
  .app-main { padding: var(--s-5); }
  .card { padding: var(--s-5); }
  h1 { font-size: 1.7rem; }
}

/* ---------- desktop ---------- */

@media (min-width: 1024px) {
  body { display: flex; padding-bottom: 0; }

  .tab-nav { display: none; }

  .sidebar {
    display: flex; flex-direction: column;
    width: var(--sidebar-width);
    min-height: 100vh;
    position: sticky; top: 0;
    max-height: 100vh;
    overflow-y: auto;
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    padding: var(--s-3);
    flex-shrink: 0;
  }

  .app-shell { flex: 1; min-width: 0; }
  .app-header__menu-btn { display: none; }
  .app-header { background: color-mix(in srgb, var(--c-bg) 78%, transparent); }
}

/* ---------- print ---------- */

@media print {
  .sidebar, .tab-nav, .app-header, .btn { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; animation: none; }
  body { padding: 0; background: #fff; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Dashboard charts
   --------------------------------------------------------------------------
   The charts are inline SVG rendered on the server (App\Core\Chart), so every
   colour here is a token rather than a hex value and dark mode needs no second
   palette. Nothing below depends on JavaScript: the page prints as it reads.
   ========================================================================== */

.chart-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-4);
}
.chart-row > .card { margin-bottom: 0; }

.sec-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 1rem; font-weight: 650; margin: 0 0 2px;
}
.sec-note { font-size: .82rem; color: var(--c-text-muted); margin: 0 0 var(--s-3); }
.sub-title {
  font-size: .78rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--c-text-muted); margin: var(--s-4) 0 var(--s-2);
}

/* The SVG itself. Width 100% with a viewBox does the scaling; the height is
   left to the aspect ratio so a narrow column does not crush the bars. */
.ct { width: 100%; height: auto; display: block; overflow: visible; }
.ct-axis { font-size: 9px; fill: var(--c-text-subtle); font-family: inherit; }

.ct-legend {
  list-style: none; margin: var(--s-2) 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4);
  font-size: .78rem; color: var(--c-text-muted);
}
.ct-legend li { display: flex; align-items: center; gap: 6px; }
.ct-legend__v { color: var(--c-text); font-weight: 600; }
.ct-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

.donut-wrap { display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; }
.ct-donut { width: 148px; height: 148px; flex: none; }
.donut-wrap .ct-legend { flex-direction: column; gap: 6px; min-width: 140px; }

/* Said instead of drawing an empty grid: a grid with no bars reads as "we sold
   nothing" when it usually means "nothing has been entered yet". */
.chart-empty {
  padding: var(--s-5) var(--s-4);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
  font-size: .85rem;
  text-align: center;
}

/* Ranked horizontal bars — the right shape when the labels are words. */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 1fr) 2.2fr auto; align-items: center; gap: var(--s-3); }
.hbar__label { font-size: .85rem; color: var(--c-text); }
.hbar__track { background: var(--c-bg-sunken); border-radius: 3px; height: 10px; overflow: hidden; }
.hbar__fill { height: 100%; border-radius: 3px; }
.hbar__value { font-size: .85rem; font-weight: 650; white-space: nowrap; }
.hbar__meta { font-weight: 400; color: var(--c-text-subtle); font-size: .78rem; }

/* The funnel. Each stage carries its own drop-off, because the useful number
   in a funnel is never the count — it is where the people went. */
.funnel { display: flex; flex-direction: column; gap: var(--s-3); }
.funnel__row { display: flex; flex-direction: column; gap: 4px; }
.funnel__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-2); }
.funnel__label { font-size: .85rem; font-weight: 600; }
.funnel__value { font-size: 1.05rem; font-weight: 650; }
.funnel__track { background: var(--c-bg-sunken); border-radius: 4px; height: 14px; overflow: hidden; }
.funnel__fill { height: 100%; border-radius: 4px; }
.funnel__meta { font-size: .76rem; color: var(--c-text-subtle); }

/* The verdicts: the sentence first, the chart underneath as the evidence. */
.verdicts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.verdict {
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: var(--s-3);
  padding: var(--s-3); border-radius: var(--radius);
  background: var(--c-surface-2); border: 1px solid var(--c-border);
}
.verdict__dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.verdict--good .verdict__dot  { background: var(--c-success); }
.verdict--watch .verdict__dot { background: var(--c-warning); }
.verdict--bad .verdict__dot   { background: var(--c-danger); }
.verdict--good  { border-left: 3px solid var(--c-success); }
.verdict--watch { border-left: 3px solid var(--c-warning); }
.verdict--bad   { border-left: 3px solid var(--c-danger); }
.verdict__text { font-size: .9rem; font-weight: 600; }
.verdict__action { font-size: .82rem; color: var(--c-text-muted); margin-top: 2px; }
.verdict__link { font-size: .82rem; white-space: nowrap; }

.mini-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--s-3); margin-top: var(--s-2);
}
.mini-grid--4 { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.mini-grid > div {
  padding: var(--s-3); background: var(--c-surface-2);
  border: 1px solid var(--c-border); border-radius: var(--radius);
}
.mini__v { display: block; font-size: 1.15rem; font-weight: 650; letter-spacing: -.02em; }
.mini__l { display: block; font-size: .74rem; color: var(--c-text-muted); margin-top: 2px; }

.stat__unit { font-size: .9rem; font-weight: 500; color: var(--c-text-muted); margin-left: 2px; }

.table--tight th, .table--tight td { padding: 6px 8px; font-size: .84rem; }
.table .num, .table--tight .num { text-align: right; white-space: nowrap; }

@media print {
  .chart-row { grid-template-columns: 1fr 1fr; }
  .verdict__link { display: none; }
}
