:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dfe3ea;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --sidebar: #0f172a;
    --success-bg: #e7f6ec;
    --success: #166534;
    --error-bg: #fdecec;
    --error: #b42318;
    --warn-bg: #fff6e0;
    --warn: #92400e;
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h1:focus { outline: none; }
a { color: var(--primary); }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar); color: #cbd5e1; flex-shrink: 0; padding: 1rem .75rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 1rem; }
.sidebar nav a { color: #cbd5e1; text-decoration: none; padding: .55rem .75rem; border-radius: 6px; }
.sidebar nav a:hover { background: #1e293b; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; margin: 1rem .75rem .25rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; color: #fff; font-size: 1rem; }
.brand-dark { color: var(--text); margin-bottom: 1rem; }
.brand-mark { background: var(--primary); color: #fff; border-radius: 6px; padding: 4px 7px; font-size: .8rem; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border-bottom: 1px solid var(--border); padding: .6rem 1.5rem; }
.topbar-title { font-weight: 600; }
.topbar-user { color: var(--muted); display: flex; align-items: center; gap: .5rem; }
.content { padding: 1.5rem; }
.inline-form { display: inline; margin: 0; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.mt { margin-top: 1rem; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.6rem; font-weight: 600; margin-top: .2rem; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field > span { font-weight: 500; font-size: .85rem; }
input, select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid #bfd3ff; border-color: var(--primary); }
input.qty { width: 90px; text-align: right; }
input.big { font-size: 1.3rem; padding: .6rem .8rem; width: 260px; }
.req { color: var(--error); }
.validation-message { color: var(--error); font-size: .85rem; }

/* Buttons */
.btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: .5rem .9rem; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: #f1f4f8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--error); }
.btn-link { border: none; background: none; color: var(--primary); padding: 0; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-sm { padding: .25rem .55rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfd; }
tfoot td { font-weight: 600; }
.empty { color: var(--muted); padding: 1rem 0; }

/* Alerts & badges */
.alert { padding: .7rem .9rem; border-radius: 6px; margin-bottom: 1rem; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert-info { background: #eaf1ff; color: #1e3a8a; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef1f5; color: var(--muted); }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-in-progress, .badge-issued { background: var(--warn-bg); color: var(--warn); }
.badge-reserved { background: #eaf1ff; color: #1e3a8a; }
.badge-delivered { background: var(--success-bg); color: var(--success); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; margin-right: 6px; box-shadow: 0 0 0 3px #dcfce7; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 360px; }

/* QR */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.qr-card { text-align: center; border: 1px dashed #b6bfcc; border-radius: var(--radius); padding: 1rem; background: #fff; page-break-inside: avoid; }
.qr-card img { width: 170px; height: 170px; image-rendering: pixelated; }
.qr-card .label { font-size: 1.4rem; font-weight: 700; margin-top: .4rem; }
.order-slip { display: flex; gap: 1.5rem; align-items: center; }
.order-slip img { width: 180px; height: 180px; image-rendering: pixelated; }
.order-number { font-size: 2rem; font-weight: 700; letter-spacing: .05em; }

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .content { padding: 0; }
    .card { border: none; }
    body { background: #fff; }
}

/* Blazor */
#blazor-error-ui { background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred." }
.text-warn { color: var(--warn); font-weight: 600; }

/* CR-001 additions */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.choice { font: inherit; padding: .8rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.choice:hover { border-color: var(--primary); }
.choice.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.choice-wide { padding: 1rem; font-size: 1.05rem; }
.choice-note { font-size: .72rem; font-weight: 500; opacity: .8; }
.summary-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; position: sticky; bottom: 0; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }
.big-alert { font-size: 1.05rem; }
.line-progress { display: flex; justify-content: space-between; gap: 1rem; max-width: 320px; }
.line-progress .done { color: var(--success); font-weight: 600; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
@keyframes flash { from { background: #fff7cc; } to { background: transparent; } }
.row-flash { animation: flash 2.5s ease-out; }

/* PDT-placed orders */
.badge-pdt { background: #ede9fe; color: #5b21b6; }
.toast-stack { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: .6rem; z-index: 900; width: 340px; max-width: calc(100vw - 2rem); }
.toast { background: #fff; border: 1px solid #c4b5fd; border-left: 5px solid #7c3aed; border-radius: 8px; padding: .8rem 1rem; box-shadow: 0 6px 18px rgba(15, 23, 42, .15); }
.toast-title { font-weight: 700; color: #5b21b6; margin-bottom: .2rem; }
.toast-actions { display: flex; justify-content: space-between; margin-top: .4rem; }


/* Counter issue tracking */
.badge-with-waiter { background: #e0f2fe; color: #075985; }
.issued-note { color: #075985; font-weight: 500; font-size: .85em; }
.text-on { color: var(--success); }
.setting-row { display: flex; justify-content: space-between; gap: 1.5rem; align-items: flex-start; }
.switch { position: relative; display: inline-block; width: 58px; height: 32px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; border-radius: 32px; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 24px; width: 24px; left: 4px; top: 4px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(26px); }
.switch input:disabled + .slider { opacity: .6; cursor: wait; }
.issue-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .issue-layout { grid-template-columns: 1fr; } }
.order-pick-list { display: flex; flex-direction: column; gap: .5rem; max-height: 65vh; overflow-y: auto; }
.order-pick { text-align: left; font: inherit; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .6rem .75rem; cursor: pointer; display: flex; flex-direction: column; gap: .15rem; }
.order-pick:hover { border-color: var(--primary); }
.order-pick.selected { border: 2px solid var(--primary); background: #f5f8ff; }
.qty-stepper { display: inline-flex; gap: .3rem; align-items: center; }
.qty-stepper input.qty { width: 64px; }
