/* Module: Dashboard colors, layout and components.
 * Tailwind loads its utilities after these styles so pages can override component defaults.
 */

/* Same palette as the homepage (assets/css/site.css): graphite and white, and colour kept for live data.
 * The shell is one tinted frame (--background) holding the sidebar and the top bar; the page is a sheet on it (--sheet).
 * Radii step down: sheet 16, card 12, control 8. Surfaces are split by a 1px line, never a shadow; only overlays float. */
:root {
  --background: 216 20% 95.3%;
  --sheet: 0 0% 100%;
  --foreground: 216 15.2% 6.5%;
  --card: 0 0% 100%;
  --card-foreground: 216 15.2% 6.5%;
  --popover: 0 0% 100%;
  --popover-foreground: 216 15.2% 6.5%;
  --primary: 216 15.2% 6.5%;
  --primary-foreground: 210 20% 96.1%;
  --secondary: 216 15.2% 94.5%;
  --secondary-foreground: 216 15.2% 6.5%;
  --muted: 216 15.2% 95%;
  --muted-foreground: 214.3 11.2% 36.7%;
  --accent: 217.5 14.3% 89%;
  --accent-foreground: 216 15.2% 6.5%;
  --destructive: 0 72.2% 44%;
  --destructive-foreground: 0 0% 100%;
  --success: 162.9 93.5% 24.3%;
  --success-foreground: 0 0% 100%;
  --warning: 26 90.5% 34%;
  --warning-foreground: 0 0% 100%;
  --border: 214.3 14.3% 90.4%;
  --input: 216 12% 83%;
  --ring: 214.3 11.2% 36.7%;
  --chart-1: 162.9 93.5% 24.3%;
  --chart-2: 214.3 11.2% 36.7%;
  --chart-3: 26 90.5% 37.1%;
  --chart-4: 218.2 13.6% 15.9%;
  --chart-5: 215 10.1% 53.3%;
  --radius: 0.5rem;
  --radius-card: 0.75rem;
  --radius-sheet: 1rem;

  --shadow-float: 0 12px 32px -8px rgb(16 24 40 / 0.18), 0 2px 6px -2px rgb(16 24 40 / 0.08);
}

.dark {
  --background: 216 15.2% 6.5%;
  --sheet: 216 15% 8.6%;
  --foreground: 210 20% 96.1%;
  --card: 217.5 15.4% 10.2%;
  --card-foreground: 210 20% 96.1%;
  --popover: 216 14.3% 13.7%;
  --popover-foreground: 210 20% 96.1%;
  --primary: 210 20% 96.1%;
  --primary-foreground: 216 15.2% 6.5%;
  --secondary: 216 14.3% 13.7%;
  --secondary-foreground: 210 20% 96.1%;
  --muted: 216 14.3% 13.7%;
  --muted-foreground: 214.3 13.5% 69.6%;
  --accent: 216.9 13.4% 19%;
  --accent-foreground: 210 20% 96.1%;
  --destructive: 0 90.6% 70.8%;
  --destructive-foreground: 216 15.2% 6.5%;
  --success: 156.2 71.6% 66.9%;
  --success-foreground: 216 15.2% 6.5%;
  --warning: 43.3 96.4% 56.3%;
  --warning-foreground: 216 15.2% 6.5%;
  --border: 218.2 13.6% 15.9%;
  --input: 216.9 13.4% 24%;
  --ring: 214.3 13.5% 69.6%;
  --chart-1: 156.2 71.6% 66.9%;
  --chart-2: 214.3 13.5% 69.6%;
  --chart-3: 43.3 96.4% 56.3%;
  --chart-4: 217.5 14.3% 89%;
  --chart-5: 215 10.1% 53.3%;
  --shadow-float: 0 12px 32px -8px rgb(0 0 0 / 0.55), 0 2px 6px -2px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */

*, ::before, ::after { border-color: hsl(var(--border)); }

body {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: 'Geist', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Dashboard shell: only <main> scrolls. Lock the browser's own scroll so a second scrollbar never shows
   (100vh is taller than the visible area on mobile, and body-level popups could push the page).
   Only the dashboard layout (#app.h-screen); public pages like shared and tutorials scroll normally. */
html:has(> body > #app.h-screen), body:has(> #app.h-screen) { height: 100%; overflow: hidden; overscroll-behavior: none; }
#app.h-screen { height: 100dvh; }

[hidden] { display: none !important; }

::selection { background-color: hsl(var(--primary) / 0.18); }
a, button, summary, input, select, textarea { -webkit-tap-highlight-color: transparent; }

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

/* ------------------------------------------------------------------ utilities */

.scrollbar-thin { scrollbar-width: thin; scrollbar-color: hsl(var(--border)) transparent; }
.scrollbar-thin::-webkit-scrollbar { width: 6px; height: 6px; }
.scrollbar-thin::-webkit-scrollbar-thumb { background-color: hsl(var(--border)); border-radius: 3px; }
.scrollbar-thin::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground)); }
.scrollbar-thin::-webkit-scrollbar-track { background-color: transparent; }

.text-balance { text-wrap: balance; }

/* Flat fills. The names stay because the pages use them. */
.bg-brand-gradient { background-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.bg-brand-soft { background-color: hsl(var(--muted) / 0.6); }
/* "Copy Code" / "Copy Link" chips in email rows. */
.copy-chip:hover { background-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.copy-chip:hover > span { background-color: transparent; }
/* Inbox tag in All emails rows; long names truncate. */
.mail-label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  height: 1.25rem;
  padding: 0 0.375rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.375rem;
  background-color: hsl(var(--muted) / 0.6);
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  line-height: 1rem;
  font-weight: 500;
}
.mail-label > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-bar { display: none; }

/* ------------------------------------------------------------------ the sheet */

.app-sheet { background-color: hsl(var(--sheet)); }
@media (min-width: 1024px) {
  .app-sheet { margin: 0 0.5rem 0.5rem 0; border: 1px solid hsl(var(--border)); border-radius: var(--radius-sheet); }
}

/* Page heading row: the title sits on the sheet, no box around it. */
.page-head { display: flex; flex-direction: column; gap: 1rem; }
@media (min-width: 640px) { .page-head { flex-direction: row; align-items: flex-end; justify-content: space-between; } }

/* KPIs: one container split by 1px lines, label over value, no icons. */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(var(--kpi-cols, 4), minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-card);
  background-color: hsl(var(--card));
}
.kpi { display: block; min-width: 0; padding: 0.875rem 1.25rem; transition: background-color .15s ease; }
.kpi + .kpi { border-left: 1px solid hsl(var(--border)); }
a.kpi:hover { background-color: hsl(var(--muted) / 0.6); }
a.kpi:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; }
.kpi-label { font-size: 0.8125rem; line-height: 1.25rem; color: hsl(var(--muted-foreground)); }
.kpi-value { margin-top: 0.125rem; font-size: 1.5rem; line-height: 2rem; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 0.75rem; line-height: 1rem; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; }
.kpi-value.is-warning { color: hsl(var(--warning)); }
@media (max-width: 639px) {
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 0.75rem 1rem; }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(even) { border-left: 1px solid hsl(var(--border)); }
  .kpi:nth-child(n+3) { border-top: 1px solid hsl(var(--border)); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Filters that change the list: underline tabs on one rule (the page reloads, so the line needs no motion). */
.filter-tabs {
  display: flex;
  gap: 1.25rem;
  overflow-x: auto;
  border-bottom: 1px solid hsl(var(--border));
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.375rem;
  height: 2.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  color: hsl(var(--muted-foreground));
  transition: color .15s ease;
}
.filter-tab:hover, .filter-tab[aria-current] { color: hsl(var(--foreground)); }
.filter-tab[aria-current]::after { content: ''; position: absolute; inset: auto 0 0 0; height: 2px; background-color: hsl(var(--foreground)); }
.filter-tab:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; border-radius: 0.25rem; }
.filter-tab-count { font-size: 0.75rem; font-weight: 400; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; }

/* Live mail lists: when the page last checked, and rows that just arrived. */
.live-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; white-space: nowrap; }
.live-dot { height: 0.375rem; width: 0.375rem; border-radius: 9999px; background-color: hsl(var(--chart-1)); animation: livePulse 2.4s ease-in-out infinite; }
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
[data-refresh].is-spinning svg { animation: spin .7s linear infinite; }
[data-email-id] { transition: background-color 1.2s ease-out; }
[data-email-id].is-new { background-color: hsl(var(--chart-1) / 0.12); transition-duration: .15s; }
/* Let row menus open beyond the card while keeping its bottom corners rounded. */
.divide-y > [data-row]:last-child { border-bottom-left-radius: calc(var(--radius-card) - 1px); border-bottom-right-radius: calc(var(--radius-card) - 1px); }

/* Inbox page rows: with a mouse the actions share the time's slot and swap in on hover or keyboard focus, so a row at
 * rest is only sender, subject and time. On touch there is no hover, so both stay on show. */
.mail-tail { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
@media (hover: hover) and (min-width: 640px) {
  .mail-tail { display: grid; align-items: center; justify-items: end; min-width: 5.25rem; }
  .mail-tail > * { grid-area: 1 / 1; }
  .mail-acts, .mail-time { transition: opacity .12s ease; }
  .mail-acts { opacity: 0; }
  [data-row]:hover .mail-acts, [data-row]:focus-within .mail-acts, [data-row]:has(details[open]) .mail-acts { opacity: 1; }
  [data-row]:hover .mail-time, [data-row]:focus-within .mail-time, [data-row]:has(details[open]) .mail-time { opacity: 0; }
}
/* All emails rows. Wide: text | copy chips | inbox tag | time, so the tags share one column. */
.mail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 9rem auto;
  grid-template-areas: "head codes box tail" "line codes box tail";
  align-items: center;
  column-gap: 1rem;
}
.mail-head { grid-area: head; }
.mail-line { grid-area: line; min-width: 0; }
.mail-meta { display: contents; }
.mail-box { grid-area: box; display: flex; min-width: 0; }
.mail-codes { grid-area: codes; }
.mail-tail { grid-area: tail; }
/* Narrower: time beside the sender, then a third line of tag and chips with the actions at its end. */
@media (max-width: 1279px) {
  .mail-body {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "head time" "line line" "meta acts";
    column-gap: 0.5rem;
  }
  .mail-meta { grid-area: meta; display: flex; align-items: center; gap: 0.375rem; min-width: 0; margin-top: 0.375rem; }
  .mail-box { flex: 0 1 auto; }
  .mail-codes { flex-shrink: 0; }
  .mail-body .mail-tail { display: contents; }
  .mail-body .mail-acts { grid-area: acts; justify-self: end; margin: 0.375rem -0.375rem 0 0; }
  .mail-body .mail-time { grid-area: time; justify-self: end; opacity: 1 !important; }
}
/* Inbox page rows. Wide: text | copy chips | actions and time. Phone: time beside the sender, then chips and actions on
 * a third line, so the sender and subject keep the row's width. */
.mail-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "head codes tail" "line codes tail";
  align-items: center;
  column-gap: 0.75rem;
}
@media (max-width: 639px) {
  .mail-item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "head time" "line line" "codes acts";
    column-gap: 0.5rem;
  }
  .mail-item .mail-tail { display: contents; }
  .mail-item .mail-codes { margin-top: 0.375rem; }
  .mail-item .mail-acts { grid-area: acts; justify-self: end; margin: 0.375rem -0.375rem 0 0; }
  .mail-item .mail-time { grid-area: time; justify-self: end; }
}
/* On a phone the toolbar keeps the live dot and refresh button but drops the words, so search keeps its width. */
@media (max-width: 639px) { .mail-tools [data-updated] { display: none; } }

/* Ctrl K search */
.modal.palette { align-items: flex-start; padding-top: 12vh; }
.palette-panel { position: relative; width: 100%; max-width: 36rem; overflow: hidden; border: 1px solid hsl(var(--border)); border-radius: var(--radius-card); background-color: hsl(var(--popover)); color: hsl(var(--popover-foreground)); box-shadow: var(--shadow-float); animation: scaleIn .14s cubic-bezier(.16, 1, .3, 1); }
.palette-input { width: 100%; height: 3rem; padding: 0 1rem; border-bottom: 1px solid hsl(var(--border)); background: transparent; font-size: 0.9375rem; outline: none; }
.palette-input::placeholder { color: hsl(var(--muted-foreground)); }
.palette-input::-webkit-search-cancel-button { display: none; }
.palette-list { max-height: min(24rem, 60vh); overflow-y: auto; padding: 0.25rem 0.5rem 0.5rem; }
.palette-group { padding: 0.625rem 0.5rem 0.25rem; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.palette-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.25rem; padding: 0.25rem 0.5rem; border-radius: var(--radius); font-size: 0.875rem; }
.palette-item[aria-selected="true"] { background-color: hsl(var(--accent)); }
.palette-detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: 'IBM Plex Mono', ui-monospace, Consolas, monospace; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

/* How much of an inbox's life is left: Mailrexo's own mark. Green while it runs, amber near the end. */
.life-meter { height: 0.25rem; overflow: hidden; border-radius: 9999px; background-color: hsl(var(--muted)); }
.life-meter > span { display: block; height: 100%; border-radius: inherit; background-color: hsl(var(--chart-1)); }
.life-meter.is-expiring > span { background-color: hsl(var(--warning)); }
.life-meter.is-expired > span { background-color: hsl(var(--muted-foreground) / 0.4); }
/* On an inbox card the meter is the card's bottom edge, so the time left reads at a glance down the grid. */
.inbox-life { position: absolute; inset: auto 0 0 0; height: 3px; border-radius: 0 0 calc(var(--radius-card) - 1px) calc(var(--radius-card) - 1px); }
.inbox-life > span { border-radius: 0; }

.animate-fade-in { animation: fadeIn 0.25s ease-out; }
.animate-slide-up { animation: slideUp 0.3s ease-out; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

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

/* One spacing scale for the whole nav: 12px gutter, 36px rows, 2px between rows, 20px between sections. */
.sb-nav { padding: 1rem 0.75rem; }
.sb-section + .sb-section { margin-top: 1.25rem; }
.sb-label {
  padding: 0 0.625rem;
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1rem;
  color: hsl(var(--muted-foreground));
}
.sb-items { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 2rem;
  padding: 0 0.625rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 400;
  color: hsl(var(--muted-foreground));
  transition: background-color .15s ease, color .15s ease;
}
.nav-link svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.nav-link:not([aria-current="page"]):hover { background-color: hsl(var(--accent) / 0.5); color: hsl(var(--foreground)); }
/* Active item: a neutral pill, the label in ink. */
.nav-link[aria-current="page"] { background-color: hsl(var(--accent)); color: hsl(var(--foreground)); font-weight: 500; }
.nav-link:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 1px; }

/* Keep the sidebar state on <html> so it survives an htmx body swap. */
#sidebar { transition: width .3s ease-in-out; }
.sb-mini { display: none; }
html.sidebar-collapsed #sidebar { width: 60px; }
html.sidebar-collapsed #sidebar .sb-full { display: none; }
html.sidebar-collapsed #sidebar .sb-mini { display: flex; }
html.sidebar-collapsed #sidebar .sb-brand { justify-content: center; padding-left: 0; padding-right: 0; }
html.sidebar-collapsed #sidebar .sb-nav { padding: 0.75rem 0; scrollbar-width: none; }
/* A visible scrollbar would take width from the 60px rail and push the nav icons off centre; the wheel still scrolls. */
html.sidebar-collapsed #sidebar .sb-nav::-webkit-scrollbar { display: none; }
html.sidebar-collapsed #sidebar .sb-items { align-items: center; }
html.sidebar-collapsed #sidebar .nav-link { justify-content: center; width: 2rem; padding: 0; }
html.sidebar-collapsed #sidebar .sb-section + .sb-section { margin: 0.75rem 0.75rem 0; padding-top: 0.75rem; border-top: 1px solid hsl(var(--border)); }
/* Every collapsed control shares the nav link's size: a 32px box around a 16px icon. */
html.sidebar-collapsed #sidebar .sb-collapse { justify-content: center; width: 2rem; height: 2rem; margin-left: auto; margin-right: auto; padding: 0; }
html.sidebar-collapsed #sidebar .sb-collapse svg { width: 1rem; height: 1rem; transform: rotate(180deg); }
html.sidebar-collapsed #sidebar .sb-new { display: flex; justify-content: center; padding: 0.75rem 0 0; }
html.sidebar-collapsed #sidebar .sb-new .btn { width: 2rem; height: 2rem; padding: 0; }

/* Nav counts: a pill when expanded, a dot on the icon when collapsed. */
.nav-count {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 9999px;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  line-height: 1.25rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.nav-count.is-hot { color: hsl(var(--chart-1)); font-weight: 600; }
.nav-dot { position: absolute; top: 0.375rem; right: 0.375rem; height: 0.5rem; width: 0.5rem; border-radius: 9999px; background-color: hsl(var(--chart-1)); box-shadow: 0 0 0 2px hsl(var(--background)); }

/* Bottom tab bar (below lg). */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom));
  border-top: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
}
.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  padding: 0.25rem 0;
  border-radius: 0.5rem;
  font-size: 11px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  transition: color .15s ease;
}
.tabbar-item:hover { color: hsl(var(--foreground)); }
.tabbar-item[aria-current="page"] { color: hsl(var(--foreground)); font-weight: 500; }
.tabbar-badge {
  position: absolute;
  top: -0.375rem;
  right: -0.625rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 9999px;
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 11px;
  font-weight: 600;
  line-height: 1rem;
  text-align: center;
  box-shadow: 0 0 0 2px hsl(var(--background));
}
.tabbar-new {
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.75rem;
  width: 2.75rem;
  align-self: center;
  border-radius: var(--radius);
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  transition: transform .15s ease;
}
.tabbar-new:active { transform: scale(.94); }
@media (max-width: 1023px) { .toaster { bottom: calc(5rem + env(safe-area-inset-bottom)); } }

/* ------------------------------------------------------------------ button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius);
  height: 2.25rem;
  padding: 0 0.875rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s ease, transform .1s ease;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px hsl(var(--ring) / 0.25); border-color: hsl(var(--ring)); }
.btn:disabled, .btn[aria-disabled="true"] { pointer-events: none; opacity: 0.5; }

.btn-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  transition: opacity .15s ease, transform .1s ease;
}
.btn-primary:hover { opacity: 0.86; }

.btn-destructive { background-color: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-destructive:hover { background-color: hsl(var(--destructive) / 0.9); }


.btn-outline { border-color: hsl(var(--input)); background-color: hsl(var(--card)); }
.btn-outline:hover { background-color: hsl(var(--muted)); }


.btn-ghost { background-color: transparent; }
.btn-ghost:hover { background-color: hsl(var(--muted)); color: hsl(var(--foreground)); }

.btn-link { background: transparent; color: hsl(var(--primary)); text-underline-offset: 4px; }
.btn-link:hover { text-decoration: underline; }

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.75rem; line-height: 1rem; }
.btn-icon { height: 2.25rem; width: 2.25rem; padding: 0; }

/* Segmented control (view / range / period toggles): .segmented > .btn[aria-pressed] */
.segmented { display: flex; align-items: center; gap: 0.125rem; border: 1px solid hsl(var(--input)); border-radius: var(--radius); background-color: hsl(var(--card)); padding: 0.125rem; }
.segmented .btn { border-radius: calc(var(--radius) - 2px); }

/* ------------------------------------------------------------------ form controls */

.input, .select, .textarea {
  display: flex;
  width: 100%;
  height: 2.25rem;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background-color: hsl(var(--card));
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: inherit;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: hsl(var(--muted-foreground)); }
.input:hover, .select:hover, .textarea:hover { border-color: hsl(var(--muted-foreground) / 0.35); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15); }
.input:disabled, .select:disabled { cursor: not-allowed; opacity: 0.5; }

.textarea { height: auto; padding: 0.75rem; }

.select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
}
.select option { background-color: hsl(var(--popover)); color: hsl(var(--popover-foreground)); }

/* Custom select (ui.js): the native <select> stays in the form, visually hidden; a button
 * (.select.cs-trigger, same classes as the select) opens a .cs-menu listbox portalled to <body>. */
.cs-native { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0 !important; opacity: 0; pointer-events: none; }
.cs-trigger { align-items: center; text-align: left; transition: color .15s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease, background-position .2s ease; }
.cs-trigger > span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-trigger.is-placeholder > span { color: hsl(var(--muted-foreground)); }
.cs-trigger[aria-expanded="true"] {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a7b0bc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 15-6-6-6 6'/%3E%3C/svg%3E");
}
.cs-menu {
  position: fixed;
  z-index: 65;
  max-height: 16rem;
  max-width: calc(100vw - 1rem);
  overflow-y: auto;
  overflow-wrap: anywhere;
  padding: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  background-color: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: var(--shadow-float);
  animation: dropIn .14s cubic-bezier(.16, 1, .3, 1);
  transform-origin: top center;
  outline: none;
}
.cs-menu.is-above { transform-origin: bottom center; }
/* Search box at the top of a select.select[data-search] menu; it stays in view while the list scrolls. */
.cs-search { position: sticky; top: -0.25rem; z-index: 1; margin: -0.25rem -0.25rem 0.25rem; padding: 0.375rem; background-color: hsl(var(--popover)); border-bottom: 1px solid hsl(var(--border)); }
.cs-search input {
  width: 100%; height: 2rem; padding: 0 0.5rem 0 1.875rem; border: 1px solid hsl(var(--input)); border-radius: 0.5rem; background-color: transparent; font-size: 0.875rem; color: inherit; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a7b0bc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 0.625rem center;
}
.cs-search input:focus { border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--ring) / 0.15); }
.cs-empty { padding: 0.5rem 0.625rem; font-size: 0.8125rem; color: hsl(var(--muted-foreground)); }
.cs-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: calc(var(--radius) - 4px);
  padding: 0.5rem 0.625rem 0.5rem 2rem;
  position: relative;
  font-size: 0.875rem;
  line-height: 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background-color .12s ease, color .12s ease;
}
.cs-option.is-active { background-color: hsl(var(--muted)); }
.cs-option[aria-selected="true"] { color: hsl(var(--primary)); font-weight: 500; background-color: hsl(var(--primary) / 0.08); }
.cs-option[aria-selected="true"].is-active { background-color: hsl(var(--primary) / 0.14); }
.cs-option[aria-selected="true"]::before {
  content: '';
  position: absolute;
  left: 0.625rem;
  top: 50%;
  width: 0.875rem;
  height: 0.875rem;
  transform: translateY(-50%);
  background: hsl(var(--primary));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%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 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.cs-option[aria-disabled="true"] { cursor: not-allowed; color: hsl(var(--muted-foreground)); }
.cs-group { padding: 0.625rem 0.625rem 0.25rem; font-size: 0.6875rem; line-height: 1rem; font-weight: 500; color: hsl(var(--muted-foreground)); user-select: none; }
.cs-group:first-child { padding-top: 0.25rem; }
.cs-badge { margin-left: auto; flex-shrink: 0; border-radius: 9999px; padding: 0 0.5rem; font-size: 0.6875rem; line-height: 1.125rem; font-weight: 500; color: hsl(var(--primary)); background-color: hsl(var(--primary) / 0.1); }

.label { display: block; font-size: 0.8125rem; line-height: 1.25rem; font-weight: 500; color: hsl(var(--foreground)); }

.checkbox {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  height: 1rem;
  width: 1rem;
  margin: 0;
  border: 1px solid hsl(var(--input));
  border-radius: 0.25rem;
  background-color: hsl(var(--card));
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.875rem;
  cursor: pointer;
}
/* Dark mode: --primary is near-white, so the tick has to be dark to show. */
.dark .checkbox:checked { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230e1013' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E"); }
.dark .checkbox:indeterminate { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230e1013' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.checkbox:focus-visible { outline: none; box-shadow: 0 0 0 1px hsl(var(--ring)); }
.checkbox:checked {
  background-color: hsl(var(--primary));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: 0.875rem;
}
.checkbox:indeterminate {
  background-color: hsl(var(--primary));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
}

/* Switch: <button role="switch" aria-checked="true|false" class="switch"> */
.switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  height: 1.25rem;
  width: 2.25rem;
  border: 2px solid transparent;
  border-radius: 9999px;
  background-color: hsl(var(--input));
  cursor: pointer;
  transition: background-color .2s ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 1rem;
  width: 1rem;
  border-radius: 9999px;
  background-color: hsl(var(--sheet));
  transition: transform .2s cubic-bezier(.4, 0, .2, 1);
}
.switch[aria-checked="true"] { background-color: hsl(var(--primary)); }
.switch[aria-checked="true"]::after { transform: translateX(1rem); }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring)); }
.switch:disabled { cursor: not-allowed; opacity: 0.5; }
/* Checkbox-backed switch (PHP forms): <input type="checkbox" class="sr-only peer"><span class="switch" data-switch> */
input:checked + [data-switch] { background-color: hsl(var(--primary)); }
input:checked + [data-switch]::after { transform: translateX(1rem); }

/* <details> dropdowns used for menus */
details.dropdown > summary { list-style: none; }
details.dropdown > summary::-webkit-details-marker { display: none; }

/* FAQ / accordion built on <details> */
details.faq > summary { list-style: none; cursor: pointer; }
details.faq > summary::-webkit-details-marker { display: none; }
details.faq[open] > summary svg { transform: rotate(180deg); }
details.faq[open] > p { animation: fadeIn .2s ease-out; }

/* ------------------------------------------------------------------ surfaces */

.card {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-card);
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  transition: border-color .15s ease;
}
/* Clickable cards (inbox grid): the edge firms up on hover, nothing moves. */
article.card:hover { border-color: hsl(var(--input)); }
/* A card's dropdown must sit above its neighbours while its menu is open. */
article.card:has(details.dropdown[open]), [data-row]:has(details.dropdown[open]) { z-index: 30; }
/* Select mode: a click ticks instead of opens, so the "Open" hint goes, and a ticked card gets a clear outline. */
[data-row]:has([data-select-only]:not([hidden])) [data-select-hide] { visibility: hidden; }
article[data-row]:has([data-select-only]:checked) {
  border-color: hsl(var(--primary));
  background-color: hsl(var(--primary) / 0.05);
  box-shadow: 0 0 0 1px hsl(var(--primary));
}

/* Code and API response surface: graphite in both themes, so it keeps its own light-on-dark tokens. */
.code-panel {
  --foreground: 210 20% 96.1%;
  --muted-foreground: 214.3 13.5% 69.6%;
  --border: 218.2 13.6% 15.9%;
  background-color: #0e1013;
  color: hsl(var(--foreground));
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid hsl(var(--border));
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  line-height: 1rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color .15s, background-color .15s;
}
.badge-default { border-color: transparent; background-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-secondary { border-color: transparent; background-color: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-outline { color: hsl(var(--foreground)); }
.badge-destructive { border-color: transparent; background-color: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }

/* Tabs: [data-tabs] > .tabs-list > .tab[data-tab] + [data-tab-panel] */
.tabs-list {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 1.25rem;
  max-width: 100%;
  overflow-x: auto;
  border-bottom: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  scrollbar-width: none;
}
.tabs-list::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2.5rem;
  white-space: nowrap;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s ease;
}
.tab:hover, .tab[aria-selected="true"] { color: hsl(var(--foreground)); }
.tab:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: -2px; border-radius: 0.25rem; }
/* Without script the selected tab draws its own line; motion.js swaps it for one line that slides between tabs. */
.tab[aria-selected="true"] { box-shadow: inset 0 -2px 0 hsl(var(--foreground)); }
.tabs-list.has-ink .tab[aria-selected="true"] { box-shadow: none; }
.tabs-ink { position: absolute; left: 0; bottom: 0; width: 1px; height: 2px; background-color: hsl(var(--foreground)); transform-origin: left center; pointer-events: none; }

/* ------------------------------------------------------------------ overlays */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgb(14 16 19 / 0.5);
  animation: fadeIn .2s ease-out;
}
.dark .modal-overlay { background-color: rgb(0 0 0 / 0.65); }
.modal-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long unbroken text can't widen the panel */
  overflow-wrap: anywhere; /* long emails, URLs and domains in titles/descriptions wrap */
  gap: 1.25rem;
  width: 100%;
  max-width: 32rem;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-card);
  background-color: hsl(var(--card));
  padding: 1.5rem;
  box-shadow: var(--shadow-float);
  animation: scaleIn .2s cubic-bezier(.16, 1, .3, 1);
}
/* Slim rounded scrollbar for every dialog and popup that scrolls (dialogs, anything scrolling inside them, Ctrl K
   results, select menus): the transparent border insets the thumb, the track margin keeps it clear of rounded corners */
:is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu)::-webkit-scrollbar { width: 14px; height: 14px; }
:is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu)::-webkit-scrollbar-track { background: transparent; margin: 0.5rem; }
:is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu)::-webkit-scrollbar-thumb { min-height: 2.5rem; border: 4px solid transparent; border-radius: 9999px; background-color: hsl(var(--border)); background-clip: padding-box; }
:is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu)::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground) / 0.45); }
:is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu)::-webkit-scrollbar-corner { background: transparent; }
.modal-panel::-webkit-scrollbar-track { margin-block: 0.75rem; }
@supports not selector(::-webkit-scrollbar) {
  :is(.modal-panel, .modal textarea, .modal pre, .modal .overflow-y-auto, .modal .overflow-auto, .palette-list, .cs-menu) { scrollbar-width: thin; scrollbar-color: hsl(var(--border)) transparent; }
}
.modal-x {
  position: absolute;
  top: 0.875rem;
  right: 0.875rem;
  display: inline-flex;
  padding: 0.375rem;
  border-radius: 0.5rem;
  color: hsl(var(--muted-foreground));
  transition: color .15s ease, background-color .15s ease;
  cursor: pointer;
}
.modal-x:hover { color: hsl(var(--foreground)); background-color: hsl(var(--muted)); }

.menu {
  position: fixed;
  z-index: 60;
  min-width: 8rem;
  overflow: hidden;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background-color: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: var(--shadow-float);
  animation: scaleIn .12s ease-out;
}
.menu-item {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border-radius: calc(var(--radius) - 4px);
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-align: left;
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background-color .12s ease, color .12s ease;
}
.menu-item:hover, .menu-item:focus-visible { background-color: hsl(var(--muted)); color: hsl(var(--foreground)); }
.menu-item.is-danger { color: hsl(var(--destructive)); }
.menu-item.is-danger:hover { color: hsl(var(--destructive)); background-color: hsl(var(--destructive) / 0.08); }
.sb-logout { color: hsl(var(--muted-foreground)); }
.sb-logout:hover, .sb-logout:focus-visible { color: hsl(var(--destructive)); background-color: hsl(var(--destructive) / 0.08); }
.menu-sep { margin: 0.25rem -0.25rem; height: 1px; background-color: hsl(var(--border)); }
/* Dropdown panels: softer, larger shadow and a quick pop from the top. */
details.dropdown > div { box-shadow: var(--shadow-float); border-radius: var(--radius-card); }
/* Top-bar menus on a phone span the screen, so they can't run off its left edge. */
@media (max-width: 639px) { header details.dropdown > div { position: fixed; top: 3.25rem; left: 0.75rem; right: 0.75rem; width: auto; max-width: none; margin-top: 0; } }
details.dropdown[open] > div { animation: dropIn .14s cubic-bezier(.16, 1, .3, 1); transform-origin: top right; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Tooltip shown by ui.js for [data-tip] */
.tooltip {
  position: fixed;
  z-index: 70;
  pointer-events: none;
  border-radius: 0.5rem;
  background-color: hsl(var(--foreground));
  color: hsl(var(--background));
  box-shadow: 0 4px 12px -2px rgb(0 0 0 / 0.2);
  padding: 0.375rem 0.625rem;
  font-weight: 500;
  font-size: 0.75rem;
  line-height: 1rem;
  /* Short tips stay on one line; long ones wrap */
  width: max-content;
  max-width: min(18rem, calc(100vw - 8px));
  animation: scaleIn .12s ease-out;
}

.drawer-panel { animation: slideInLeft .3s ease-out; }

/* ------------------------------------------------------------------ toasts (sonner "richColors" look) */

.toaster {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(356px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid;
  border-radius: 0.75rem;
  padding: 0.875rem 1rem;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 12px 28px -8px rgb(16 24 40 / 0.18);
  animation: toastIn .25s ease-out;
  transition: opacity .2s, transform .2s;
}
.toast-out { opacity: 0; transform: translateY(8px); }
.toast-undo { flex: none; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.toast-close { display: inline-flex; border-radius: 9999px; padding: 2px; opacity: 0.6; cursor: pointer; }
.toast-close:hover { opacity: 1; }

.toast-success { background: hsl(152 81% 96%); border-color: hsl(149 80% 85%); color: hsl(163 94% 24%); }
.toast-error   { background: hsl(359 100% 97%); border-color: hsl(359 100% 94%); color: hsl(360 100% 45%); }
.toast-info    { background: hsl(183 100% 96%); border-color: hsl(186 94% 85%); color: hsl(192 82% 31%); }
.dark .toast-success { background: hsl(164 86% 9%); border-color: hsl(163 80% 18%); color: hsl(158 64% 62%); }
.dark .toast-error   { background: hsl(358 76% 10%); border-color: hsl(357 89% 16%); color: hsl(358 100% 81%); }
.dark .toast-info    { background: hsl(193 80% 9%); border-color: hsl(192 70% 20%); color: hsl(188 86% 63%); }

/* ------------------------------------------------------------------ motion
 * Page entrances, scroll reveals, meters and the tab line live in assets/js/motion.js (GSAP). They only run while
 * .page-shell still has .animate-slide-up, i.e. on a real navigation; ui.js strips that class for same-page actions
 * and auto-refresh, so those stay still. CSS keeps the small feedback: menus, dialogs, toasts, press states. */

@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.97); } }
@keyframes slideOutLeft { from { transform: translateX(0); } to { transform: translateX(-100%); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes spinIn { from { transform: rotate(-90deg) scale(.6); opacity: 0; } to { transform: rotate(0) scale(1); opacity: 1; } }
@keyframes navProgress { 0% { width: 0; } 10% { width: 35%; } 40% { width: 65%; } 100% { width: 92%; } }
@keyframes spin { to { transform: rotate(360deg); } }

.page-shell.animate-slide-up { animation: none; }

/* Top navigation progress bar while htmx loads the next page (html.is-navigating, set by ui.js). */
.nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 95;
  height: 2px;
  width: 0;
  /* Brand green (deep teal in light mode, mint in dark mode) so it stands out from the black/white UI. */
  background-color: hsl(var(--chart-1));
  box-shadow: 0 0 8px hsl(var(--chart-1) / 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
html.is-navigating .nav-progress { opacity: 1; transition-delay: .12s; animation: navProgress 8s cubic-bezier(.1, .7, .2, 1) forwards; }

/* Modal + drawer close (ui.js adds .is-closing, then hides after the animation). */
.modal.is-closing .modal-overlay { animation: fadeOut .16s ease-out forwards; }
.modal.is-closing .modal-panel { animation: scaleOut .16s ease-out forwards; }
#drawer.is-closing > :first-child { animation: fadeOut .22s ease-out forwards; }
#drawer.is-closing .drawer-panel { animation: slideOutLeft .22s ease-out forwards; }

/* Tab panels fade in when switched. */
[data-tab-panel]:not([hidden]) { animation: fadeIn .22s ease-out; }

/* Sidebar: labels fade back in when the sidebar expands. */
html.sidebar-animating #sidebar .sb-full { animation: fadeIn .3s ease-out .08s backwards; }

/* Small feedback touches. */
/* Only on an actual click (theme-transition is set briefly by ui.js / :focus while ticking), not on every page swap. */
html.theme-transition [data-theme-toggle] svg { animation: spinIn .4s cubic-bezier(.16, 1, .3, 1); }
.checkbox:checked:focus, .checkbox:indeterminate:focus { animation: pop .22s ease-out; }
.is-copied { animation: pop .3s ease-out; color: hsl(var(--primary)) !important; border-color: hsl(var(--primary) / 0.4) !important; }
/* Submit buttons show a spinner while their htmx request is in flight. */
form.htmx-request button[type=submit].btn { position: relative; color: transparent !important; }
form.htmx-request button[type=submit].btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  height: 1rem;
  width: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid currentColor;
  border-color: hsl(var(--primary-foreground)) hsl(var(--primary-foreground)) hsl(var(--primary-foreground)) transparent;
  border-radius: 9999px;
  animation: spin .6s linear infinite;
}
form.htmx-request button[type=submit].btn:is(.btn-outline, .btn-ghost)::after { border-color: hsl(var(--primary)) hsl(var(--primary)) hsl(var(--primary)) transparent; }
/* A busy dialog (form[data-busy], ui.js) shows a spinner with step text, dims its fields and hides the way out. */
.modal.is-busy form[data-busy] button[type=submit].btn { color: hsl(var(--primary-foreground)) !important; opacity: 1; gap: 0.5rem; cursor: progress; }
.modal.is-busy form[data-busy] button[type=submit].btn::after { content: none; }
.modal.is-busy form[data-busy] > :not(:last-child) { opacity: 0.6; transition: opacity .15s ease; }
.modal.is-busy :is(.modal-x, .btn[data-close]) { pointer-events: none; opacity: 0.4; }
.btn-spinner {
  height: 1rem;
  width: 1rem;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 9999px;
  animation: spin .6s linear infinite;
}

/* ============================= Auth pages (login, sign-up, verify) ============================= */
.auth-body { background-color: hsl(var(--background)); }

/* Brand showcase panel */
.auth-showcase {
  display: none; /* large screens only (set here too, so it never flashes before Tailwind loads) */
  isolation: isolate;
  background-color: #121418;
  border-right: 1px solid rgb(255 255 255 / 0.06);
  /* Graphite in both themes, so the panel keeps its own light-on-dark tokens. */
  --primary: 210 18.2% 96.1%;
  --primary-foreground: 216 15.2% 6.5%;
}
.dark .auth-showcase { background-color: #0a0b0d; } /* a step darker than the dark form side, so the two halves still read apart */
@media (min-width: 1024px) { .auth-showcase { display: flex; } }

/* Fine grid behind the panel, fading out toward the edges, plus a faint mint wash behind the mock-up */
.auth-grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(38rem 26rem at 40% 68%, rgb(131 204 173 / 0.07), transparent 70%),
    linear-gradient(rgb(255 255 255 / 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgb(255 255 255 / 0.035) 1px, transparent 1px);
  background-size: auto, 44px 44px, 44px 44px;
  background-position: 0 0, -1px -1px, -1px -1px;
  -webkit-mask-image: radial-gradient(ellipse 85% 75% at 40% 55%, #000 35%, transparent 100%);
  mask-image: radial-gradient(ellipse 85% 75% at 40% 55%, #000 35%, transparent 100%);
}

/* Concentric rings + mint orb in the top-right corner, with two dots slowly orbiting */
.auth-shapes { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; pointer-events: none; }
.auth-orbit { transform-box: view-box; transform-origin: 790px 110px; animation: authOrbit 48s linear infinite; }
.auth-orbit-slow { animation-duration: 80s; animation-direction: reverse; }
@keyframes authOrbit { to { transform: rotate(360deg); } }
/* Fine film grain over the whole panel, so the flat graphite doesn't look digital */
.auth-showcase::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Headline word that swaps every few seconds (script in auth_end) */
.auth-rotator {
  display: inline-block;
  color: #83ccad;
  transition: opacity .35s ease, transform .45s cubic-bezier(.16, 1, .3, 1), filter .35s ease;
}
.auth-rotator.is-out { opacity: 0; transform: translateY(-0.35em); filter: blur(6px); }
.auth-rotator.is-in { opacity: 0; transform: translateY(0.35em); filter: blur(6px); transition: none; }

/* Inbox mock-up: a window with a floating "code copied" card over its corner */
.auth-stage { position: relative; margin-top: 2.5rem; padding-bottom: 2.25rem; }
@media (max-height: 780px) { .auth-stage { display: none; } } /* short laptop screens: keep the panel uncrowded */
.auth-mock {
  overflow: hidden;
  max-width: 27rem;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 0.875rem;
  background-color: #15181c;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.05) inset, 0 30px 60px -20px rgb(0 0 0 / 0.6);
}
.auth-mock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem 0.7rem 1rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.07);
  background-color: rgb(255 255 255 / 0.02);
}
.auth-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  padding: 0.2rem 0.5rem;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 0.375rem;
  font-size: 11px;
  color: rgb(255 255 255 / 0.7);
}
.auth-live { position: relative; height: 0.4375rem; width: 0.4375rem; flex-shrink: 0; border-radius: 9999px; background-color: #83ccad; }
.auth-live::after { content: ''; position: absolute; inset: -3px; border-radius: inherit; border: 1px solid #83ccad; opacity: 0; animation: authPing 2.4s ease-out infinite; }
@keyframes authPing { 0% { transform: scale(.6); opacity: .7; } 100% { transform: scale(1.8); opacity: 0; } }
.auth-mock-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-top: 1px solid rgb(255 255 255 / 0.05);
}
.auth-mock-bar + .auth-mock-row { border-top: 0; }
.auth-mock-row.is-open { background-color: rgb(131 204 173 / 0.06); box-shadow: inset 2px 0 0 #83ccad; }
.auth-mock-avatar {
  display: flex;
  height: 1.875rem;
  width: 1.875rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: 0.5rem;
  background-color: rgb(255 255 255 / 0.05);
  font-size: 0.75rem;
  font-weight: 600;
  color: rgb(255 255 255 / 0.75);
}
.auth-unread { height: 0.375rem; width: 0.375rem; border-radius: 9999px; background-color: #83ccad; }
.auth-float {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 15rem;
  padding: 0.85rem 1rem 1rem;
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 0.75rem;
  background-color: #1b1f24;
  box-shadow: 0 24px 48px -12px rgb(0 0 0 / 0.7), 0 0 0 1px rgb(0 0 0 / 0.4);
}
@media (min-width: 1280px) { .auth-float { right: -0.5rem; } }

/* Form side */
.auth-main { isolation: isolate; background-color: hsl(var(--sheet)); }
.auth-glow { display: none; } /* still used by shared.php */
.auth-foot {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid hsl(var(--border));
  font-size: 0.8125rem;
  line-height: 1.6;
  color: hsl(var(--muted-foreground));
}

/* Step bar (auth_steps): thin segments, filled up to the current step */
.auth-steps { display: flex; gap: 0.375rem; margin-bottom: 1.75rem; }
.auth-steps > span { flex: 1; height: 3px; border-radius: 9999px; background-color: hsl(var(--border)); transition: background-color .3s ease; }
.auth-steps > span.is-on { background-color: hsl(var(--primary)); }

/* Icon inputs + password toggle */
.auth-field-icon { position: absolute; left: 0.875rem; top: 50%; transform: translateY(-50%); color: hsl(var(--muted-foreground)); pointer-events: none; transition: color .15s ease; }
.auth-field:focus-within .auth-field-icon { color: hsl(var(--primary)); }
.auth-field .input:focus-visible { border-color: hsl(var(--foreground) / 0.55); box-shadow: 0 0 0 3px hsl(var(--foreground) / 0.08); }
.auth-pw-toggle {
  position: absolute;
  right: 0.375rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  height: 2rem;
  width: 2rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  color: hsl(var(--muted-foreground));
  transition: background-color .15s ease, color .15s ease;
}
.auth-pw-toggle:hover { background-color: hsl(var(--muted)); color: hsl(var(--foreground)); }

/* Password strength meter: 4 segments, coloured up to data-score */
.pw-meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.25rem; }
.pw-meter > span { height: 0.25rem; border-radius: 9999px; background-color: hsl(var(--muted)); transition: background-color .25s ease; }
[data-score="1"] .pw-meter > span:nth-child(-n+1) { background-color: hsl(var(--destructive)); }
[data-score="2"] .pw-meter > span:nth-child(-n+2) { background-color: hsl(var(--warning)); }
[data-score="3"] .pw-meter > span:nth-child(-n+3) { background-color: hsl(var(--success)); }
[data-score="4"] .pw-meter > span { background-color: hsl(var(--success)); }
[data-score="0"] [data-pw-label], [data-score="1"] [data-pw-label] { color: hsl(var(--destructive)); }
[data-score="2"] [data-pw-label] { color: hsl(var(--warning)); }
[data-score="3"] [data-pw-label], [data-score="4"] [data-pw-label] { color: hsl(var(--success)); }

.auth-main .btn-primary { height: 2.75rem; } /* same height as the inputs */

/* Smooth colour change when switching light / dark (html.theme-transition is set briefly by ui.js). */
html.theme-transition, html.theme-transition *, html.theme-transition *::before, html.theme-transition *::after {
  transition: background-color .3s ease, border-color .3s ease, color .3s ease, fill .3s ease !important;
}
