/**
 * DIDO Fermentation Lab — Fluid Responsive Stylesheet (320px -> Ultrawide 1600px+)
 * Mobile-first (100% width + 100dvh) -> Tablet 2-col -> Desktop Auto-Sidebar + 2-col Run Card -> 3-4 col Dashboard.
 */

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Boot Loader */
.boot-loader {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.boot-badge {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  background: linear-gradient(135deg, #1b5233, #0d1b14);
  border: 2px solid var(--brand-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 1.5px;
  color: #f3f6f4;
  box-shadow: var(--shadow-card);
}

.boot-text {
  color: var(--text-secondary);
  font-size: 0.92rem;
}

/* ============================================================================
 * ADAPTIVE APP SHELL (Mobile Top+Bottom Nav -> Desktop Auto-Sidebar >= 1024px)
 * ============================================================================ */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Desktop Sidebar (hidden on < 1024px) */
.sidebar {
  display: none;
}

.shell-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-shield {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, #194d30, #0d1b14);
  border: 1.5px solid var(--brand-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #f3f6f4;
}

.brand-titles {
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.8px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  white-space: nowrap;
}

.status-pill.online {
  color: var(--brand-green);
  border-color: rgba(63, 158, 100, 0.4);
  background: var(--brand-green-soft);
}

.status-pill.offline {
  color: var(--warn-amber);
  border-color: rgba(242, 183, 5, 0.45);
  background: var(--warn-amber-soft);
}

.status-pill.demo {
  color: var(--ai-pink);
  border-color: rgba(244, 126, 176, 0.45);
  background: var(--ai-pink-soft);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.op-chip-top {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  min-height: 34px;
}

/* Banners */
.offline-banner {
  background: var(--warn-amber-soft);
  border-bottom: 1px solid rgba(242, 183, 5, 0.4);
  color: var(--warn-amber);
  padding: 9px var(--gutter);
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Main Content Area */
.main-content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--gutter);
  padding-bottom: calc(var(--nav-height) + 26px + env(safe-area-inset-bottom));
}

/* Mobile Bottom Nav (4 tabs) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.22);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  position: relative;
  transition: color 0.15s, background 0.15s;
}

.nav-btn .nav-ico {
  font-size: 1.25rem;
  line-height: 1;
}

.nav-btn.active {
  color: var(--brand-green);
  background: var(--brand-green-soft);
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: 16%;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--brand-green);
  color: var(--text-on-brand);
  font-size: 0.68rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-badge.warn {
  background: var(--warn-amber);
  color: #111;
}

/* ============================================================================
 * COMMON COMPONENTS: CARDS, BUTTONS, INPUTS, GRIDS, PILLS
 * ============================================================================ */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  letter-spacing: 0.5px;
  line-height: 1.15;
}

.page-sub {
  margin: 3px 0 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(14px, 1.8vw, 20px);
  box-shadow: var(--shadow-card);
}

.card-elevated {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(12px, 1.5vw, 18px);
}

/* Responsive Adaptive Grids */
.grid-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(12px, 1.6vw, 18px);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

/* Buttons (>= 48x48 px touch target for primary workshop controls) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.94rem;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  text-align: center;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-lg {
  min-height: 54px;
  padding: 12px 20px;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

.btn-sm {
  min-height: 40px;
  padding: 7px 12px;
  font-size: 0.84rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--brand-green);
  color: var(--text-on-brand);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-green-hover);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--brand-green);
}

.btn-ai {
  background: var(--ai-pink-soft);
  border: 1.5px solid var(--ai-pink);
  color: var(--ai-pink);
}
.btn-ai:hover:not(:disabled) {
  background: var(--ai-pink);
  color: #190711;
}

.btn-warn {
  background: var(--warn-amber-soft);
  border: 1.5px solid var(--warn-amber);
  color: var(--warn-amber);
}
.btn-warn:hover:not(:disabled) {
  background: var(--warn-amber);
  color: #141002;
}

.btn-danger {
  background: var(--danger-red-soft);
  border: 1.5px solid var(--danger-red);
  color: var(--danger-red);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-red);
  color: #fff;
}

.btn-ghost {
  color: var(--text-secondary);
  background: transparent;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

/* Form Controls */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.textarea {
  min-height: 82px;
  resize: vertical;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand-green);
}

.field-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.field-error {
  font-size: 0.78rem;
  color: var(--danger-red);
  font-weight: 600;
}

/* Chips / Pills */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 42px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.14s;
}

.chip.selected {
  background: var(--brand-green);
  border-color: var(--brand-green);
  color: var(--text-on-brand);
}

/* Tare Accent Badges & Borders */
.tare-card {
  position: relative;
  overflow: hidden;
  border-left: 5px solid var(--tare-color, var(--brand-green));
}

.tare-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--tare-color, var(--brand-green));
  background: var(--tare-soft, var(--brand-green-soft));
  border: 1px solid color-mix(in srgb, var(--tare-color, var(--brand-green)) 40%, transparent);
}

.tare-ico {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tare-ico-lg {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ============================================================================
 * AUTH SCREEN (PIN + Operator Select)
 * ============================================================================ */

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 30px);
  box-shadow: var(--shadow-float);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 20px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 14px 0 18px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
  transition: all 0.15s;
}

.pin-dot.filled {
  background: var(--brand-green);
  border-color: var(--brand-green);
  transform: scale(1.1);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.pin-key {
  min-height: 54px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-key:active {
  background: var(--brand-green-soft);
  border-color: var(--brand-green);
}

.shake {
  animation: dido-shake 0.35s ease;
}

@keyframes dido-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ============================================================================
 * SHOP BOARD, WIZARD, LIVE RUN CARD, FINISH VIEW
 * ============================================================================ */

.run-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}

.run-tile:hover {
  border-color: var(--tare-color, var(--brand-green));
  transform: translateY(-2px);
}

.run-tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.run-drink {
  font-size: clamp(1.08rem, 1.5vw, 1.28rem);
  font-weight: 800;
  margin: 0;
}

.run-meta {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.run-timer-sm {
  font-family: var(--font-display);
  font-size: 1.45rem;
  letter-spacing: 1px;
  color: var(--brand-green);
}

.run-timer-sm.paused {
  color: var(--warn-amber);
}

/* Wizard Tiles */
.tare-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.tare-tile-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  text-align: left;
  min-height: 126px;
  transition: all 0.15s;
}

.tare-tile-btn:hover, .tare-tile-btn.selected {
  border-color: var(--tare-color, var(--brand-green));
  background: var(--tare-soft, var(--brand-green-soft));
}

.ckt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.ckt-btn {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 82px;
}

.ckt-btn.selected {
  border-color: var(--brand-green);
  background: var(--brand-green-soft);
}

.drink-suggestions {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  margin-top: 6px;
}

.drink-opt {
  width: 100%;
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drink-opt:last-child { border-bottom: none; }
.drink-opt:hover, .drink-opt.selected {
  background: var(--brand-green-soft);
  color: var(--brand-green);
  font-weight: 700;
}

/* Live Run Card (1-col Mobile -> 2-col Desktop >= 1024px) */
.run-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(14px, 2vw, 22px);
  align-items: start;
}

.stage-stepper {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  margin: 14px 0;
}

.stage-step {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stage-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--border-subtle);
}

.stage-step.done .stage-bar { background: var(--brand-green); }
.stage-step.current .stage-bar { background: var(--tare-color, var(--brand-green)); box-shadow: 0 0 10px var(--tare-color, var(--brand-green)); }

.stage-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.stage-step.current .stage-label { color: var(--text-primary); font-weight: 700; }
.stage-step.done .stage-label { color: var(--brand-green); }

.timer-box {
  background: var(--bg-input);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(14px, 2vw, 22px);
  text-align: center;
  margin: 12px 0;
}

.timer-box.paused {
  border-color: var(--warn-amber);
  background: var(--warn-amber-soft);
}

.timer-stage-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

.timer-digits {
  font-family: var(--font-display);
  font-size: var(--timer-size);
  font-weight: 700;
  letter-spacing: 2px;
  line-height: 1.1;
  margin-top: 4px;
}

/* Crew Stepper */
.crew-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
}

.stepper-ctrl {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stepper-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  font-size: 1.4rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stepper-val {
  min-width: 34px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
}

/* Timeline / Key-Value rows */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.88rem;
  padding-bottom: 7px;
  border-bottom: 1px dashed var(--border-subtle);
}

.kv-row:last-child { border-bottom: none; padding-bottom: 0; }
.kv-key { color: var(--text-secondary); }
.kv-val { font-weight: 700; text-align: right; }

/* KPI Mini Cards */
.kpi-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  font-weight: 700;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.6rem);
  font-weight: 700;
  line-height: 1.1;
}

.kpi-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Alert Boxes */
.alert-box {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alert-warn {
  background: var(--warn-amber-soft);
  border: 1px solid rgba(242, 183, 5, 0.45);
  color: var(--warn-amber);
}

.alert-danger {
  background: var(--danger-red-soft);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: var(--danger-red);
}

.alert-ai {
  background: var(--ai-pink-soft);
  border: 1px solid rgba(244, 126, 176, 0.45);
  color: var(--text-primary);
}

/* Empty / Error / Skeleton States */
.state-panel {
  text-align: center;
  padding: clamp(28px, 5vw, 52px) 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.state-emoji {
  font-size: 2.6rem;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: skel 1.2s infinite;
  border-radius: var(--radius-md);
  height: 138px;
}

@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================================
 * MODALS & BOTTOM SHEETS (Bottom Sheet on Mobile -> Centered Modal on Tablet/PC)
 * ============================================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal-sheet {
  width: 100%;
  max-height: 92dvh;
  background: var(--bg-surface);
  border-top: 1.5px solid var(--border-strong);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-float);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.modal-close {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Tabs inside Manual Editor */
.subtabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.subtab-btn {
  min-height: 40px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.subtab-btn.active {
  background: var(--brand-green);
  border-color: var(--brand-green);
  color: var(--text-on-brand);
}

/* Diff Preview inside AI Modal */
.diff-card {
  border: 1.5px solid var(--ai-pink);
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.diff-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.86rem;
  border-bottom: 1px dashed var(--border-subtle);
  padding-bottom: 6px;
}
.diff-row:last-child { border-bottom: none; padding-bottom: 0; }
.diff-old { color: var(--text-muted); text-decoration: line-through; }
.diff-new { color: var(--brand-green); font-weight: 800; }
.diff-del { color: var(--danger-red); font-weight: 800; }

/* AI Chat Row */
.ai-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.mic-btn {
  width: 48px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1.5px solid var(--border-strong);
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mic-btn.recording {
  border-color: var(--danger-red);
  background: var(--danger-red-soft);
  animation: pulse-rec 1s infinite;
}

@keyframes pulse-rec {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Toast + 8s Undo */
.toast-root {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-height) + 14px + env(safe-area-inset-bottom));
  z-index: 80;
  width: min(94vw, 480px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-surface-elevated);
  border: 1.5px solid var(--brand-green);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-float);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
}

.toast.warn { border-color: var(--warn-amber); }
.toast.error { border-color: var(--danger-red); }

.toast-undo-btn {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--brand-green);
  color: var(--text-on-brand);
  font-weight: 800;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Dashboard Bars */
.bar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  font-weight: 600;
}

.bar-track {
  height: 10px;
  border-radius: 99px;
  background: var(--bg-input);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--brand-green);
}

/* ============================================================================
 * FLUID RESPONSIVE BREAKPOINTS (320px -> Tablet -> Laptop -> Full HD / Ultrawide)
 * ============================================================================ */

.brand-short {
  display: none;
}

@media (max-width: 440px) {
  .brand-full { display: none; }
  .brand-short { display: inline; }
}

/* 1. Compact Smartphones (< 380px) */
@media (max-width: 379px) {
  .brand-sub { display: none; }
  .op-chip-top { padding: 4px 8px; font-size: 0.72rem; }
  .subtabs { grid-template-columns: repeat(2, 1fr); }
  .nav-btn { font-size: 0.66rem; }
}

/* 2. Landscape Smartphones (compact vertical layout) */
@media (max-height: 520px) and (orientation: landscape) {
  .timer-box { padding: 10px; }
  .timer-digits { font-size: 2rem; }
  .auth-card { max-width: 680px; }
  .pin-pad { grid-template-columns: repeat(6, 1fr); }
}

/* 3. Tablets (640px - 1023px) */
@media (min-width: 640px) {
  .grid-cards {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }

  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .modal-sheet {
    max-width: 640px;
    max-height: 88dvh;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-lg);
  }
}

/* 4. Laptops & Desktops (>= 1024px): Auto Left Sidebar + 2-Column Live Run Card */
@media (min-width: 1024px) {
  .app-shell {
    flex-direction: row;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100dvh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: 18px 14px;
    gap: 18px;
    z-index: 35;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
  }

  .sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.94rem;
    text-align: left;
    transition: all 0.14s;
  }

  .sidebar-btn:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
  }

  .sidebar-btn.active {
    background: var(--brand-green-soft);
    color: var(--brand-green);
    border: 1px solid rgba(63, 158, 100, 0.35);
  }

  .sidebar-btn-left {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .sidebar-pill {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    background: var(--brand-green);
    color: var(--text-on-brand);
    font-size: 0.74rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-footer {
    border-top: 1px solid var(--border-subtle);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .topbar .brand-group {
    display: none;
  }

  .bottom-nav {
    display: none;
  }

  .main-content {
    padding-bottom: 36px;
  }

  .toast-root {
    bottom: 24px;
    left: calc(50% + var(--sidebar-width) / 2);
  }

  .run-layout {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  }

  .finish-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: 20px;
    align-items: start;
  }

  .dash-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }
}

/* 5. Large Monitors Full HD / 2K / Ultrawide (>= 1440px) */
@media (min-width: 1440px) {
  .grid-cards {
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  }

  .grid-kpi {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}
