/* =========================================================================
   Hardy Fitness - design system
   Brand: deep gym green, clean white surfaces, yellow for energy/attention.
   ========================================================================= */

:root {
  color-scheme: light;

  /* brand ramp */
  --green-950: #04240f;
  --green-900: #052e16;
  --green-800: #14532d;
  --green-700: #15803d;
  --green-600: #16a34a;
  --green-500: #22c55e;
  --green-300: #86efac;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;

  --yellow-600: #ca8a04;
  --yellow-500: #eab308;
  --yellow-400: #facc15;
  --yellow-200: #fef08a;
  --yellow-100: #fef9c3;

  --red-600: #dc2626;
  --red-500: #ef4444;
  --red-100: #fee2e2;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --slate-500: #64748b;

  /* semantic - light */
  --bg:          #f4f7f4;
  --bg-grad:     radial-gradient(1200px 600px at 100% -10%, #e8f5ec 0%, transparent 60%);
  --surface:     #ffffff;
  --surface-2:   #f8faf8;
  --surface-3:   #eff3ef;
  --text:        #0f1f16;
  --text-2:      #40534a;
  --muted:       #6b7f74;
  --border:      #e2e9e4;
  --border-2:    #cfdad3;
  --primary:     var(--green-700);
  --primary-hover:var(--green-800);
  --primary-soft:var(--green-50);
  --primary-text:#ffffff;
  --accent:      var(--yellow-400);
  --accent-text: #3f2d02;
  --ring:        color-mix(in srgb, var(--green-600) 35%, transparent);
  --shadow-sm:   0 1px 2px rgba(9, 30, 18, .06), 0 1px 3px rgba(9, 30, 18, .05);
  --shadow-md:   0 4px 14px rgba(9, 30, 18, .08);
  --shadow-lg:   0 18px 45px rgba(9, 30, 18, .16);
  --sidebar-bg:  linear-gradient(170deg, var(--green-800) 0%, var(--green-900) 55%, var(--green-950) 100%);

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --sidebar-w: 250px;
  --topbar-h: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg:          #08130d;
  --bg-grad:     radial-gradient(1100px 550px at 100% -10%, #0f2c1c 0%, transparent 62%);
  --surface:     #0f1d15;
  --surface-2:   #142518;
  --surface-3:   #1b3122;
  --text:        #e8f2eb;
  --text-2:      #bacfc2;
  --muted:       #8ba496;
  --border:      #1f3527;
  --border-2:    #2c4635;
  --primary:     var(--green-500);
  --primary-hover:var(--green-600);
  --primary-soft:#12301e;
  --primary-text:#04240f;
  --ring:        color-mix(in srgb, var(--green-500) 45%, transparent);
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:   0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg:   0 22px 55px rgba(0, 0, 0, .6);
  --sidebar-bg:  linear-gradient(170deg, #0d2417 0%, #071710 60%, #04120b 100%);
  --green-100: #16301f;
  --green-50:  #10241a;
  --yellow-100: #33290a;
  --yellow-200: #4a3a08;
  --red-100: #3a1414;
  --blue-100: #10233d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--green-100); color: var(--text); }

/* ------------------------------------------------------------------ boot -- */
.app-boot { display: grid; place-items: center; min-height: 100vh; }
.boot { display: grid; gap: 1rem; place-items: center; color: var(--muted); }
.boot-mark { width: 44px; height: 44px; color: var(--primary); animation: pulse 1.4s ease-in-out infinite; }
.boot-mark svg { width: 100%; height: 100%; }
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.94); } 50% { opacity: 1; transform: scale(1); } }

/* ---------------------------------------------------------------- layout -- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns .22s ease;
}
/* Collapsed: the panel slides out of the way and the content takes the space. */
body.nav-collapsed .shell { grid-template-columns: 0 minmax(0, 1fr); }
body.nav-collapsed .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar {
  background: var(--sidebar-bg);
  color: #d9ece0;
  display: flex; flex-direction: column;
  padding: 1.1rem .85rem;
  gap: .35rem;
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid rgba(255,255,255,.06);
  overflow: hidden;
  transition: transform .22s ease, opacity .18s ease;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .35rem .5rem 1.15rem; }
/* Only needed while the panel is a slide-over. */
.nav-close {
  display: none; margin-left: auto; flex: none;
  background: rgba(255,255,255,.08); color: #fff;
  border: 0; border-radius: 9px; padding: .4rem; cursor: pointer;
}
.nav-close:hover { background: rgba(255,255,255,.16); }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: linear-gradient(150deg, var(--yellow-400), var(--yellow-500));
  color: var(--green-900);
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(250, 204, 21, .28);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-name { font-weight: 700; color: #fff; letter-spacing: -.02em; font-size: 1.0625rem; line-height: 1.15; }
.brand-sub { font-size: .6875rem; color: rgba(217,236,224,.6); text-transform: uppercase; letter-spacing: .09em; margin-top: 2px; }

.nav { display: grid; gap: 2px; }
.nav-label {
  font-size: .6875rem; text-transform: uppercase; letter-spacing: .09em;
  color: rgba(217,236,224,.45); padding: 1rem .75rem .35rem; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .75rem; border-radius: 10px;
  color: rgba(217,236,224,.82); font-weight: 500;
  text-decoration: none; border: 0; background: none; width: 100%; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item.is-active { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--yellow-400); }
.nav-item.is-active svg { opacity: 1; color: var(--yellow-400); }
.nav-count {
  margin-left: auto; font-size: .6875rem; font-weight: 700;
  background: var(--yellow-400); color: var(--green-900);
  padding: .1rem .4rem; border-radius: 999px; min-width: 20px; text-align: center;
}
.sidebar-foot { margin-top: auto; padding-top: 1rem; display: grid; gap: .5rem; }
.side-user {
  display: flex; gap: .6rem; align-items: center; padding: .6rem;
  background: rgba(255,255,255,.06); border-radius: 12px;
}
.side-user-name { font-size: .8125rem; font-weight: 600; color: #fff; }
.side-user-role { font-size: .6875rem; color: rgba(217,236,224,.6); text-transform: capitalize; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 56;
}
.topbar h1 { font-size: 1.1875rem; }
.topbar-sub { font-size: .8125rem; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
/* Always available: it slides the panel over on a phone and collapses it on a
   desktop. */
.hamburger { display: grid; }

/* A real element, not a pseudo-element, so tapping outside can close the panel. */
.nav-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 20, 12, .5);
  border: 0; padding: 0; cursor: pointer;
  animation: fade .16s ease;
}
.content { padding: 1.35rem 1.25rem 3rem; max-width: 1420px; width: 100%; }

@media (max-width: 1000px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--sidebar-w));
    z-index: 60; transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-collapsed .shell { grid-template-columns: minmax(0, 1fr); }
  body.nav-collapsed .sidebar { transform: translateX(-102%); opacity: 1; pointer-events: auto; }
  body.nav-open .sidebar { transform: none; opacity: 1; pointer-events: auto; }
  body.nav-open .nav-backdrop { display: block; }
  body.nav-open .nav-close { display: grid; }
  .hamburger { display: grid; }
  .content { padding: 1rem .85rem 3.5rem; }
}

@media (max-width: 760px) {
  /* The topbar cannot shrink below its buttons, so give them their own row. */
  .topbar {
    height: auto; min-height: var(--topbar-h);
    flex-wrap: wrap; row-gap: .45rem; padding: .55rem .85rem;
  }
  .topbar h1 { font-size: 1.0625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { width: 100%; margin-left: 0; justify-content: flex-start; flex-wrap: wrap; }
  .card-head { padding: .85rem .9rem; }
  .card-body { padding: .9rem; }
  .kpi { padding: .9rem; }
}

/* --------------------------------------------------------------- buttons -- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-2);
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .5rem .85rem; border-radius: 10px;
  background: var(--btn-bg); color: var(--btn-fg); border: 1px solid var(--btn-bd);
  font-size: .875rem; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, transform .06s, box-shadow .14s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--primary-text); --btn-bd: transparent; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { --btn-bg: var(--yellow-400); --btn-fg: var(--accent-text); --btn-bd: transparent; }
.btn-accent:hover { background: var(--yellow-500); }
.btn-wa { --btn-bg: #25d366; --btn-fg: #05230f; --btn-bd: transparent; font-weight: 600; }
.btn-wa:hover { background: #1eb855; }
.btn-danger { --btn-fg: var(--red-600); --btn-bd: color-mix(in srgb, var(--red-500) 35%, transparent); }
.btn-danger:hover { background: var(--red-100); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { padding: .3rem .55rem; font-size: .8125rem; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { padding: .45rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- cards -- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: 1rem 1.15rem; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 1rem; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 1.15rem; }
.card-body.tight { padding: .5rem; }
.card-foot { padding: .85rem 1.15rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-note { font-size: .8125rem; color: var(--muted); }

.grid { display: grid; gap: 1rem; }

/* Single-column grids get an implicit `auto` track, whose automatic minimum is
   min-content - so one wide child (a data table, a long email address) stretches
   the track past the viewport and scrolls the whole page sideways. Pinning the
   minimum to 0 makes wide children scroll inside their own container instead.
   The .cols-* / .split-* modifiers below set their own tracks. */
.stack, .field, .timeline, .tl-body, .donut-legend, .msg-list, .kpi, .empty,
.switch-row-text, .auth-card, .auth-title, .auth-points, .nav, .sidebar-foot,
.boot, .toasts, .card-body.stack {
  grid-template-columns: minmax(0, 1fr);
}
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.split-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
/* Without this the shorter card stretches to its neighbour's height and shows
   a large empty area (plan mix beside collections, details beside the plan). */
.split-2-1 > * { align-self: start; }
@media (max-width: 1400px) { .cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1180px) { .cols-4, .cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .split-2-1 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px)  { .cols-3, .cols-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px)  { .cols-4, .cols-5 { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------------ kpis -- */
.kpi { position: relative; overflow: hidden; padding: 1.1rem 1.15rem; display: grid; gap: .3rem; }
/* Keeps a longer label ("Payment follow-ups") clear of the absolute icon. */
.kpi-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding-right: 2.75rem; }
.kpi-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.kpi-value.sm { font-size: 1.375rem; }
.kpi-meta { font-size: .8125rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.kpi-icon {
  position: absolute; right: .9rem; top: .9rem; width: 36px; height: 36px;
  border-radius: 11px; display: grid; place-items: center;
}
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-earn  .kpi-icon { background: var(--green-100); color: var(--green-700); }
.kpi-due   .kpi-icon { background: var(--yellow-100); color: var(--yellow-600); }
.kpi-exp   .kpi-icon { background: var(--red-100); color: var(--red-600); }
.kpi-act   .kpi-icon { background: var(--blue-100); color: var(--blue-500); }
.kpi-earn .kpi-value { color: var(--green-700); }
[data-theme='dark'] .kpi-earn .kpi-value { color: var(--green-500); }
.kpi-due .kpi-value { color: var(--yellow-600); }
[data-theme='dark'] .kpi-due .kpi-value { color: var(--yellow-400); }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .16rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-active    { background: var(--green-100);  color: var(--green-700); }
.badge-expiring  { background: var(--yellow-100); color: var(--yellow-600); }
.badge-expired   { background: var(--red-100);    color: var(--red-600); }
.badge-frozen    { background: var(--blue-100);   color: var(--blue-500); }
.badge-cancelled { background: var(--surface-3);  color: var(--muted); }
.badge-no_plan   { background: var(--surface-3);  color: var(--muted); }
.badge-plain::before { display: none; }
[data-theme='dark'] .badge-active { color: var(--green-300); }
[data-theme='dark'] .badge-expiring { color: var(--yellow-400); }
[data-theme='dark'] .badge-expired { color: #fca5a5; }

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .6rem; border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--surface); font-size: .8125rem; cursor: pointer; color: var(--text-2);
  transition: background .13s, border-color .13s, color .13s;
}
.chip:hover { background: var(--surface-3); }
.chip.is-on { background: var(--primary); border-color: transparent; color: var(--primary-text); font-weight: 600; }
.chip-count { font-size: .6875rem; opacity: .75; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
  text-align: left; font-size: .6875rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 650; padding: .6rem .75rem;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .sort-arrow { display: inline-block; margin-left: .2rem; opacity: .6; }
table.data td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.is-selected { background: var(--primary-soft); }
table.data tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.cell-actions { display: flex; gap: .25rem; justify-content: flex-end; }

.person { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center; font-size: .8125rem; font-weight: 700;
  background: var(--green-100); color: var(--green-700); letter-spacing: -.02em;
}
.avatar.lg { width: 56px; height: 56px; font-size: 1.25rem; border-radius: 16px; }
[data-theme='dark'] .avatar { color: var(--green-300); }
.person-main { min-width: 0; }
.person-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-meta { font-size: .75rem; color: var(--muted); display: flex; gap: .4rem; align-items: center; }
.mono { font-family: var(--mono); font-size: .8125rem; }

/* ---------------------------------------------------------------- forms --- */
.field { display: grid; gap: .3rem; min-width: 0; }
.field > label, .label { font-size: .8125rem; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: .75rem; color: var(--muted); }
.field .err { font-size: .75rem; color: var(--red-600); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 10px; padding: .5rem .65rem; width: 100%;
  transition: border-color .13s, box-shadow .13s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring);
}
input[aria-invalid='true'], select[aria-invalid='true'], textarea[aria-invalid='true'] {
  border-color: var(--red-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red-500) 18%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%236b7f74' stroke-width='1.6'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; background-size: 12px; padding-right: 1.8rem; }
input[type='checkbox'], input[type='radio'] { width: auto; accent-color: var(--primary); }
.check { display: flex; gap: .55rem; align-items: flex-start; cursor: pointer; font-size: .875rem; }
.check input { margin-top: .2rem; flex: none; }
.form-grid { display: grid; gap: .9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
/* A checkbox is much shorter than the input beside it, so centre it in the row. */
.form-grid > .field:has(> .check) { align-self: center; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.input-group { display: flex; }
.input-group input { border-radius: 10px 0 0 10px; }
.input-group .btn { border-radius: 0 10px 10px 0; border-left: 0; }
.search {
  position: relative; flex: 1 1 240px; max-width: 420px;
}
.search input { padding-left: 2.1rem; }
.search svg { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row-text { display: grid; gap: .1rem; }
.switch-row-text strong { font-weight: 600; font-size: .875rem; }

/* --------------------------------------------------------------- modals --- */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(6, 25, 15, .45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 1rem;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  width: min(640px, 100%); max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  animation: rise .2s cubic-bezier(.2, .9, .3, 1);
}
.modal.wide { width: min(860px, 100%); }
.modal.narrow { width: min(460px, 100%); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.modal-head { display: flex; align-items: flex-start; gap: 1rem; padding: 1.15rem 1.25rem .9rem; }
.modal-head h2 { font-size: 1.0625rem; }
.modal-head p { font-size: .8125rem; color: var(--muted); margin-top: .15rem; }
.modal-body { padding: 0 1.25rem 1.1rem; overflow-y: auto; }
.modal-foot {
  display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap;
  padding: .95rem 1.25rem; border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.modal-foot .left { margin-right: auto; }
@media (max-width: 560px) {
  .overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 92vh; }
  .modal-foot { border-radius: 0; }
  .modal-foot .btn { flex: 1; }
}

/* --------------------------------------------------------------- toasts --- */
.toasts { position: fixed; bottom: 1rem; right: 1rem; z-index: 200; display: grid; gap: .5rem; max-width: min(400px, calc(100vw - 2rem)); }
.toast {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .7rem .85rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: .875rem;
  animation: toast-in .22s cubic-bezier(.2,.9,.3,1);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.toast.leaving { animation: toast-out .18s ease forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
.toast svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast-ok  { border-left: 3px solid var(--green-600); }
.toast-ok svg { color: var(--green-600); }
.toast-err { border-left: 3px solid var(--red-500); }
.toast-err svg { color: var(--red-500); }
.toast-info { border-left: 3px solid var(--blue-500); }
.toast-info svg { color: var(--blue-500); }
.toast-body { min-width: 0; }
/* The update toast carries actions, so the text claims the slack between them. */
.toast-update .toast-body { flex: 1; }
.toast-update .btn { align-self: center; flex: none; }
.toast-body strong { display: block; font-weight: 600; }
.toast-body span { color: var(--muted); font-size: .8125rem; }

/* ----------------------------------------------------------------- misc --- */
.empty { display: grid; gap: .6rem; justify-items: center; text-align: center; padding: 2.75rem 1rem; color: var(--muted); }
.empty-icon { width: 46px; height: 46px; border-radius: 14px; background: var(--surface-3); display: grid; place-items: center; color: var(--muted); }
.empty-icon svg { width: 22px; height: 22px; }
.empty strong { color: var(--text); font-size: .9375rem; }
.empty p { font-size: .875rem; max-width: 40ch; }

.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.sk-line { height: 12px; }
.sk-row { display: flex; align-items: center; gap: .75rem; padding: .7rem .75rem; border-bottom: 1px solid var(--border); }

.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); padding: 0 .35rem; }
.tab {
  padding: .65rem .8rem; border: 0; background: none; cursor: pointer;
  font-size: .875rem; font-weight: 550; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--primary); border-bottom-color: var(--primary); }

.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row.tight { gap: .35rem; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stack { display: grid; gap: 1rem; }
.stack.sm { gap: .5rem; }
.spacer { margin-left: auto; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }
.tiny { font-size: .75rem; }
.strong { font-weight: 650; }
.danger-text { color: var(--red-600); }
.ok-text { color: var(--green-700); }
[data-theme='dark'] .ok-text { color: var(--green-500); }
.warn-text { color: var(--yellow-600); }
[data-theme='dark'] .warn-text { color: var(--yellow-400); }
.center { text-align: center; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: minmax(90px, auto) minmax(0, 1fr); gap: .35rem .9rem; font-size: .875rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.pager { display: flex; align-items: center; gap: .5rem; justify-content: flex-end; }
.pager .page-info { margin-right: auto; font-size: .8125rem; color: var(--muted); }

.bulkbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem .9rem; margin-top: -1px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 -6px 18px rgba(9,30,18,.06);
}
.bulkbar strong { font-size: .875rem; }

/* --------------------------------------------------------------- charts --- */
.chart { width: 100%; overflow: visible; }
.chart .bar { fill: var(--green-600); transition: fill .15s; }
.chart .bar:hover { fill: var(--green-700); }
.chart .bar.is-current { fill: var(--yellow-400); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 13px; font-family: var(--font); }
.chart .bar-value { fill: var(--text-2); font-size: 13px; font-weight: 650; font-family: var(--font); }
.donut-wrap { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.donut-legend { display: grid; gap: .45rem; font-size: .8125rem; flex: 1 1 140px; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: .5rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-item .spacer { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------------------------------------------- auth / setup screen -- */
.auth-shell {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.auth-aside {
  background: var(--sidebar-bg); color: #e6f3ea;
  padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-aside::after {
  content: ''; position: absolute; width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, rgba(250,204,21,.16), transparent 68%);
  right: -140px; bottom: -160px;
}
.auth-aside h2 { font-size: 2.125rem; color: #fff; max-width: 22ch; letter-spacing: -.03em; line-height: 1.15; }
.auth-aside p { color: rgba(230,243,234,.72); max-width: 40ch; margin-top: .85rem; }
.auth-points { display: grid; gap: .75rem; margin-top: 2rem; position: relative; }
.auth-point { display: flex; gap: .65rem; align-items: flex-start; font-size: .9375rem; color: rgba(230,243,234,.9); }
.auth-point svg { width: 18px; height: 18px; flex: none; color: var(--yellow-400); margin-top: 2px; }
.auth-main { display: grid; place-items: center; padding: 2rem 1.25rem; }
.auth-card { width: min(420px, 100%); display: grid; gap: 1.1rem; }
.auth-card.setup { width: min(560px, 100%); }
.auth-logo { display: flex; align-items: center; gap: .7rem; }
.auth-title { display: grid; gap: .25rem; }
.auth-title h1 { font-size: 1.5rem; }
.auth-title p { color: var(--muted); font-size: .875rem; }
.auth-error {
  display: flex; gap: .55rem; padding: .7rem .8rem; border-radius: 10px;
  background: var(--red-100); color: var(--red-600); font-size: .875rem; font-weight: 500;
}
.auth-error svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.auth-foot { font-size: .8125rem; color: var(--muted); text-align: center; }
/* Shown only when the browser reports the app is installable. */
.install-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .75rem; border: 1px dashed var(--border); border-radius: 12px;
  background: var(--surface-2);
}
.install-row > div { flex: 1; }
.install-row .btn { flex: none; }
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
}

/* ------------------------------------------------------- message composer -- */
.msg-list { display: grid; gap: .6rem; max-height: 340px; overflow-y: auto; padding-right: .2rem; }
.msg-item { border: 1px solid var(--border); border-radius: 12px; padding: .7rem .8rem; background: var(--surface-2); }
.msg-item.is-bad { border-color: color-mix(in srgb, var(--red-500) 40%, transparent); background: var(--red-100); }
.msg-head { display: flex; align-items: center; gap: .5rem; font-size: .875rem; }
.msg-head .spacer { margin-left: auto; }
.msg-preview {
  margin-top: .45rem; font-size: .8125rem; color: var(--text-2);
  white-space: pre-wrap; max-height: 8.5em; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem;
  font-family: var(--font); line-height: 1.5;
}
.token-list { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.token {
  font-family: var(--mono); font-size: .6875rem; padding: .15rem .4rem;
  background: var(--surface-3); border-radius: 6px; cursor: pointer; border: 1px solid transparent; color: var(--text-2);
}
.token:hover { border-color: var(--primary); color: var(--primary); }

.perm-grid { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 640px) { .perm-grid { grid-template-columns: minmax(0, 1fr); } }
.perm-group { border: 1px solid var(--border); border-radius: 12px; padding: .75rem .85rem; background: var(--surface-2); }
.perm-group h4 { font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: .5rem; }
.perm-group .check { padding: .2rem 0; }

.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: .75rem; padding-bottom: 1rem; position: relative; }
.tl-item:not(:last-child)::before {
  content: ''; position: absolute; left: 10px; top: 22px; bottom: 0; width: 2px; background: var(--border);
}
.tl-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--green-100); color: var(--green-700); display: grid; place-items: center; z-index: 1; }
.tl-dot svg { width: 12px; height: 12px; }
.tl-body { font-size: .875rem; display: grid; gap: .15rem; }
.tl-time { font-size: .75rem; color: var(--muted); }

@media print {
  .sidebar, .topbar, .bulkbar, .pager, .cell-actions { display: none !important; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  body { background: #fff; }
}
