/* ============================================================================
   Kinder Bites Portal — design system (app.css)
   ----------------------------------------------------------------------------
   Framework-free. Replaces Bootstrap 5. Structure borrowed from the DWWA portal
   (fixed sidebar + sticky topbar + custom components); palette + typography from
   the Kinder Bites brand site (www.kinder-bites.com): soft sage greens, Poppins
   headings, Inter body. LIGHT is the default theme; DARK is opt-in via
   <html data-theme="dark"> (see theme.js). All colors flow through the CSS custom
   properties below, so the dark override is a single small block.

   NOTE (migration): a few "legacy compat" shims live at the very bottom, kept only
   while the portal is mid-conversion (Phase 1 = shell + login + styleguide). They
   are removed once every page has been converted to the semantic classes here.
   ========================================================================== */

/* ─────────────────────────────────────────────────────────────────────────
   1. Design tokens
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* Brand palette (from the Kinder Bites logo / marketing site) */
  --green-700: #3f7e22;
  --green-600: #4f9d2b;
  --green-500: #6fb22c;
  --green-100: #eaf4e1;
  --brand-orange: #f39b1f;
  --brand-red:    #d8392a;
  --brand-purple: #7b2d8e;

  /* Semantic — LIGHT theme (default) */
  --bg:        #f5f9f1;   /* page background: barely-there sage */
  --surface:   #ffffff;   /* cards, sidebar, topbar, modals */
  --surface-2: #eef4e8;   /* table headers, subtle panels, hovers */
  --panel:     #f7faf4;   /* inset panels */
  --border:    #e3ebdd;   /* hairlines, dividers */
  --border-strong: #d4e0c8;

  --primary:        #64b23a;
  --primary-strong: #4a8f27;
  --primary-soft:   #eaf4e1;
  --on-primary:     #ffffff;

  --accent:  #f39b1f;
  --danger:  #d8392a;
  --danger-strong: #b32b1f;
  --warning: #e08a12;
  --success: #64b23a;
  --info:    #2c8bb0;

  --ink:       #1d2a21;   /* headings */
  --text:      #2d3b31;   /* body */
  --text-soft: #47574b;   /* secondary */
  --muted:     #6c7d73;   /* captions, placeholders, labels */

  --focus-ring: rgba(79, 157, 43, .28);
  --danger-ring: rgba(216, 57, 42, .22);

  /* Typography */
  --font-head: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: Consolas, Menlo, "SFMono-Regular", monospace;

  /* Metrics */
  --nav-w: 250px;
  --topbar-h: 64px;
  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(29, 42, 33, .06), 0 1px 3px rgba(29, 42, 33, .05);
  --shadow-md: 0 4px 14px rgba(29, 42, 33, .09);
  --shadow-lg: 0 16px 40px rgba(29, 42, 33, .18);

  --z-topbar:  40;
  --z-overlay: 45;   /* below the sidebar (must not cover its links), above topbar/content */
  --z-sidebar: 50;
  --z-modal:   1050;
  --z-toast:   1090;
}

/* Semantic — DARK theme (opt-in). Warm, green-tinted neutrals so the brand green
   still reads as "the accent" rather than a lone splash of color. */
html[data-theme="dark"] {
  --bg:        #141312;
  --surface:   #1d1c1b;
  --surface-2: #272524;
  --panel:     #201f1e;
  --border:    #34322f;
  --border-strong: #46433f;

  --primary:        #7cc74e;
  --primary-strong: #6fb22c;
  --primary-soft:   #23301a;
  --on-primary:     #10140d;

  --accent:  #f6ad3f;
  --danger:  #ef5a4c;
  --danger-strong: #f0705f;
  --warning: #f0b24a;
  --success: #7cc74e;
  --info:    #4bb4d8;

  --ink:       #eeedec;
  --text:      #d9d8d5;
  --text-soft: #b4b2ae;
  --muted:     #8b8984;

  --focus-ring: rgba(124, 199, 78, .30);
  --danger-ring: rgba(239, 90, 76, .28);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .55);
}

/* ─────────────────────────────────────────────────────────────────────────
   2. Reset / base
   ───────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  /* Keep the vertical scrollbar reserved so the viewport width never jumps when
     content grows (FullCalendar measures width at load — Phase 2 relies on this). */
  overflow-y: scroll;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .2s ease, color .2s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-head);
  color: var(--ink);
  line-height: 1.2;
  margin: 0 0 .5em;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.7rem; font-weight: 700; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

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

code, kbd, pre { font-family: var(--font-mono); }

img { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.muted { color: var(--muted); }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ─────────────────────────────────────────────────────────────────────────
   3. App layout — fixed sidebar + sticky topbar + fluid content (DWWA shell)
   ───────────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav-w);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand img { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; }
.sidebar-brand-text {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.1;
  color: var(--ink);
}
.sidebar-brand-text span {
  display: block;
  font-weight: 500;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--primary);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

.nav-section-label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 10px 6px;
}
.nav-section-label:first-child { padding-top: 4px; }

.nav-links { list-style: none; margin: 0; padding: 0; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-family: var(--font-head);
  font-weight: 500;
  font-size: .92rem;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.nav-links a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: .95rem;
  color: var(--muted);
  flex-shrink: 0;
}
.nav-links a:hover {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}
.nav-links a:hover .nav-icon { color: var(--primary); }
.nav-links a.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
}
.nav-links a.active .nav-icon { color: var(--primary-strong); }

.sidebar-footer {
  flex-shrink: 0;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 10px;
  flex-wrap: wrap;
}
.sidebar-user strong { font-size: .92rem; color: var(--ink); font-weight: 600; }
.sidebar-actions { display: flex; gap: 8px; }
.sidebar-actions .btn { flex: 1; }

/* Main column offset by the sidebar */
.main-wrap {
  margin-left: var(--nav-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: .85rem;
}

.content { flex: 1; padding: 26px clamp(16px, 3vw, 30px); }
.content > .page-title { margin-bottom: 18px; }

/* Hamburger (mobile only) */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.hamburger span { display: block; height: 2px; border-radius: 2px; background: var(--text); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 10, .45);
  z-index: var(--z-overlay);
}
.sidebar-overlay.open { display: block; }

/* ── Collapsible sidebar (desktop icon-only rail; state persisted on <html>) ── */
.nav-collapse-btn { display: inline-flex; }   /* desktop-only toggle (hidden on mobile below) */
.nav-c-closed { display: none; }
html.nav-collapsed .nav-c-open   { display: none; }
html.nav-collapsed .nav-c-closed { display: inline; }
/* The generic upward [data-tooltip] bubble is for grids; suppress it inside the sidebar. The
   collapsed rail instead uses .kb-nav-tip — a single JS-positioned bubble parented to <body> so it
   can never be clipped or painted over by page content (an in-sidebar ::after bubble was). */
.sidebar [data-tooltip]::before, .sidebar [data-tooltip]::after { content: none; }
.kb-nav-tip {
  position: fixed;
  transform: translateY(-50%) translateX(-4px);
  background: var(--ink); color: var(--surface);
  padding: 5px 9px; border-radius: 7px;
  font-family: var(--font-body); font-size: .74rem; font-weight: 500; line-height: 1.2;
  white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18);
  opacity: 0; pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
  z-index: 1040;   /* above content, below modals/toasts (1050/1090) */
}
.kb-nav-tip.show { opacity: 1; transform: translateY(-50%) translateX(0); }

@media (min-width: 861px) {
  html.nav-collapsed { --nav-w: 68px; }   /* shrinks .sidebar width AND .main-wrap margin at once */
  html.nav-collapsed .sidebar-brand { padding: 0; justify-content: center; gap: 0; }
  html.nav-collapsed .sidebar-brand-text,
  html.nav-collapsed .nav-section-label,
  html.nav-collapsed .nav-label,
  html.nav-collapsed .sidebar-user,
  html.nav-collapsed .btn-label { display: none; }
  html.nav-collapsed .nav-links a { justify-content: center; gap: 0; padding: 10px 0; }
  html.nav-collapsed .nav-links a .nav-icon { width: auto; font-size: 1.05rem; }
  html.nav-collapsed .sidebar-actions { flex-direction: column; gap: 6px; }
  html.nav-collapsed .sidebar-actions .btn { padding: 8px 0; }
}

@media (max-width: 860px) {
  .nav-collapse-btn { display: none; }   /* mobile uses the hamburger + off-canvas drawer instead */
}

/* Impersonation strip */
.impersonation-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 20px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--ink);
  font-size: .88rem;
  font-weight: 500;
}
.impersonation-strip > span .fa { color: var(--accent); }

/* Logged-out (auth) shell */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 18px;
  gap: 22px;
}
.auth-brand { text-align: center; }
.auth-brand img { max-width: 220px; }
.auth-card { width: 100%; max-width: 400px; }
.floating-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--z-topbar);
}

/* ─────────────────────────────────────────────────────────────────────────
   4. Buttons
   ───────────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .9rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .05s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-strong); border-color: var(--danger-strong); color: #fff; }

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--primary); color: var(--ink); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-accent  { background: var(--accent); border-color: var(--accent); color: #3a2600; }
.btn-accent:hover { filter: brightness(1.05); }

.btn-sm  { padding: 6px 11px; font-size: .82rem; border-radius: 8px; }
.btn-lg  { padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-pill { border-radius: var(--radius-pill); }

/* Icon-only round button (topbar theme toggle, etc.) */
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }

/* Theme toggle: show moon in light mode (→ switch to dark), sun in dark mode */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ─────────────────────────────────────────────────────────────────────────
   5. Cards & panels
   ───────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  /* NOTE: no `overflow: hidden` — it would clip KBSelect/date-picker popovers that
     open inside a card. Instead the header/footer round their own outer corners. */
}
.card + .card { margin-top: 18px; }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.card > .card-header:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card > .card-footer:last-child  { border-radius: 0 0 var(--radius) var(--radius); }
.card-header h1, .card-header h2, .card-header h3, .card-title { margin: 0; }
.card-title { font-size: 1.1rem; font-family: var(--font-head); font-weight: 600; color: var(--ink); }
.card-sub { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.page-header h1 { margin: 0; }

/* ─────────────────────────────────────────────────────────────────────────
   6. Forms
   ───────────────────────────────────────────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label, .form-label {
  font-family: var(--font-head);
  font-weight: 500;
  font-size: .82rem;
  color: var(--text-soft);
}
.form-field .field-hint { font-size: .78rem; color: var(--muted); }

.form-control,
.form-select,
input[type="text"].form-control,
select.form-select,
textarea.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .92rem;
  line-height: 1.4;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea.form-control { min-height: 90px; resize: vertical; }
.form-control::placeholder { color: var(--muted); }
.form-control:focus,
.form-select:focus,
textarea.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.form-control:disabled, .form-select:disabled { background: var(--surface-2); opacity: .7; cursor: not-allowed; }

.form-select {
  appearance: none;
  -webkit-appearance: none;
  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='%236c7d73' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 34px;
}

/* JustValidate error state */
.is-invalid,
.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-ring);
}
.just-validate-error-label,
.js-validate-error-label {
  color: var(--danger);
  font-size: .8rem;
  margin-top: 4px;
}

/* Checkbox / radio */
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check-input {
  width: 1.05em;
  height: 1.05em;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.form-check-label { font-size: .9rem; color: var(--text); cursor: pointer; }

/* Toggle switch */
.form-switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.form-switch input {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background .15s ease;
  flex-shrink: 0;
}
.form-switch input::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .15s ease;
}
.form-switch input:checked { background: var(--primary); }
.form-switch input:checked::after { transform: translateX(18px); }
.form-switch input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.form-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.link-muted { color: var(--muted); font-size: .88rem; cursor: pointer; }
.link-muted:hover { color: var(--primary-strong); }

/* ─────────────────────────────────────────────────────────────────────────
   7. Tables
   ───────────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table thead th {
  text-align: left;
  padding: 11px 12px;
  background: transparent;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .td-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table .td-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table tbody tr.row-danger { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.table tbody tr.row-danger:hover { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); }

/* ─────────────────────────────────────────────────────────────────────────
   8. Badges
   ───────────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .72rem;
  line-height: 1.4;
  border: 1px solid transparent;
}
.badge-green   { background: var(--primary-soft); color: var(--primary-strong); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.badge-gray    { background: var(--surface-2); color: var(--text-soft); border-color: var(--border); }
.badge-orange  { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); color: #9a6208; border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.badge-red     { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger-strong); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
html[data-theme="dark"] .badge-orange { color: var(--accent); }

/* ─────────────────────────────────────────────────────────────────────────
   9. Alerts / flash
   ───────────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 16px;
}
.alert-success { background: var(--primary-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); color: var(--primary-strong); }
.alert-danger  { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger-strong); }
.alert-info    { background: color-mix(in srgb, var(--info) 12%, var(--surface)); border-color: color-mix(in srgb, var(--info) 40%, transparent); color: var(--info); }

/* ─────────────────────────────────────────────────────────────────────────
   10. Modal (vanilla — drives KBUI in ui.js)
   ───────────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 16px;
  overflow-y: auto;
  background: rgba(15, 20, 10, .5);
  opacity: 0;
  transition: opacity .18s ease;
}
.modal-backdrop.open { opacity: 1; }

.modal {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  transform: translateY(-10px);
  transition: transform .18s ease;
  display: flex;
  flex-direction: column;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 1080px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
  background: var(--primary-soft);
  color: var(--primary-strong);
  border-radius: var(--radius) var(--radius) 0 0;
}
.modal-title { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; color: var(--primary-strong); }
.modal-close {
  background: transparent;
  border: 0;
  color: var(--primary-strong);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: .85;
}
.modal-close:hover { opacity: 1; }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  border-radius: 0 0 var(--radius) var(--radius);
}
body.modal-open { overflow: hidden; }

/* ─────────────────────────────────────────────────────────────────────────
   11. Toasts (vanilla — drives KBUI.notify)
   ───────────────────────────────────────────────────────────────────────── */
.kb-toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
}
.kb-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.kb-toast.show { opacity: 1; transform: translateY(0); }
.kb-toast-body { flex: 1; font-size: .9rem; }
.kb-toast-close { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.kb-toast-success { border-left-color: var(--success); }
.kb-toast-danger  { border-left-color: var(--danger); }
.kb-toast-warning { border-left-color: var(--warning); }
.kb-toast-info    { border-left-color: var(--info); }

/* ─────────────────────────────────────────────────────────────────────────
   12. Utilities (small, intentional set — not a utility framework)
   ───────────────────────────────────────────────────────────────────────── */
.stack   { display: flex; flex-direction: column; gap: 16px; }
.cluster { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread  { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
/* Kitchen page: the left form is shorter than the results table, so top-align the columns
   (the shared .spread centers them, which left a large gap above the form). */
.kitchen-layout { align-items: flex-start; }
/* Cap the form column and let the results table claim the remaining width, so its rows stop
   wrapping (Season/When/action buttons had been stacking in a content-sized column). min-width:0
   lets the flex item shrink so the inner width:100% table fits. Columns still stack on mobile
   (inherited flex-wrap from .spread). */
.kitchen-layout > aside            { flex: 0 1 400px; }
.kitchen-layout > #search-results  { flex: 1 1 480px; min-width: 0; }
/* Keep the four nav tabs on one line inside the capped form column. */
.menu-nav-tabs { flex-wrap: nowrap; gap: 0; }
.menu-nav-tabs .tab { padding: 9px 10px; font-size: .86rem; white-space: nowrap; }
/* Keep short value columns (Season, When) on one line. */
.table .td-nowrap { white-space: nowrap; }
/* Keep the row-action icons on ONE line so the row can't grow tall. Without this, a narrow
   actions column (e.g. on a laptop, worsened when a badge widens the meal cell) let the icons
   wrap into a vertical stack, making the row extremely tall. They're ~108px total, so reserving
   that is cheap; the flexible meal cell absorbs the width instead. */
#search-results .td-actions { flex-wrap: nowrap; }

/* Square icon-only button (used for the compact Menus-tab row actions). */
.btn-icon { width: 32px; height: 32px; padding: 0; gap: 0; }

/* Slick hover/focus tooltip — add data-tooltip="..." to any element. No JS. */
[data-tooltip] { position: relative; }
[data-tooltip]::after,
[data-tooltip]::before { opacity: 0; pointer-events: none; transition: opacity .14s ease, transform .14s ease; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--ink);
  color: var(--surface);
  padding: 5px 9px;
  border-radius: 7px;
  font-family: var(--font-body);
  font-size: .74rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: var(--shadow-md, 0 4px 14px rgba(0,0,0,.18));
  z-index: 60;
}
[data-tooltip]::before {   /* little arrow */
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 5px solid transparent;
  border-top-color: var(--ink);
  z-index: 60;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after,
[data-tooltip]:hover::before, [data-tooltip]:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.grow    { flex: 1; }
.hidden  { display: none !important; }

.spinner {
  display: inline-block;
  width: 2.2rem;
  height: 2.2rem;
  border: .22em solid var(--border-strong);
  border-right-color: var(--primary);
  border-radius: 50%;
  animation: kb-spin .7s linear infinite;
}
.spinner-center { display: flex; justify-content: center; padding: 24px 0; }
@keyframes kb-spin { to { transform: rotate(360deg); } }

/* Initial-hidden auth sub-cards (used by login + passwdreset flows) */
#recover-account-container,
#recovery-secondary-container,
#reset-success,
#result-container { display: none; }

/* ─────────────────────────────────────────────────────────────────────────
   13. Responsive
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .hamburger { display: flex; }
  .topbar-right .topbar-date { display: none; }
}

/* Phones: stack action buttons full-width instead of wrapping into a jagged grid. */
@media (max-width: 600px) {
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; }
}

@media print {
  .sidebar, .topbar, .sidebar-overlay, .impersonation-strip, .kb-toast-container { display: none !important; }
  .d-print-none { display: none !important; }
  .main-wrap { margin-left: 0; }
  body { background: #fff; }
}

/* ─────────────────────────────────────────────────────────────────────────
   14. Tabs (kitchen: Menus / Items / Ingredients / Production)
   ───────────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab {
  padding: 10px 18px;
  border: 0;
  background: transparent;
  border-bottom: 2px solid transparent;
  color: var(--text-soft);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  margin-bottom: -1px;
  text-decoration: none;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary-strong); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─────────────────────────────────────────────────────────────────────────
   15. List group (selectable lists — kitchen search picks, menu items)
   ───────────────────────────────────────────────────────────────────────── */
.list-group {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 14px;
}
.list-group-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: .92rem;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.list-group-item:last-child { border-bottom: 0; }
.list-group-item:hover { background: var(--surface-2); color: var(--ink); }
.list-group-item.active { background: var(--primary-soft); color: var(--primary-strong); }

/* ─────────────────────────────────────────────────────────────────────────
   16. Search box (input + adjoined button — replaces input-group)
   ───────────────────────────────────────────────────────────────────────── */
.search-box {
  display: inline-flex;
  align-items: stretch;
  width: 100%;
  max-width: 22rem;
}
.search-box .form-control { flex: 1 1 auto; min-width: 0; }
/* Only square the input's right corner when a button is adjoined (e.g. KBTable search);
   an [addon][input] pair (attendance counts) keeps the input's right corner rounded. */
.search-box .form-control:has(+ .btn) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.search-box .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  margin-left: -1px;
}
.search-box .addon {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.search-box .addon:first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
  border-right: none;
}
.search-box .addon:last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  border-left: none;
}
.search-box .addon:first-child + .form-control,
.search-box .addon:first-child + .form-select {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.form-inline {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* Menus tab (kitchen) search form: the advanced-option fields are bare label/select
   pairs in a form-stack, so every element sat a full 16px apart. Tighten it — group
   each label with its input (6px) and use a smaller gap between fields. */
#search-menu-form { gap: 12px; }
#search-menu-advanced-options { gap: 6px; }
#search-menu-advanced-options .kb-select + label,
#search-menu-advanced-options select + label { margin-top: 8px; }

/* ─────────────────────────────────────────────────────────────────────────
   17. KBSelect (vanilla searchable select — select.js)
   ───────────────────────────────────────────────────────────────────────── */
.kb-select { position: relative; }
.kb-select-toggle {
  width: 100%;
  text-align: left;
  min-height: calc(1.4em + 20px);
  white-space: normal;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.kb-select-toggle.placeholder { color: var(--muted); }
.kb-select-menu {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  min-width: 12rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
}
.kb-select.open .kb-select-menu { display: block; }
.kb-select-search { margin-bottom: 6px; }
.kb-select-list { max-height: 16rem; overflow-y: auto; display: flex; flex-direction: column; }
.kb-select-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: .9rem;
  cursor: pointer;
}
.kb-select-item:hover { background: var(--surface-2); }
.kb-select-item.active { background: var(--primary-soft); color: var(--primary-strong); }
.kb-select-item.disabled { opacity: .5; cursor: default; }
.kb-select-item.disabled:hover { background: transparent; }

/* ─────────────────────────────────────────────────────────────────────────
   18. KBTable chrome (table.js) — toolbar, footer, pager, grid polish
   ───────────────────────────────────────────────────────────────────────── */
.kb-table-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.kb-table-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.kb-table-info { color: var(--muted); font-size: .82rem; }
.kb-table-footer-right { display: flex; align-items: center; gap: 10px; }
.kb-pagesize { width: auto; padding-top: 6px; padding-bottom: 6px; font-size: .82rem; }
.kb-empty { text-align: center; color: var(--muted); padding: 22px 0; }

.kb-pager ul { display: flex; list-style: none; margin: 0; padding: 0; gap: 4px; }
.kb-page a {
  display: inline-flex;
  min-width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .85rem;
  text-decoration: none;
}
.kb-page a:hover { background: var(--surface-2); text-decoration: none; }
.kb-page.active a { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.kb-page.disabled a { opacity: .45; pointer-events: none; }

/* Server-rendered result tables (kitchen) share the grid look. */
#search-results table { width: 100%; border-collapse: collapse; font-size: .9rem; }
#search-results table thead th {
  text-align: left; padding: 11px 12px; border-bottom: 2px solid var(--border);
  color: var(--muted); font-family: var(--font-head); font-weight: 600;
  font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
}
#search-results table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
#search-results table tbody tr:hover { background: var(--surface-2); }

/* Multi-center cell on /admin/users: clip long lists to one line (tooltip has full). */
.kb-centers-cell {
  display: inline-block;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  cursor: help;
}

.nowrap { white-space: nowrap; }
.cursor-pointer { cursor: pointer; }

/* ─────────────────────────────────────────────────────────────────────────
   19. Attendance — menu buttons + calendar wrapper
   ───────────────────────────────────────────────────────────────────────── */
/* Attendance-entry count grid: each meal type is a row of equal-width age-group
   inputs, three across (Soy Milk spans the full width). */
.attendance-groups { display: flex; flex-direction: column; gap: 14px; }
.meal-group > .form-label { display: block; margin-bottom: 6px; }
.attendance-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.attendance-grid .search-box { max-width: none; width: 100%; }
.attendance-grid .soy-cell { grid-column: 1 / -1; }

.calendar-wrapper { min-height: 200px; overflow-x: auto; }
.calendar-wrapper .fc { min-width: 640px; }
.calendar-wrapper-disabled {
  opacity: .5 !important;
  user-select: none !important;
  cursor: not-allowed !important;
}
.attendance-menu-button {
  cursor: pointer;
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 15%, var(--surface));
  color: var(--primary-strong);
  font-weight: 600;
  font-size: .8rem;
  margin: 4px 4px 2px;
  text-align: center;
  transition: background-color .15s ease;
}
.attendance-menu-button:hover { background: color-mix(in srgb, var(--primary) 26%, var(--surface)); }

/* ─────────────────────────────────────────────────────────────────────────
   20. FullCalendar v6 — themed to the portal
   ───────────────────────────────────────────────────────────────────────── */
.fc .fc-col-header-cell { background: var(--surface-2); padding: .4rem 0; }
.fc .fc-col-header-cell-cushion { color: var(--primary-strong); font-weight: 600; text-decoration: none; cursor: default; }
.fc .fc-scrollgrid,
.fc .fc-scrollgrid td,
.fc .fc-scrollgrid th { border-color: var(--border); }
.fc .fc-daygrid-day-number { color: var(--muted); text-decoration: none; padding: 4px 6px; font-size: .85rem; }
.fc .fc-day-today { background: var(--primary-soft) !important; }
.fc .fc-daygrid-day-frame { padding: 2px 4px 4px; }
/* The whole day cell is clickable (opens attendance entry) — show a pointer. */
.fc .fc-daygrid-day { cursor: pointer; }
.fc-event:not(.attendance-menu-button), .fc-event-dot { background-color: transparent; }
.fc-event { position: relative; display: block; font-size: .85em; line-height: 1.3; border-radius: 3px; border: none; }
.fc-daygrid-event, .fc-daygrid-event .fc-event-main { white-space: normal; }
.fc-event-title,
.fc-daygrid-event .fc-event-title {
  white-space: pre-line;
  line-height: 1.25;
  padding: 2px 4px;
  font-size: .78rem;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.fc-daygrid-day-events { min-height: 2em; }
.fc-daygrid-block-event { white-space: normal; }
.fc .fc-button-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.fc .fc-button-primary:hover,
.fc .fc-button-primary:focus,
.fc .fc-button-primary:not(:disabled):active,
.fc .fc-button-primary:not(:disabled).fc-button-active {
  background-color: var(--primary-strong);
  border-color: var(--primary-strong);
  box-shadow: none;
}
.fc .fc-toolbar-title { font-size: 1.25rem; color: var(--ink); }

/* ─────────────────────────────────────────────────────────────────────────
   21. Kitchen prep sheets
   ───────────────────────────────────────────────────────────────────────── */
.prep-sheet-header, .prep-sheet-item-header { margin-top: 0; margin-bottom: 10px; }
.prep-sheet-label { font-size: 1rem; }
@media only screen and (max-width: 960px) {
  .prep-sheet-user-action-container { margin-bottom: 15px; }
}
