/* Global Theme Design System & Tokens */
:root {
  /* Tell the browser which way round the page is, so the controls it draws itself —
     the calendar button inside a date field, the picker panel, select popups,
     scrollbars — come back readable instead of dark-on-dark. */
  color-scheme: dark;

  /* Colors - Vibrant, Harmonious HSL */
  --bg-primary: hsl(222, 47%, 7%);
  --bg-surface: hsla(222, 47%, 12%, 0.7);
  --bg-surface-hover: hsla(222, 47%, 18%, 0.85);
  --border-color: hsla(217, 30%, 25%, 0.6);
  --border-color-glow: hsla(250, 84%, 60%, 0.3);

  --text-primary: hsl(210, 40%, 98%);
  --text-secondary: hsl(215, 20%, 75%);
  --text-muted: hsl(215, 15%, 55%);

  --color-primary: hsl(250, 84%, 58%);
  --color-primary-hover: hsl(250, 84%, 65%);
  --color-primary-active: hsl(250, 84%, 50%);
  --color-primary-glow: hsla(250, 84%, 58%, 0.25);

  --color-secondary: hsl(190, 90%, 45%);
  --color-secondary-hover: hsl(190, 90%, 55%);

  --color-success: hsl(145, 80%, 40%);
  --color-success-bg: hsla(145, 80%, 40%, 0.15);
  --color-warning: hsl(38, 95%, 55%);
  --color-warning-bg: hsla(38, 95%, 55%, 0.15);
  --color-danger: hsl(355, 85%, 55%);
  --color-danger-bg: hsla(355, 85%, 55%, 0.15);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.75rem;

  /* Accessibility & Usability (Gate ACC-01 & UX-02) */
  --min-tap-target: 44px;
  --focus-ring: 2px solid hsl(190, 90%, 50%);
  --focus-ring-offset: 2px;

  /* Premium Effects */
  --blur-amount: 12px;
  --border-radius-sm: 8px;
  --border-radius-md: 16px;
  --border-radius-lg: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Mode Variables Override (English/Spanish Friendly) */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg-primary: hsl(210, 30%, 96%);
    --bg-surface: hsla(0, 0%, 100%, 0.8);
    --bg-surface-hover: hsla(0, 0%, 100%, 0.95);
    --border-color: hsla(210, 18%, 80%, 0.7);
    --border-color-glow: hsla(250, 84%, 58%, 0.15);

    --text-primary: hsl(222, 47%, 12%);
    --text-secondary: hsl(222, 15%, 35%);
    --text-muted: hsl(222, 10%, 55%);

    --color-primary-glow: hsla(250, 84%, 58%, 0.15);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 12px 32px rgba(222, 47%, 12%, 0.08);
  }
}

/* Global resets for usability */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Standard accessibility support */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

button, a, input, select {
  font-family: inherit;
  font-size: inherit;
}

/* Interactive elements min touch targets */
button, select, input[type="number"], .tap-target {
  min-width: var(--min-tap-target);
  min-height: var(--min-tap-target);
}

/* Glassmorphism card utilities */
.glass-panel {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--blur-amount));
  -webkit-backdrop-filter: blur(var(--blur-amount));
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--spacing-lg);
  transition: var(--transition-smooth);
}

.glass-panel:hover {
  border-color: var(--border-color-glow);
  box-shadow: var(--shadow-lg);
}

/* Primary Button Design */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 0 1.25rem;
  border-radius: var(--border-radius-sm);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
  user-select: none;
}

.btn-primary {
  background: var(--color-primary);
  /* The ink is MEASURED against this exact background server-side (readableInkFor
     in services/identity/branding.mjs picks whichever of dark/light wins on
     contrast ratio). Hardcoding white here threw that away, and a restaurant with
     a light brand colour got white-on-cream buttons that were invisible until you
     happened to click one. The fallback is only for a tenant with no colour set. */
  color: var(--color-on-primary, hsl(0, 0%, 100%));
  box-shadow: 0 4px 12px var(--color-primary-glow);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  background: var(--color-primary-active);
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

/* Dialog & Backdrop Styles with baseline fallback compatibility */
dialog {
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  padding: var(--spacing-xl);
  max-width: 500px;
  width: 90%;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

dialog::backdrop {
  background: rgba(7, 10, 15, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Responsive Grid / Flex utilities */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-lg);
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Supplier Price Comparison & Splitting (T-0006) */
.supplier-compare-title {
  font-size: var(--font-size-xs) !important;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--spacing-xs);
  letter-spacing: 0.5px;
}

.supplier-compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.supplier-option {
  border: 1px solid var(--border-color);
  padding: var(--spacing-sm);
  border-radius: var(--border-radius-sm);
  background: var(--bg-primary);
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  position: relative;
}

.supplier-option:hover {
  border-color: var(--text-secondary);
  background: var(--bg-surface-hover);
}

.supplier-option.selected {
  border-color: var(--color-secondary);
  box-shadow: 0 0 8px var(--border-color-glow);
  background: var(--bg-surface);
}

.supplier-option.cheapest {
  border-left: 3px solid var(--color-success);
}

.supplier-option-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.supplier-option-price {
  font-size: var(--font-size-md);
  font-weight: 800;
  color: var(--color-secondary);
}

.cheapest-badge {
  font-size: 9px;
  padding: 1px 4px;
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 800;
}

/* Audit Log Trail (T-0006) */
.audit-card {
  margin-top: var(--spacing-lg);
  border-top: 2px solid var(--border-color);
  padding-top: var(--spacing-lg);
}

.audit-log-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  max-height: 160px;
  overflow-y: auto;
  padding-right: var(--spacing-xs);
}

.audit-log-item {
  font-size: var(--font-size-xs);
  border: 1px solid var(--border-color);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius-sm);
  background: var(--bg-surface-hover);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-md);
}

.audit-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.audit-meta-time {
  color: var(--text-muted);
  font-size: 10px;
}

.audit-total {
  font-weight: 800;
  color: var(--color-secondary);
  font-size: var(--font-size-sm);
}

/* Walk-In Freezer Mode (High-contrast, Large Touch Targets >=48px for kitchen gloves) */
body.freezer-mode {
  color-scheme: dark;
  /* High contrast BOH color tokens */
  --bg-primary: #000000;
  --bg-surface: #111111;
  --bg-surface-hover: #222222;
  --border-color: #ffff00; /* High contrast yellow border */
  --border-color-glow: #39ff14; /* Neon green glow border */

  --text-primary: #ffffff;
  --text-secondary: #ffff00;
  --text-muted: #aaaaaa;

  --color-primary: #ffff00; /* High contrast yellow buttons */
  --color-primary-hover: #e6e600;
  --color-primary-active: #cccc00;
  --color-primary-glow: rgba(255, 255, 0, 0.4);
  /* Black on yellow, ~19:1 — the classic high-visibility pairing, and the whole
     point of this theme. Without it the fallback ink is white, which on yellow is
     1.07:1: the worst contrast in the app, in the mode built for a dark freezer. */
  --color-on-primary: #000000;

  --color-secondary: #39ff14; /* Neon green accents */
  --color-secondary-hover: #32cd32;

  --color-success: #39ff14;
  --color-success-bg: rgba(57, 255, 20, 0.2);
  --color-warning: #ffff00;
  --color-warning-bg: rgba(255, 255, 0, 0.2);
  --color-danger: #ff073a; /* Neon red */
  --color-danger-bg: rgba(255, 7, 58, 0.2);

  /* Larger touch targets & text for freezer visibility */
  --font-size-xs: 0.95rem;
  --font-size-sm: 1.1rem;
  --font-size-md: 1.25rem;
  --font-size-lg: 1.5rem;
  --font-size-xl: 2rem;
  --min-tap-target: 48px;
}

body.freezer-mode .btn-secondary {
  border-color: #ffff00;
  color: #ffff00;
}

body.freezer-mode .btn-secondary:hover {
  background: #222222;
  border-color: #39ff14;
  color: #39ff14;
}

body.freezer-mode .connection-badge.online {
  border-color: #39ff14;
  color: #39ff14;
}



/* ── Sidebar shell (T-0060 / T-0063) ────────────────────────────────────────
   A real left rail: pinned to the very edge of the window, running the FULL
   height, with the signed-in person at the bottom of it. Everything else on the
   page is pushed clear of it, so the whole right-hand side is free for work.

   On a phone the rail becomes a scrolling strip across the top — the floor uses
   this one-handed, and a hidden drawer costs a tap they do not have. */
:root { --rail-width: 232px; }

.app-shell { display: block; }
.app-main { min-width: 0; }   /* lets wide tables scroll rather than stretch */

@media (min-width: 901px) {
  body { padding-left: var(--rail-width); }

  .app-shell > .tab-navigation {
    position: fixed;
    inset: 0 auto 0 0;                 /* top:0 right:auto bottom:0 left:0 */
    width: var(--rail-width);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: var(--spacing-md);
    overflow-y: auto;
    border: 0;
    border-right: 1px solid var(--border-color);
    border-radius: 0;
  }
  .app-shell > .tab-navigation .btn { width: 100%; text-align: left; }
}

@media (max-width: 900px) {
  .app-shell > .tab-navigation {
    position: static;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: var(--spacing-sm);
    overflow-x: auto;
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
  }
  .app-shell > .tab-navigation .btn { width: auto; white-space: nowrap; }
}

/* ── User menu ─────────────────────────────────────────────────────────────── */
.user-menu-wrap { position: relative; }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  z-index: 60;
  background: var(--bg-surface, var(--bg-primary));
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
  padding: 6px;
}
.user-menu-head { padding: 8px 10px; border-bottom: 1px solid var(--border-color); margin-bottom: 4px; }
.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--border-radius-sm);
  background: none;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}
.user-menu-item:hover, .user-menu-item:focus-visible { background: var(--bg-surface-hover); }

/* ── Permissions grid ──────────────────────────────────────────────────────── */
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-color); }
.perm-table th.role-col, .perm-table td.role-col { text-align: center; width: 92px; }
.perm-table tbody tr:hover { background: var(--bg-surface-hover); }
.perm-group th { background: var(--bg-surface-hover); font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: .04em; }
.perm-table input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.perm-table input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .55; }

/* ── Restaurant logo (T-0061) ───────────────────────────────────────────────
   Many restaurant logos are white artwork made for a dark menu or storefront.
   Sitting one on a light header would show nothing at all, so the logo always
   gets its own dark plate — correct for white marks, harmless for dark ones. */
.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  margin-right: var(--spacing-sm);
  border-radius: var(--border-radius-sm);
  background: #130f0c;
}
.brand-logo-img { display: block; height: 34px; width: auto; max-width: 180px; }


/* ── Header alignment (T-0062) ──────────────────────────────────────────────
   Logo, restaurant name and the signed-in person were colliding because they
   were three siblings in one flex row. The name and person now share a text
   column, so they read as one block and never touch. */
.brand { display: flex; align-items: center; gap: var(--spacing-sm); min-width: 0; }
.brand-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.brand-text h1 { margin: 0; line-height: 1.15; }
.brand-text .tagline { margin: 2px 0 0; line-height: 1.2; }

/* ── The signed-in person, at the foot of the sidebar ───────────────────────
   Same shape as an editor or a chat app: your name sits at the bottom-left and
   the menu opens upward. It is the last thing in the nav column, pushed down by
   margin-top:auto so it stays pinned no matter how many modules are switched on. */
.sidebar-user { margin-top: auto; padding-top: var(--spacing-sm); border-top: 1px solid var(--border-color); }
.sidebar-user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--border-radius-sm);
  background: none;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.sidebar-user-btn:hover, .sidebar-user-btn:focus-visible { background: var(--bg-surface-hover); border-color: var(--border-color); }
.sidebar-user-avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary, #fff);
  font-weight: 800; font-size: var(--font-size-sm);
  text-transform: uppercase;
}
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar-user-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: var(--font-size-xs); color: var(--text-secondary); text-transform: capitalize; }
.sidebar-user-caret { color: var(--text-secondary); font-size: var(--font-size-xs); }
/* opens UPWARD from the foot of the sidebar */
.sidebar-user .user-menu { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; min-width: 100%; }

@media (max-width: 900px) {
  /* On a phone the nav is a horizontal strip, so the person goes back inline. */
  .sidebar-user { margin-top: 0; padding-top: 0; border-top: 0; }
  .sidebar-user-btn { width: auto; white-space: nowrap; }
  .sidebar-user .user-menu { bottom: auto; top: calc(100% + 6px); min-width: 220px; }
}

/* ── Password field with a reveal eye (T-0064) ──────────────────────────────
   Anyone choosing a password should be able to SEE what they typed — on a phone
   keyboard, blind double-entry is how people lock themselves out on day one. */
.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 44px !important; }
.password-eye {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  min-width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--border-radius-sm);
  background: none; cursor: pointer;
  font-size: 16px; line-height: 1; opacity: .65;
}
.password-eye:hover, .password-eye:focus-visible { opacity: 1; background: var(--bg-surface-hover); }
.password-eye[aria-pressed="true"] { opacity: 1; }

/* A destructive confirm reads as destructive: the safe choice is the plain one. */
.btn-danger { background: var(--color-danger, #dc2626); color: #fff; border-color: transparent; }
.btn-danger:hover { filter: brightness(1.08); }
#confirm-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
