/* Masala R&D — theme.
 *
 * Two registers, deliberately:
 *
 *   The dashboard is dense and dramatic. You glance at it.
 *   Everything else is calm and quiet. You read it for an hour.
 *
 * A formulator comparing 15 ingredient percentages does not want glow. A person
 * checking where things stand at 9am does. Same system, different jobs.
 *
 * Both registers follow the light/dark toggle: the dashboard runs its own
 * --dash-* palette (see .dash) that flips with the theme like everything else.
 *
 * Contrast: every foreground/background pair meets WCAG AA in both modes.
 */

:root {
  /* Brand */
  --spice-red: #9a2617;
  --spice-red-dark: #7a1e12;
  --spice-red-light: #c14a34;
  --warm-orange: #e8751a;

  /* Surfaces */
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-alt: #f1efea;
  --border: #e4e0d8;
  --border-strong: #cdc7bb;

  /* Text */
  --text: #23211f;
  --text-muted: #736c64;
  --text-faint: #9c948b;
  --text-inverse: #ffffff;

  /* Status */
  --success: #2e7d32;
  --success-bg: #e9f5ea;
  --warning: #a86200;
  --warning-bg: #fdf3e3;
  --danger: #c62828;
  --danger-bg: #fdeceb;
  --info: #1565c0;
  --info-bg: #e9f1fb;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(35, 33, 31, .05);
  --sidebar-w: 216px;
  --sidebar-w-collapsed: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --spice-red: #e0684f;
    --spice-red-dark: #c14a34;
    --spice-red-light: #f08a72;
    --warm-orange: #f3903f;
    --bg: #161514;
    --surface: #201f1e;
    --surface-alt: #292726;
    --border: #35322f;
    --border-strong: #4a4541;
    --text: #ece8e3;
    --text-muted: #9d958c;
    --text-faint: #736c64;
    --text-inverse: #161514;
    --success: #7cc47f;
    --success-bg: #1c2b1d;
    --warning: #e8a33d;
    --warning-bg: #302512;
    --danger: #ef7b72;
    --danger-bg: #301c1a;
    --info: #6ba7e8;
    --info-bg: #18232f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --spice-red: #e0684f;
  --spice-red-dark: #c14a34;
  --spice-red-light: #f08a72;
  --warm-orange: #f3903f;
  --bg: #161514;
  --surface: #201f1e;
  --surface-alt: #292726;
  --border: #35322f;
  --border-strong: #4a4541;
  --text: #ece8e3;
  --text-muted: #9d958c;
  --text-faint: #736c64;
  --text-inverse: #161514;
  --success: #7cc47f;
  --success-bg: #1c2b1d;
  --warning: #e8a33d;
  --warning-bg: #302512;
  --danger: #ef7b72;
  --danger-bg: #301c1a;
  --info: #6ba7e8;
  --info-bg: #18232f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

/* ---------- Bootstrap bridge ----------
 * Bootstrap 5.3 paints its own components — tables, form controls, dropdowns,
 * alerts, .text-muted — from --bs-* variables, keyed to [data-bs-theme]. The
 * app.js toggle sets data-bs-theme alongside data-theme so those components
 * switch too; here we point the --bs-* vars at our palette so they match the
 * warm theme instead of Bootstrap's stock grey. These reference our custom
 * vars, which already flip with data-theme / prefers-color-scheme, so the
 * bridge flips with them — no dark duplicate needed. */
:root {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-emphasis-color: var(--text);
  --bs-heading-color: var(--text);
  --bs-secondary-color: var(--text-muted);
  --bs-secondary-bg: var(--surface-alt);
  --bs-tertiary-color: var(--text-faint);
  --bs-tertiary-bg: var(--surface-alt);
  --bs-border-color: var(--border);
  --bs-link-color: var(--spice-red);
  --bs-link-hover-color: var(--spice-red-dark);
  --bs-emphasis-color-rgb: 35, 33, 31;
}

/* ---------- Base ---------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--spice-red); text-decoration: none; }
a:hover { color: var(--spice-red-dark); text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--warm-orange);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--spice-red); color: #fff; padding: .6rem 1rem;
}
.skip-link:focus { left: 0; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

/* Sidebar: chrome, not content. Light by default, dark override below — so it
 * follows the theme toggle instead of staying dark in light mode. */
.sidebar {
  /* light register */
  --sb-bg: #ffffff;
  --sb-border: #e4e0d8;
  --sb-brand: #23211f;
  --sb-label: #9c948b;
  --sb-link: #56504a;
  --sb-hover-bg: #f1efea;
  --sb-hover-text: #23211f;
  --sb-active-bg: #f1efea;
  --sb-active-text: #23211f;
  --sb-scroll: #cdc7bb;

  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width .12s ease, flex-basis .12s ease;
}
/* Dark register — same activation conditions as the app's dark palette. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sidebar {
    --sb-bg: #1a1918;
    --sb-border: #2a2827;
    --sb-brand: #ffffff;
    --sb-label: #6b635a;
    --sb-link: #b8b0a7;
    --sb-hover-bg: #262423;
    --sb-hover-text: #ffffff;
    --sb-active-bg: #262423;
    --sb-active-text: #ffffff;
    --sb-scroll: #35322f;
  }
}
:root[data-theme="dark"] .sidebar {
  --sb-bg: #1a1918;
  --sb-border: #2a2827;
  --sb-brand: #ffffff;
  --sb-label: #6b635a;
  --sb-link: #b8b0a7;
  --sb-hover-bg: #262423;
  --sb-hover-text: #ffffff;
  --sb-active-bg: #262423;
  --sb-active-text: #ffffff;
  --sb-scroll: #35322f;
}
.app.is-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  flex-basis: var(--sidebar-w-collapsed);
}
.app.is-collapsed .sidebar .nav-label,
.app.is-collapsed .sidebar .sidebar-brand-text,
.app.is-collapsed .sidebar .nav-section-label { display: none; }
.app.is-collapsed .sidebar .nav-link { justify-content: center; padding-inline: 0; }

.sidebar-brand {
  display: flex; align-items: center; gap: .55rem;
  padding: 1.1rem .95rem; border-bottom: 1px solid var(--sb-border);
  color: var(--sb-brand); font-weight: 600; font-size: .92rem; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden;
}
.sidebar-brand .bi { color: var(--warm-orange); font-size: 1.05rem; flex: 0 0 auto; }

.sidebar-nav { padding: .5rem .4rem 1rem; overflow-y: auto; flex: 1; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sb-scroll); border-radius: 2px; }

.nav-section-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--sb-label); padding: 1rem .6rem .35rem; font-weight: 600;
}

.sidebar .nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .42rem .6rem; border-radius: var(--radius-sm);
  color: var(--sb-link); font-size: .82rem; white-space: nowrap;
  border-left: 2px solid transparent;
}
.sidebar .nav-link .bi { font-size: .95rem; flex: 0 0 .95rem; opacity: .75; }
.sidebar .nav-link:hover { background: var(--sb-hover-bg); color: var(--sb-hover-text); text-decoration: none; }
.sidebar .nav-link.active {
  background: var(--sb-active-bg); color: var(--sb-active-text); font-weight: 500;
  border-left-color: var(--warm-orange);
}
.sidebar .nav-link.active .bi { color: var(--warm-orange); opacity: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .55rem 1.25rem; display: flex; align-items: center; gap: .9rem;
  position: sticky; top: 0; z-index: 10;
}
.topbar .search { flex: 1; max-width: 380px; }
.topbar .form-control {
  background: var(--bg); border-color: var(--border); color: var(--text);
  font-size: .82rem;
}
.topbar .form-control::placeholder { color: var(--text-faint); }

.content { padding: 1.4rem 1.25rem 3rem; flex: 1; }

/* ---------- Working pages: calm ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-header {
  background: transparent; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .82rem; padding: .7rem .9rem;
  letter-spacing: .01em;
}
.card-header .bi { color: var(--text-faint); }
.card-body { padding: .9rem; }

.table {
  font-size: .82rem; margin-bottom: 0;
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
  --bs-table-hover-color: var(--text);
  --bs-table-striped-color: var(--text);
}
.table thead th {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600; border-bottom-color: var(--border);
  padding: .5rem .6rem; white-space: nowrap;
}
.table tbody td { padding: .45rem .6rem; border-color: var(--border); }
.table-hover tbody tr:hover { background: var(--surface-alt); }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem .9rem; height: 100%;
}
.stat-label {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 600;
}
.stat-value {
  font-size: 1.5rem; font-weight: 650; color: var(--text);
  line-height: 1.15; margin-top: .1rem; font-variant-numeric: tabular-nums;
}
.stat-note { font-size: .7rem; color: var(--text-faint); margin-top: .2rem; }
.stat.is-pending { border-style: dashed; background: transparent; }
.stat.is-pending .stat-value { color: var(--text-faint); font-weight: 400; }

.badge-status {
  font-size: .66rem; font-weight: 600; padding: .15rem .45rem;
  border-radius: 3px; border: 1px solid transparent; white-space: nowrap;
  display: inline-block;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-muted   { background: var(--surface-alt); color: var(--text-muted); }

.breadcrumb { margin: 0; font-size: .76rem; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .active { color: var(--text); }

.empty-state { text-align: center; padding: 2.2rem 1rem; color: var(--text-faint); }
.empty-state .bi { font-size: 1.6rem; opacity: .4; display: block; margin-bottom: .5rem; }
.empty-state p { font-size: .82rem; margin: 0; }

.btn { font-size: .8rem; }
.btn-sm { font-size: .75rem; padding: .25rem .55rem; }
.btn-primary {
  background: var(--spice-red); border-color: var(--spice-red); color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--spice-red-dark); border-color: var(--spice-red-dark); color: #fff;
}
.btn-outline-secondary { color: var(--text); border-color: var(--border-strong); }
.btn-outline-secondary:hover {
  background: var(--surface-alt); color: var(--text); border-color: var(--border-strong);
}

.form-control, .form-select { font-size: .8rem; }
.page-title { font-size: 1.05rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-sub { font-size: .76rem; color: var(--text-muted); margin: .1rem 0 0; }

.htmx-indicator { opacity: 0; transition: opacity .12s ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------- Dashboard: the other register ---------- */
.dash {
  /* Light by default now; the dark override below restores the dramatic dark
   * register whenever the app is in dark mode. It used to be always-dark and
   * ignored the toggle — now it follows the theme like every other page. */
  --dash-bg: #efece6;
  --dash-panel: #ffffff;
  --dash-line: #e4e0d8;
  --dash-text: #23211f;
  --dash-dim: #6f685f;
  --dash-accent: #b5560e;
  --dash-accent-2: #b3271a;

  background: var(--dash-bg);
  margin: -1.4rem -1.25rem -3rem;
  padding: 1.6rem 1.5rem 3rem;
  min-height: calc(100vh - 46px);
  color: var(--dash-text);
}

.dash-head { margin-bottom: 1.5rem; }
.dash-title {
  font-size: 1.35rem; font-weight: 650; letter-spacing: -.02em; margin: 0;
  color: var(--dash-text);
}
.dash-sub { font-size: .78rem; color: var(--dash-dim); margin: .25rem 0 0; }

.dash-grid {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: .75rem;
}

.tile {
  background: var(--dash-panel);
  border: 1px solid var(--dash-line);
  border-radius: 10px;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}
/* The one flourish: a hairline of accent along the top edge. Not a gradient wash. */
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--dash-accent), transparent);
  opacity: .5;
}
.tile-label {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dash-dim); font-weight: 600;
}
.tile-value {
  font-size: 2rem; font-weight: 300; line-height: 1.05; margin-top: .35rem;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  color: var(--dash-text);
}
.tile-value.accent { color: var(--dash-accent); }
.tile-value.warn { color: var(--dash-accent-2); }
.tile-value.dim { color: var(--dash-dim); font-weight: 200; }
.tile-note { font-size: .66rem; color: var(--dash-dim); margin-top: .3rem; }

.tile-lg { grid-column: span 2; }
@media (max-width: 640px) { .tile-lg { grid-column: span 1; } }

.dash-panel {
  background: var(--dash-panel);
  border: 1px solid var(--dash-line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: .75rem;
}
.dash-panel-title {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dash-dim); font-weight: 600; margin-bottom: .8rem;
  display: flex; align-items: center; gap: .5rem;
}

/* A thin horizontal bar. Reads as a proportion without needing a chart library. */
.meter { height: 3px; background: var(--dash-line); border-radius: 2px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--dash-accent); border-radius: 2px; }
.meter-fill.red { background: var(--dash-accent-2); }
.meter-fill.dim { background: var(--dash-dim); }

.dash-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .45rem 0; border-bottom: 1px solid var(--dash-line);
  font-size: .78rem;
}
.dash-row:last-child { border-bottom: 0; }
.dash-row .name { flex: 1; min-width: 0; color: var(--dash-text); }
.dash-row .bar { flex: 0 0 90px; }
.dash-row .val {
  flex: 0 0 auto; font-variant-numeric: tabular-nums; color: var(--dash-dim);
  font-size: .74rem; min-width: 3.5rem; text-align: right;
}

.dash a { color: var(--dash-accent); }
.dash a:hover { color: var(--dash-accent-2); }

.dash-link {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .72rem; color: var(--dash-dim); text-decoration: none;
}
.dash-link:hover { color: var(--dash-accent); text-decoration: none; }

/* Dashboard dark register — applied under the same conditions as the app's dark
 * palette (OS-dark unless forced light, or explicit dark) so it tracks the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dash {
    --dash-bg: #121110;
    --dash-panel: #1c1b1a;
    --dash-line: #2c2a28;
    --dash-text: #f0ece7;
    --dash-dim: #8b837a;
    --dash-accent: #e8751a;
    --dash-accent-2: #e0684f;
  }
}
:root[data-theme="dark"] .dash {
  --dash-bg: #121110;
  --dash-panel: #1c1b1a;
  --dash-line: #2c2a28;
  --dash-text: #f0ece7;
  --dash-dim: #8b837a;
  --dash-accent: #e8751a;
  --dash-accent-2: #e0684f;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; z-index: 30; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .16s ease;
  }
  .app.is-open .sidebar { transform: translateX(0); }
  .app.is-open .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 20; }
  .topbar .search { max-width: none; }
  .dash { margin-inline: -1.25rem; padding-inline: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
