/* Heading Setup Assistant (HSA) — Global Styles
 * Ported from the CherryMax Rework Agent design system for a consistent
 * PCC setup-app UI family, with HSA additions (numeric keypad, coach chat,
 * parameter rows, citation chips). Touch-first per .kiro/steering/ui-standards.md:
 * body text >= 18px, touch targets >= 48px (64px preferred), works at 1024x768. */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
    --bg: #f0f4f8;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --sidebar-from: #0f1a2e;
    --sidebar-to: #1a2744;
    --accent: #2563eb;
    --accent-to: #1d4ed8;
    --border: #e2e8f0;
    --border-faint: #eef1f5;
    --card-bg: #ffffff;
    --radius: 12px;
    --radius-lg: 16px;
    /* Status palette (shared with CherryMax) */
    --st-active: #2563eb;
    --st-paused: #d97706;
    --st-completed: #16a34a;
    --st-hold: #7c3aed;
    --st-engineering: #c2410c;
    --st-mrb: #dc2626;
    /* Touch sizing (gloves + noise, shop floor) */
    --tap-min: 48px;
    --tap-pref: 64px;
    --body-size: 18px;
}

[x-cloak] { display: none !important; }
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    font-size: var(--body-size);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ── Login / Idle ──────────────────────────────────────────────────────── */
.login-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem;
    background: linear-gradient(135deg, var(--sidebar-from), var(--sidebar-to));
}
.login-card {
    background: #fff; border-radius: var(--radius-lg); padding: 2.5rem; width: 420px;
    max-width: 100%; box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand .brand-logo {
    width: 72px; height: 72px; margin: 0 auto 1rem; background: #fff; border-radius: 18px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); border: 1px solid var(--border-faint);
}
.login-brand .brand-logo svg { width: 42px; height: 42px; color: var(--accent); }
.login-brand h1 { font-size: 1.6rem; font-weight: 800; color: #0f172a; }
.login-brand p { font-size: 0.95rem; color: var(--text-muted); }

/* Mode switch: operator badge vs lead/engineer sign-in */
.login-mode-switch { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.login-mode-switch button {
    flex: 1; padding: 0.75rem; border: 1px solid var(--border); background: #f8fafc;
    border-radius: 10px; font-size: 0.95rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; min-height: var(--tap-min); font-family: inherit;
}
.login-mode-switch button.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-to));
    color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

/* ── App Shell ─────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 240px; background: linear-gradient(180deg, var(--sidebar-from), var(--sidebar-to));
    color: #fff; display: flex; flex-direction: column; position: fixed;
    top: 0; left: 0; bottom: 0; z-index: 100; box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.sidebar-brand {
    padding: 1.5rem 1.25rem; display: flex; align-items: center; gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .brand-logo {
    width: 44px; height: 44px; flex: none; background: #fff; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.sidebar-brand .brand-logo svg { width: 26px; height: 26px; color: var(--accent); }
.sidebar-brand .brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 0.95rem; line-height: 1.2; }
.sidebar-brand .brand-subtitle { font-size: 0.72rem; opacity: 0.6; margin-top: 0.15rem; }
.sidebar-nav { flex: 1; padding: 1.25rem 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; overflow-y: auto; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 0.85rem; padding: 1rem;
    color: rgba(255,255,255,0.6); text-decoration: none; border-radius: 10px;
    font-size: 1rem; font-weight: 500; transition: all 0.2s; min-height: var(--tap-min);
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }
.sidebar-nav a.active { background: linear-gradient(135deg, var(--accent), var(--accent-to)); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,0.3); font-weight: 600; }
.sidebar-nav .nav-icon { width: 24px; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-nav .nav-icon svg { width: 22px; height: 22px; display: block; }
.sidebar-footer { padding: 1.25rem; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.8rem; }
.sidebar-footer .status-dot { display: inline-block; width: 9px; height: 9px; background: var(--st-completed); border-radius: 50%; margin-right: 0.5rem; }
.sidebar-footer .status-dot.offline { background: #ef4444; animation: pulse-red 2s infinite; }
.sidebar-footer .status-text { opacity: 0.7; }
.sidebar-footer .version { opacity: 0.4; margin-top: 0.3rem; }
@keyframes pulse-red { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Main */
.main-wrapper { margin-left: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.top-header {
    background: #fff; border-bottom: 1px solid var(--border); padding: 1rem 2rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 3px rgba(0,0,0,0.04); flex-wrap: wrap;
}
.top-header .page-title-area { display: flex; align-items: center; gap: 0.85rem; }
.top-header .page-icon {
    width: 42px; height: 42px; border-radius: 10px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: #eff6ff; color: var(--accent);
}
.top-header .page-icon svg { width: 22px; height: 22px; display: block; }
.top-header .page-title { font-size: 1.3rem; font-weight: 700; color: #0f172a; }
.top-header .page-subtitle { font-size: 0.85rem; color: var(--text-muted); }

/* Header session context strip (job/item/qty/material/machine/badge/phase) */
.session-strip { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.session-strip .strip-item { display: flex; flex-direction: column; }
.session-strip .strip-label { font-size: 0.68rem; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.session-strip .strip-value { font-size: 0.95rem; font-weight: 700; color: #0f172a; }

.top-header .user-area { display: flex; align-items: center; gap: 1rem; position: relative; }
.top-header .user-badge-chip {
    display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.85rem;
    background: #eff6ff; color: var(--accent-to); border-radius: 10px; font-weight: 700; font-size: 0.9rem;
}
.end-session-btn {
    padding: 0.7rem 1.25rem; border-radius: 10px; font-weight: 700; font-size: 0.9rem;
    background: #fef2f2; color: var(--st-mrb); border: 1px solid #fecaca; cursor: pointer;
    min-height: var(--tap-min); display: inline-flex; align-items: center; gap: 0.4rem;
}
.end-session-btn:hover { background: #fee2e2; }

.page-content { flex: 1; padding: 2rem; }

/* ── Flash ─────────────────────────────────────────────────────────────── */
.flash-messages { padding: 0 2rem; margin-top: 0.75rem; }
.flash-msg { padding: 0.9rem 1.25rem; border-radius: 8px; margin-bottom: 0.5rem; font-size: 0.95rem; font-weight: 500; }
.flash-msg.info { background: #eff6ff; color: var(--accent-to); border: 1px solid #bfdbfe; }
.flash-msg.error { background: #fef2f2; color: var(--st-mrb); border: 1px solid #fecaca; }
.flash-msg.success { background: #f0fdf4; color: var(--st-completed); border: 1px solid #bbf7d0; }
.flash-msg.warning { background: #fffbeb; color: var(--st-paused); border: 1px solid #fde68a; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    padding: 0.75rem 1.25rem; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; border: none; text-decoration: none; display: inline-flex;
    align-items: center; justify-content: center; gap: 0.5rem; transition: all 0.2s;
    min-height: var(--tap-min); font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-to)); color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,0.25); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,99,235,0.35); }
.btn-dark { background: linear-gradient(135deg, #1a2332, #2d3748); color: #fff; box-shadow: 0 2px 8px rgba(26,35,50,0.2); }
.btn-dark:hover { transform: translateY(-1px); }
.btn-outline { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-outline:hover { background: #f9fafb; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label { display: block; margin-bottom: 0.35rem; font-weight: 600; color: #374151; font-size: 0.9rem; }
select, input[type="text"], input[type="number"], input[type="email"], input[type="password"], textarea {
    width: 100%; padding: 0.75rem 0.85rem; border: 1px solid var(--border); border-radius: 8px;
    font-size: 1rem; background: #fff; color: #1a202c; font-family: inherit; min-height: var(--tap-min);
}
textarea { min-height: 96px; resize: vertical; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.required-star { color: var(--st-mrb); font-weight: 700; }
.field-error { color: var(--st-mrb); font-size: 0.8rem; margin-top: 0.25rem; }
.field-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.25rem; }

/* ── Cards / panels ────────────────────────────────────────────────────── */
.card {
    background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04); border: 1px solid rgba(0,0,0,0.04);
}
.card-header {
    display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.05rem;
    margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid #f1f5f9;
}

/* Status summary cards */
.status-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.status-card {
    background: #fff; border-radius: 14px; padding: 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border-faint);
    cursor: pointer; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    min-height: 96px; min-width: 0;
}
.status-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.07); border-color: var(--border); }
.status-card .card-icon { width: 52px; height: 52px; border-radius: 13px; flex: none; display: flex; align-items: center; justify-content: center; }
.status-card .card-icon svg { width: 26px; height: 26px; display: block; }
.status-card .card-icon.active { background: #eff6ff; color: var(--st-active); }
.status-card .card-icon.paused { background: #fffbeb; color: var(--st-paused); }
.status-card .card-icon.completed { background: #f0fdf4; color: var(--st-completed); }
.status-card .card-info { display: flex; flex-direction: column; gap: 0.1rem; }
.status-card .card-title { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; white-space: nowrap; }
.status-card .card-value { font-size: 2.2rem; font-weight: 800; line-height: 1.1; }
.status-card .card-label { font-size: 0.78rem; color: var(--text-faint); white-space: nowrap; }

/* ── Search + table (jobs) ─────────────────────────────────────────────── */
.jobs-toolbar { display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.search-box {
    display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 220px; max-width: 600px;
    background: #fff; border: 1px solid #e6eaf0; border-radius: 10px; padding: 0.7rem 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s; min-height: var(--tap-min);
}
.search-box:focus-within { border-color: #c7d2e2; box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.search-box .search-icon { color: #9aa5b5; display: inline-flex; }
.search-box input { border: none; outline: none; background: transparent; font-size: 1rem; flex: 1; color: var(--text); min-height: auto; padding: 0; }
.search-box input::placeholder { color: #9aa5b5; }

.table-container { background: #fff; border-radius: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); overflow: hidden; border: 1px solid rgba(0,0,0,0.04); }
.data-table-full { width: 100%; border-collapse: collapse; }
.data-table-full th { text-align: left; padding: 0.95rem 1.4rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border-faint); background: #fafbfd; }
.data-table-full td { text-align: left; padding: 1.2rem 1.4rem; font-size: 0.95rem; color: #475569; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table-full tbody tr:last-child td { border-bottom: none; }
.data-table-full tr:hover { background: #f8fafc; }
.table-footer { padding: 0.9rem 1.4rem; font-size: 0.85rem; color: var(--text-muted); border-top: 1px solid #f1f5f9; }

.status-text { font-size: 0.92rem; font-weight: 600; }
.status-text.active { color: var(--st-active); }
.status-text.paused { color: var(--st-paused); }
.status-text.completed { color: var(--st-completed); }

/* Empty state */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.empty-state .empty-icon { margin-bottom: 1rem; color: #cbd5e1; display: flex; justify-content: center; }
.empty-state p { margin-bottom: 1.25rem; font-size: 1rem; }

/* ── Stepper (guided setup phases) ─────────────────────────────────────── */
.session-stepper {
    display: flex; align-items: center; justify-content: center; gap: 0; flex-wrap: wrap;
    margin-bottom: 1.5rem; padding: 1rem 1.5rem; background: #fff; border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04); border: 1px solid rgba(0,0,0,0.04);
}
.stepper-step { display: flex; align-items: center; gap: 0.5rem; position: relative; }
.stepper-circle {
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem; background: #f1f5f9; border: 2px solid var(--border); color: var(--text-faint);
    font-weight: 600; flex-shrink: 0; transition: all 0.3s;
}
.stepper-step.active .stepper-circle { background: linear-gradient(135deg, var(--accent), var(--accent-to)); border-color: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.stepper-step.completed .stepper-circle { background: var(--st-completed); border-color: var(--st-completed); color: #fff; }
.stepper-label { font-size: 0.78rem; font-weight: 600; color: var(--text-faint); white-space: nowrap; }
.stepper-step.active .stepper-label { color: var(--accent); }
.stepper-step.completed .stepper-label { color: var(--st-completed); }
.stepper-connector { width: 40px; height: 2px; background: var(--border); margin: 0 0.5rem; flex-shrink: 0; }
.stepper-step.completed .stepper-connector { background: var(--st-completed); }

/* Compact step indicator (shown below ~1280px instead of full rail) */
.step-indicator-compact { display: none; align-items: center; gap: 0.6rem; padding: 0.85rem 1.25rem; background: #fff; border-radius: 10px; margin-bottom: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,0.04); font-weight: 700; }
.step-indicator-compact .pill { font-size: 0.8rem; color: var(--text-muted); }

/* ── Three-panel session grid (left rail / center / right coach) ───────── */
.session-grid { display: grid; grid-template-columns: 240px 1fr 480px; gap: 1.25rem; align-items: start; }
.session-panel { background: #fff; border-radius: 12px; padding: 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.04); border: 1px solid rgba(0,0,0,0.04); }
.session-panel-header { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1rem; margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid #f1f5f9; }

/* Left rail: station/transfer progress tracker */
.progress-rail { display: flex; flex-direction: column; gap: 0.35rem; }
.rail-step {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem; border-radius: 10px;
    cursor: pointer; transition: all 0.15s; border: 1px solid transparent; min-height: var(--tap-min);
}
.rail-step:hover { background: #f8fafc; }
.rail-step.active { background: #eff6ff; border-color: #bfdbfe; }
.rail-step .rail-marker { width: 26px; height: 26px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; background: #f1f5f9; color: var(--text-faint); border: 2px solid var(--border); }
.rail-step.active .rail-marker { background: var(--accent); border-color: var(--accent); color: #fff; }
.rail-step.done .rail-marker { background: var(--st-completed); border-color: var(--st-completed); color: #fff; }
.rail-step .rail-label { font-size: 0.9rem; font-weight: 600; color: #374151; }
.rail-step .rail-sub { font-size: 0.75rem; color: var(--text-faint); }

/* Center: print / setup chart viewer */
.print-viewer { margin-top: 1rem; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #f8fafc; }
.print-viewer-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 0.85rem; background: #fff; border-bottom: 1px solid var(--border); }
.print-viewer-toolbar .zoom-btns { display: flex; gap: 0.4rem; }
.zoom-btn { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 1.1rem; font-weight: 700; color: #374151; }
.zoom-btn:hover { background: #f1f5f9; }
.print-canvas { padding: 1.5rem; text-align: center; color: var(--text-muted); overflow: auto; }

/* Parameter rows: Document value | Past setups (hidden Stage A) | Final value */
.param-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 1rem; align-items: center; padding: 1rem; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 0.75rem; background: #fafbfd; }
.param-name { font-weight: 700; color: #0f172a; font-size: 0.95rem; }
.param-unit { color: var(--text-faint); font-weight: 500; font-size: 0.85rem; }
.param-doc-value { font-size: 1.1rem; font-weight: 700; color: #0f172a; }
.param-history { background: #f5f3ff; border: 1px dashed #c4b5fd; border-radius: 8px; padding: 0.5rem 0.75rem; }
.param-history .ph-label { font-size: 0.68rem; font-weight: 700; color: var(--st-hold); text-transform: uppercase; }
.param-history .ph-value { font-size: 1rem; font-weight: 700; color: var(--st-hold); }
.param-final input { text-align: center; font-size: 1.15rem; font-weight: 700; font-family: 'SF Mono', 'Cascadia Code', monospace; }
.param-final.unset input { border-color: var(--st-paused); background: #fffbeb; }
@media (max-width: 760px) { .param-row { grid-template-columns: 1fr; } }

/* Source citation chip */
.source-chip {
    display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.65rem;
    background: #eff6ff; color: var(--accent-to); border: 1px solid #bfdbfe; border-radius: 999px;
    font-size: 0.78rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.source-chip:hover { background: #dbeafe; }
.source-chip svg { width: 14px; height: 14px; }

/* ── Coach chat (right panel) ──────────────────────────────────────────── */
.coach-panel { display: flex; flex-direction: column; max-height: calc(100vh - 11rem); position: sticky; top: 6rem; }
.coach-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.85rem; padding-right: 0.25rem; min-height: 200px; }
.coach-msg { max-width: 90%; padding: 0.85rem 1rem; border-radius: 12px; font-size: 0.95rem; line-height: 1.4; }
.coach-msg.coach { background: #f1f5f9; color: #1e293b; align-self: flex-start; border-bottom-left-radius: 4px; }
.coach-msg.operator { background: linear-gradient(135deg, var(--accent), var(--accent-to)); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.coach-msg .msg-citations { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.coach-input-row { display: flex; gap: 0.5rem; margin-top: 1rem; align-items: flex-end; }
.coach-input-row textarea { min-height: var(--tap-min); max-height: 120px; }
.mic-btn { width: var(--tap-min); height: var(--tap-min); flex: none; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--accent); }
.mic-btn:hover { background: #eff6ff; }
.mic-btn.recording { background: #fef2f2; color: var(--st-mrb); border-color: #fecaca; animation: pulse-red 1.5s infinite; }

/* Coach as slide-over drawer (narrow viewports) */
.coach-drawer-toggle { display: none; }
.coach-backdrop { display: none; }

/* ── AI loading spinner ────────────────────────────────────────────────── */
.ai-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1.5rem; text-align: center; }
.ai-loading-spinner { width: 48px; height: 48px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: ai-spin 1s linear infinite; margin-bottom: 1.25rem; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-loading-text { font-size: 1.05rem; font-weight: 700; color: #1e293b; margin-bottom: 0.5rem; }
.ai-loading-subtext { font-size: 0.9rem; color: var(--text-muted); max-width: 300px; line-height: 1.4; }

/* ── Numeric keypad (badge + parameter entry) ──────────────────────────── */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; max-width: 320px; margin: 0 auto; }
.keypad-key {
    min-height: var(--tap-pref); border-radius: 12px; border: 1px solid var(--border);
    background: #fff; font-size: 1.5rem; font-weight: 700; color: #0f172a; cursor: pointer;
    font-family: inherit; transition: all 0.12s; display: flex; align-items: center; justify-content: center;
}
.keypad-key:hover { background: #f1f5f9; }
.keypad-key:active { transform: scale(0.96); background: #e2e8f0; }
.keypad-key.wide { grid-column: span 1; }
.keypad-key.action { background: #eff6ff; color: var(--accent-to); }
.keypad-key.danger { background: #fef2f2; color: var(--st-mrb); }
.keypad-display {
    text-align: center; font-size: 2rem; font-weight: 800; letter-spacing: 0.35rem;
    padding: 1rem; margin-bottom: 1rem; border: 2px solid var(--border); border-radius: 12px;
    min-height: 72px; color: #0f172a; background: #f8fafc; font-family: 'SF Mono', 'Cascadia Code', monospace;
}

/* ── Failure-mode cards (troubleshoot) ─────────────────────────────────── */
.fm-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.75rem; }
.fm-card {
    display: flex; align-items: center; gap: 0.75rem; padding: 1rem; border: 2px solid var(--border);
    border-radius: 12px; cursor: pointer; transition: all 0.2s; background: #fafbfd; min-height: var(--tap-min);
}
.fm-card:hover { border-color: #cbd5e1; background: #fff; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.fm-card.selected { border-color: var(--accent); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.fm-card .fm-icon { flex: none; color: var(--text-muted); display: inline-flex; }
.fm-card.selected .fm-icon { color: var(--accent); }
.fm-card .fm-label { font-size: 0.95rem; font-weight: 600; color: #374151; }

/* Ranked cause list */
.cause-item { border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 0.75rem; background: #fff; }
.cause-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.5rem; }
.cause-rank { width: 32px; height: 32px; border-radius: 50%; background: #eff6ff; color: var(--accent-to); font-weight: 800; display: flex; align-items: center; justify-content: center; flex: none; }
.cause-title { font-weight: 700; color: #0f172a; flex: 1; }
.cause-confidence { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); }
.cause-action { color: #475569; font-size: 0.95rem; }
.cause-action p { margin: 0.4rem 0; }
.cause-action p:first-child { margin-top: 0; }
.cause-action p:last-child { margin-bottom: 0; }
.cause-action ul, .cause-action ol { margin: 0.5rem 0; padding-left: 1.5rem; }
.cause-action li { margin: 0.25rem 0; }
.cause-action strong { font-weight: 700; }
.cause-action code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.9em; }

/* ── Choice cards (machine select, outcome) ────────────────────────────── */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.choice-card {
    border: 2px solid var(--border); border-radius: 12px; padding: 1.5rem; cursor: pointer;
    background: #fff; transition: all 0.2s; text-align: left; min-height: 110px; font-family: inherit;
    display: flex; flex-direction: column; gap: 0.4rem;
}
.choice-card:hover { border-color: #cbd5e1; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.07); }
.choice-card.selected { border-color: var(--accent); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.choice-card .choice-title { font-size: 1.1rem; font-weight: 700; color: #0f172a; }
.choice-card .choice-sub { font-size: 0.85rem; color: var(--text-muted); }

/* ── User dropdown menu ────────────────────────────────────────────────── */
.user-dropdown { position: absolute; top: 100%; right: 0; margin-top: 0.5rem; background: #fff; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08); border: 1px solid var(--border); min-width: 220px; z-index: 200; overflow: hidden; }
.user-dropdown-header { padding: 0.85rem 1rem; background: #f8fafc; border-bottom: 1px solid #f1f5f9; }
.user-dropdown-divider { height: 1px; background: #f1f5f9; }
.user-dropdown-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.85rem 1rem; border: none; background: none; font-size: 0.95rem; color: #374151; cursor: pointer; text-align: left; transition: background 0.15s; min-height: var(--tap-min); font-family: inherit; }
.user-dropdown-item:hover { background: #f1f5f9; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px); padding: 1.5rem; }
.modal-card { background: #fff; border-radius: 16px; padding: 2.5rem; max-width: 420px; width: 100%; box-shadow: 0 25px 50px rgba(0,0,0,0.15); }
.modal-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.25rem; text-align: center; }
.modal-sub { color: var(--text-muted); font-size: 0.9rem; text-align: center; margin-bottom: 1.5rem; }

/* ── Utility ───────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 1rem; } .mt-2 { margin-top: 1.5rem; } .mb-1 { margin-bottom: 1rem; }
.loading-inline { text-align: center; padding: 3rem; color: var(--text-faint); font-size: 1rem; }

/* ── Responsive ────────────────────────────────────────────────────────── */
/* Below ~1280px: coach becomes a slide-over drawer, rail becomes compact. */
@media (max-width: 1280px) {
    .session-grid { grid-template-columns: 1fr; }
    .progress-rail-panel { display: none; }
    .step-indicator-compact { display: flex; }
    .coach-drawer-toggle {
        display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
        position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 300;
        min-height: var(--tap-pref); padding: 0 1.5rem; border-radius: 999px; border: none;
        background: linear-gradient(135deg, var(--accent), var(--accent-to)); color: #fff;
        font-weight: 700; font-size: 1rem; cursor: pointer; box-shadow: 0 6px 20px rgba(37,99,235,0.4);
    }
    .coach-panel {
        position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw); z-index: 400;
        max-height: calc(100vh - 11rem); margin: 0; border-radius: 0; transform: translateX(100%);
        transition: transform 0.25s ease; box-shadow: -8px 0 32px rgba(0,0,0,0.2);
    }
    .coach-panel.open { transform: translateX(0); }
    .coach-backdrop.open { display: block; position: fixed; inset: 0; z-index: 390; background: rgba(15,23,42,0.4); }
}

/* Below ~1024px: sidebar collapses to a top bar context; stack content. */
@media (max-width: 1024px) {
    .sidebar { width: 72px; }
    .sidebar-brand .brand-text, .sidebar-nav a span:not(.nav-icon), .sidebar-footer { display: none; }
    .sidebar-nav a { justify-content: center; }
    .main-wrapper { margin-left: 72px; }
    .top-header { padding: 1rem; }
    .page-content { padding: 1.25rem; }
}

@media (max-width: 768px) {
    .stepper-label { display: none; }
    .stepper-connector { width: 20px; }
    .session-strip { gap: 0.85rem; }
}


/* ── Coach Page (full-screen LLM chat) ─────────────────────────────────── */
.coach-page-container {
    height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
}

.coach-page-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.04);
    overflow: hidden;
}

.coach-page-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.coach-page-msg {
    display: flex;
    max-width: 85%;
}

.coach-page-msg.coach {
    align-self: flex-start;
}

.coach-page-msg.user {
    align-self: flex-end;
}

.coach-page-msg-content {
    padding: 1rem 1.25rem;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.5;
}

.coach-page-msg.coach .coach-page-msg-content {
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}

.coach-page-msg.user .coach-page-msg-content {
    background: linear-gradient(135deg, var(--accent), var(--accent-to));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.coach-page-msg-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.coach-page-msg-citations {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.coach-page-msg-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 0.5rem;
    text-align: right;
}

/* Typing indicator */
.coach-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.25rem 0;
}

.coach-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: coach-typing-bounce 1.4s ease-in-out infinite;
}

.coach-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.coach-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes coach-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input area */
.coach-page-input {
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid var(--border);
    background: #fafbfc;
}

.coach-page-input-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.coach-page-input textarea {
    flex: 1;
    min-height: var(--tap-min);
    max-height: 150px;
    resize: none;
    font-size: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
}

.coach-page-input textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.coach-send-btn {
    min-width: 80px;
    height: var(--tap-min);
}

.coach-page-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .coach-page-container {
        height: calc(100vh - 120px);
    }
    
    .coach-page-wrapper {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .coach-page-msg {
        max-width: 92%;
    }
    
    .coach-page-messages {
        padding: 1rem;
    }
    
    .coach-page-input {
        padding: 1rem;
    }
}


/* ── Machine Select Page ───────────────────────────────────────────────── */

/* Machine grid with larger cards for shop floor */
.machine-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Machine card with three-column layout */
.machine-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.machine-card-main {
    flex: 1;
    padding: 1.25rem;
    cursor: pointer;
}

.machine-card-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.machine-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.machine-detail {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.machine-detail .detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.machine-detail .detail-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #0f172a;
}

.machine-detail .detail-value:empty::before,
.machine-detail .detail-value:contains("N/A") {
    color: var(--text-faint);
    font-style: italic;
}

/* Admin action buttons on machine cards */
.machine-card-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-faint);
    background: #fafbfc;
    justify-content: flex-end;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    color: var(--text-muted);
}

.btn-icon:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: var(--text);
}

.btn-icon.btn-danger {
    color: var(--st-mrb);
}

.btn-icon.btn-danger:hover {
    background: #fef2f2;
    border-color: #fecaca;
}

/* Danger button style */
.btn-danger {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: #fff;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}

/* Manufacturer count badge */
.mfr-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 0.5rem;
    background: #eff6ff;
    color: var(--accent-to);
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* Responsive machine cards */
@media (max-width: 600px) {
    .machine-grid {
        grid-template-columns: 1fr;
    }
    
    .machine-card-details {
        grid-template-columns: 1fr;
    }
}

