/* QBIS application — layout, components, screens. Tokens live in tokens.css. */
html, body { height: 100%; }
body { overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
p { margin: 0 0 .6rem; max-width: 74ch; }
h1 { font-size: clamp(1.45rem, 2.2vw, 1.85rem); margin: 0; font-weight: 750; }
h1:focus { box-shadow: none; }
h2 { font-size: 1.12rem; margin: 0 0 .6rem; font-weight: 700; }
h3 { font-size: .98rem; margin: 0 0 .45rem; font-weight: 700; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* boot */
.boot { height: 100vh; display: grid; place-items: center; }
.boot-ring { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--primary); border-right-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================ shell */
.shell { height: 100vh; height: 100dvh; display: grid; grid-template-columns: var(--rail-w) 1fr; grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-areas: "rail head" "rail main" "rail foot"; transition: grid-template-columns var(--t-med) var(--ease); }
.shell.collapsed { grid-template-columns: var(--rail-w-collapsed) 1fr; }

.app-head { grid-area: head; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line);
  background: var(--surface-glass); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); z-index: 20; }
.app-head .crumb { min-width: 0; }
.app-head .crumb small { display: block; color: var(--muted); font-size: .76rem; font-weight: 600; line-height: 1.1; }
.app-head .crumb b { display: block; font: 700 1.02rem var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: var(--r-s); border: 1px solid transparent; background: transparent; color: var(--ink-2); display: inline-grid; place-items: center; cursor: pointer; transition: background var(--t-fast), color var(--t-fast); -webkit-tap-highlight-color: transparent; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .dot { position: absolute; top: 7px; right: 7px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #241600; font-size: .66rem; font-weight: 800; display: grid; place-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 800 .82rem var(--font-display); color: var(--primary-ink); background: linear-gradient(135deg, var(--primary), var(--accent)); border: 0; cursor: pointer; }
.menu-btn { display: none; }

.rail { grid-area: rail; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); overflow: hidden; z-index: 30; }
.rail-brand { height: var(--header-h); display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid var(--line); flex: none; }
.rail-brand .name { font: 800 1.2rem var(--font-display); letter-spacing: .02em; }
.rail-brand .co { display: block; font-size: .74rem; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.rail-nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.rail-group { margin: 14px 12px 4px; font-size: .74rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.rail-nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--r-s); color: var(--ink-2); text-decoration: none; font-weight: 600; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); }
.rail-nav a svg { flex: none; }
.rail-nav a:hover { background: var(--surface-2); color: var(--ink); }
.rail-nav a.active { background: var(--primary-wash); color: var(--primary); }
.rail-nav a.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.rail-nav a .count { margin-left: auto; background: var(--accent); color: #241600; border-radius: 9px; font-size: .7rem; font-weight: 800; padding: 1px 7px; }
.rail-foot { padding: 10px; border-top: 1px solid var(--line); }
.shell.collapsed .rail-brand .txt, .shell.collapsed .rail-group, .shell.collapsed .rail-nav a span, .shell.collapsed .rail-nav a .count { display: none; }
.shell.collapsed .rail-nav a { justify-content: center; padding: 10px; }
.shell.collapsed .rail-brand { justify-content: center; padding: 0; }

main.app-main { grid-area: main; overflow-y: auto; overflow-x: hidden; padding: 24px 28px 24px; scroll-behavior: smooth; overscroll-behavior: contain; }
.app-foot { grid-area: foot; display: flex; align-items: center; gap: 16px; padding: 0 20px; border-top: 1px solid var(--line); background: var(--surface); font-size: .78rem; color: var(--muted); z-index: 10; white-space: nowrap; overflow: hidden; }
.app-foot .live { display: inline-flex; align-items: center; gap: 6px; }
.app-foot .live i { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-wash); }
.app-foot .live.off i { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-wash); }
.app-foot .sp { margin-left: auto; }

.tabbar { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(6, 18, 15, .45); backdrop-filter: blur(2px); z-index: 25; opacity: 0; pointer-events: none; transition: opacity var(--t-med); }
.scrim.on { opacity: 1; pointer-events: auto; }

/* page transitions */
.view-enter { animation: view-in var(--t-slow) var(--ease) backwards; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; }

/* popover menu */
.pop { position: fixed; z-index: 60; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-3); padding: 6px; transform-origin: top right; animation: pop .18s var(--ease-spring) both; }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(-4px); } to { opacity: 1; transform: none; } }
.pop .who { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.pop .who b { display: block; }
.pop .who span { color: var(--muted); font-size: .84rem; }
.pop button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 12px; border: 0; border-radius: var(--r-s); background: transparent; cursor: pointer; text-align: left; font-weight: 600; color: var(--ink-2); }
.pop button:hover { background: var(--surface-2); color: var(--ink); }
.pop button[aria-checked="true"] { color: var(--primary); }
.pop .seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 6px; }
.pop .seg button { justify-content: center; flex-direction: column; gap: 2px; font-size: .74rem; padding: 8px 4px; border: 1px solid var(--line); }
.pop .seg button[aria-checked="true"] { border-color: var(--primary); background: var(--primary-wash); }

/* ============================================================ page building blocks */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .8rem; color: var(--ink-2); font-weight: 700; }
.field small { color: var(--muted); }
input[type=text], input[type=number], input[type=month], input[type=date], input[type=email], input[type=search], input[type=password], select, textarea {
  border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); padding: 9px 12px; min-height: 42px; width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast); }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
.toolbar input:not([type=checkbox]):not([type=radio]), .toolbar select { width: auto; min-width: 170px; }
textarea { min-height: 80px; resize: vertical; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 600; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow-1); }
.panel.flush { padding: 0; overflow: hidden; }
.note { border-radius: var(--r-m); padding: 12px 16px; margin-bottom: 14px; background: var(--primary-wash); border: 1px solid transparent; color: var(--ink); }
.note.warn { background: var(--accent-wash); }
.note.err { background: var(--danger-wash); }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.draft { background: var(--accent-wash); color: var(--accent); }
:root:not([data-theme="dark"]) .pill.draft { color: #8a5a00; }
.pill.published { background: var(--primary-wash); color: var(--primary); }
.pill.erp { background: var(--indigo-wash); color: var(--indigo); }
.pill.manual { background: var(--primary-wash); color: var(--primary); }
.pill.calculated { background: var(--violet-wash); color: var(--violet); }
.pill.core, .pill.off { background: var(--canvas-2); color: var(--muted); }
.pill.error { background: var(--danger-wash); color: var(--danger); }

table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data td input, table.data td select { width: 100%; }
table.data tr.inactive td { color: var(--muted); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; width: fit-content; max-width: 100%; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--ink-2); border-radius: var(--r-s); font-weight: 700; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); }
.tabs a:hover { background: var(--surface-2); }
.tabs a.active { background: var(--ink); color: var(--canvas); }

.skeleton { border-radius: var(--r-s); background: linear-gradient(90deg, var(--surface-2) 25%, var(--canvas-2) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.loading { padding: 10px 0; display: grid; gap: 12px; }
.loading .skeleton { height: 18px; }
.loading .skeleton.big { height: 120px; border-radius: var(--r-l); }

/* ============================================================ menu planning */
.plan-layout { display: grid; grid-template-columns: minmax(270px, 340px) 1fr; gap: 18px; align-items: start; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .dow { font-size: .72rem; color: var(--muted); text-align: center; font-weight: 700; }
.cal button { position: relative; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-s); min-height: 54px; padding: 5px 6px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between; font-size: .76rem; transition: transform var(--t-fast) var(--ease), border-color var(--t-fast), background var(--t-fast); }
.cal button:hover { border-color: var(--ink-2); transform: translateY(-1px); }
.cal button .d { font-weight: 800; font-size: .92rem; }
.cal button .t { color: var(--ink-2); font-weight: 600; }
.cal button.has { background: var(--primary-wash); border-color: transparent; }
.cal button.has.draft { background: var(--accent-wash); }
.cal button.today .d { color: var(--primary); }
.cal button.sel { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-wash), inset 0 0 0 1px var(--primary); }
.cal button.blank { visibility: hidden; }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--line); }

.day-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.day-head h2 { font-size: 1.25rem; margin-bottom: 4px; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: .84rem; }
.total-field input { font: 800 1.9rem var(--font-display); width: 180px; text-align: right; min-height: 58px; letter-spacing: -.02em; }
.wh-line { font-size: .84rem; color: var(--muted); margin-top: 4px; }
.dish-table td.qty { width: 190px; }
.dish-table tr.zero td:not(.qty) { color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper input { text-align: right; font-weight: 800; min-width: 70px; }
.stepper button { width: 36px; height: 36px; flex: none; border-radius: var(--r-s); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); display: grid; place-items: center; cursor: pointer; transition: background var(--t-fast), transform var(--t-fast); }
.stepper button:hover { background: var(--primary-wash); color: var(--primary); }
.stepper button:active { transform: scale(.92); }

/* allocation footer — the plate gauge */
.alloc { position: sticky; bottom: -24px; z-index: 5; margin: 16px -22px -20px; padding: 14px 22px; border-radius: 0 0 var(--r-l) var(--r-l);
  background: #0e2621; color: #e6f2ee; display: grid; grid-template-columns: auto repeat(3, auto) 1fr; gap: 6px 26px; align-items: center; box-shadow: 0 -12px 30px -18px rgba(0, 0, 0, .5); }
:root[data-theme="dark"] .alloc { background: #061310; border-top: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .alloc { background: #061310; border-top: 1px solid var(--line); } }
.alloc .plate { width: 64px; height: 64px; --line: rgba(255, 255, 255, .14); --ink: #fff; }
.alloc .plate-seg { transition: stroke-dasharray .5s var(--ease), stroke-dashoffset .5s var(--ease); }
.alloc .plate-tick { transition: transform .5s var(--ease); }
.alloc .k { font-size: .74rem; color: #9fbfb5; font-weight: 700; }
.alloc .v { font: 800 1.55rem var(--font-display); line-height: 1.1; letter-spacing: -.02em; }
.alloc .delta.over { color: #aab6ff; }
.alloc .delta.under { color: #ffcf6d; }
.alloc .delta.even { color: #7fe3bd; }
.alloc .info { cursor: help; border-bottom: 1px dotted #9fbfb5; }
.alloc .per { justify-self: end; text-align: right; font-size: .8rem; color: #9fbfb5; }
.alloc .per b { display: block; color: #fff; font: 700 1.05rem var(--font-display); }
.alloc-save { display: none !important; }
details.req summary { cursor: pointer; font-weight: 700; padding: 2px 0; list-style: none; display: flex; align-items: center; gap: 8px; }
details.req summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform var(--t-med); }
details.req[open] summary::before { transform: rotate(45deg); }
.daystrip { display: none; }

/* PDF viewer */
.pdf-frame { width: 100%; height: min(78vh, 900px); border: 0; border-radius: var(--r-m); background: var(--surface-2); }

/* ============================================================ grids (Handsontable) */
.grid-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); overflow: hidden; box-shadow: var(--shadow-1); }
.grid-host { height: calc(100dvh - var(--header-h) - var(--footer-h) - 330px); min-height: 340px; overflow: hidden; }
.grid-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: .84rem; color: var(--muted); flex-wrap: wrap; }
.handsontable { font-family: var(--font-ui); font-size: 14px; color: var(--ink); }
.handsontable th, .handsontable td { border-color: var(--line) !important; }
.handsontable td { background: var(--surface); color: var(--ink); }
.handsontable th { background: var(--grid-head); color: var(--ink-2); font-weight: 700; }
.handsontable th.col-manual { background: var(--primary-wash); color: var(--primary); }
.handsontable th.col-calculated { background: var(--violet-wash); color: var(--violet); }
.handsontable td.cell-ro { background: var(--surface-2); color: var(--ink-2); }
.handsontable td.cell-calc { background: var(--violet-wash); color: var(--violet); }
.handsontable td.cell-err { color: var(--danger); }
.handsontable td.cell-inactive { color: var(--muted); text-decoration: line-through; }
.handsontable .wtBorder.current, .handsontable .wtBorder.area { background-color: var(--primary) !important; }
.handsontable td.area::before { background: var(--primary) !important; }
.handsontableInput { background: var(--surface) !important; color: var(--ink) !important; box-shadow: inset 0 0 0 2px var(--primary) !important; }
.htDropdownMenu, .htAutocompleteArrow { color: var(--muted); }
.saving-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1s ease infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.grid-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 10px; }
.grid-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* card list (mobile alternative to grids) */
.cards { display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 14px 16px; display: grid; gap: 6px; text-align: left; width: 100%; cursor: pointer; transition: transform var(--t-fast), box-shadow var(--t-fast); color: var(--ink); font: inherit; }
.card:active { transform: scale(.985); }
.card .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.card .top b { font-family: var(--font-display); }
.card .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .84rem; color: var(--muted); }
.card .meta span b { color: var(--ink-2); font-weight: 700; }

/* ============================================================ misc screens */
.map-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .84rem; background: var(--surface); }
.chip.ok { border-color: var(--primary); color: var(--primary); background: var(--primary-wash); }
.chip.new { border-color: var(--indigo); background: var(--indigo-wash); color: var(--indigo); }
.chip.skip { color: var(--muted); text-decoration: line-through; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 12px; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 0; transition: width .25s var(--ease); }
.quota { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; width: 160px; max-width: 100%; }
.quota div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.quota div.hi { background: linear-gradient(90deg, var(--accent), var(--danger)); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 14px; }
.split { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 16px; align-items: start; }
.user-list { max-height: calc(100vh - 300px); overflow: auto; }
.user-list button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); padding: 11px 16px; cursor: pointer; color: var(--ink); transition: background var(--t-fast); }
.user-list button:hover { background: var(--surface-2); }
.user-list button.sel { background: var(--primary-wash); box-shadow: inset 3px 0 0 var(--primary); }
.user-list .code { font-weight: 800; font-family: var(--font-display); }
.auth-matrix td select { min-width: 160px; }
.auth-matrix tr.area td { background: var(--surface-2); font-weight: 800; font-size: .78rem; color: var(--muted); }
.lvl { font-weight: 700; font-size: .84rem; }
.lvl.full { color: var(--primary); }
.lvl.read { color: var(--indigo); }
.lvl.none { color: var(--muted); }
.script-box { height: 220px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre; }
ol.steps-list { padding-left: 20px; margin: 8px 0 16px; }
ol.steps-list li { margin-bottom: 8px; max-width: 76ch; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); text-decoration: underline; cursor: pointer; font-weight: 600; }
.codes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; margin: 14px 0; }
.codes-grid code { display: block; text-align: center; padding: 10px; font-size: .92rem; white-space: nowrap; letter-spacing: .06em; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--r-s); }

/* ============================================================ dialogs → bottom sheets on phones */
.modal-back { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: rgba(6, 18, 15, .5); backdrop-filter: blur(3px); animation: fade .2s ease both; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-xl); width: min(880px, 100%); max-height: calc(100dvh - 48px); display: flex; flex-direction: column; box-shadow: var(--shadow-3); border: 1px solid var(--line); animation: modal-in .3s var(--ease-spring) both; }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.modal.narrow { width: min(500px, 100%); }
.modal header { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px 22px; overflow-y: auto; }
.modal footer { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.modal .grab { display: none; }

/* toasts */
.toasts { position: fixed; right: 20px; bottom: calc(var(--footer-h) + 16px); display: flex; flex-direction: column; gap: 8px; z-index: 1100; max-width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; background: var(--ink); color: var(--canvas); padding: 12px 14px; border-radius: var(--r-m); box-shadow: var(--shadow-3); animation: toast-in .35s var(--ease-spring) both; }
.toast svg { flex: none; margin-top: 1px; }
.toast.ok svg { color: var(--primary-2); }
.toast.warn svg { color: var(--accent); }
.toast.error svg { color: var(--danger); }
.toast.out { animation: toast-out .25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ============================================================ sign-in, setup */
.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: 1fr minmax(380px, 520px); overflow-y: auto; height: 100dvh; }
.auth-side { position: relative; overflow: hidden; background: linear-gradient(155deg, #0e2621, #133d33 60%, #1b4b3f); color: #e6f2ee; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side::after { content: ""; position: absolute; right: -20%; bottom: -25%; width: 80%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(closest-side, rgba(245, 184, 61, .22), transparent 70%); }
.auth-side .brand { display: flex; align-items: center; gap: 10px; font: 800 1.3rem var(--font-display); }
.auth-side h2 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.08; max-width: 14ch; margin: 0 0 12px; color: #fff; }
.auth-side p { color: #b9d3cb; max-width: 42ch; }
.auth-side .plate-wrap { position: relative; z-index: 1; width: min(320px, 70%); align-self: center; }
.auth-side .plate { --line: rgba(255, 255, 255, .12); --ink: #fff; }
.plate-big { font: 800 34px var(--font-display); letter-spacing: -.02em; }
.plate-small { font: 600 10.5px var(--font-ui); }
.auth-side .plate-big { fill: #fff; }
.auth-side .plate-small { fill: #9fbfb5; }
.auth-side .plate-seg { animation: draw 1.6s var(--ease) both; }
@keyframes draw { from { stroke-dasharray: 0 999; } }
.auth-main { display: flex; flex-direction: column; justify-content: center; padding: 48px clamp(24px, 5vw, 56px); background: var(--surface); }
.auth-main h1 { font-size: 1.8rem; margin-bottom: 6px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin: 22px 0 14px; }
.auth-form .btn { width: 100%; }
.auth-msg { color: var(--danger); font-size: .9rem; min-height: 1.3em; }
.auth-msg.ok { color: var(--primary); }
.auth-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-wrap button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.strength { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.strength i { display: block; height: 100%; width: 0; transition: width var(--t-med), background var(--t-med); }

.stepper-dots { display: flex; gap: 6px; margin: 4px 0 22px; }
.stepper-dots span { height: 4px; flex: 1; border-radius: 2px; background: var(--line); transition: background var(--t-med); }
.stepper-dots span.on { background: linear-gradient(90deg, var(--primary), var(--accent)); }
.setup-card { width: min(620px, 100%); }
.unit-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.unit-chips span { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; border-radius: 999px; background: var(--primary-wash); color: var(--primary); font-weight: 700; }
.unit-chips button { border: 0; background: transparent; color: inherit; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; }

/* ============================================================ tablet */
@media (max-width: 1180px) {
  .plan-layout { grid-template-columns: 1fr; }
  .cal button { min-height: 48px; }
}
@media (max-width: 1024px) {
  .shell, .shell.collapsed { grid-template-columns: var(--rail-w-collapsed) 1fr; }
  .rail-brand .txt, .rail-group, .rail-nav a span, .rail-nav a .count { display: none; }
  .rail-nav a { justify-content: center; padding: 10px; }
  .rail-brand { justify-content: center; padding: 0; }
  .shell.rail-open .rail { position: fixed; inset: 0 auto 0 0; width: var(--rail-w); box-shadow: var(--shadow-3); }
  .shell.rail-open .rail .rail-brand .txt, .shell.rail-open .rail .rail-group, .shell.rail-open .rail .rail-nav a span, .shell.rail-open .rail .rail-nav a .count { display: revert; }
  .shell.rail-open .rail .rail-nav a { justify-content: flex-start; padding: 9px 12px; }
  .shell.rail-open .rail .rail-brand { justify-content: flex-start; padding: 0 20px; }
  .split { grid-template-columns: 1fr; }
  .user-list { max-height: 300px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

/* ============================================================ phone: explicit mobile layout */
@media (max-width: 760px) {
  :root { --header-h: 56px; }
  .shell, .shell.collapsed { grid-template-columns: 1fr; grid-template-rows: calc(var(--header-h) + env(safe-area-inset-top)) 1fr calc(var(--tabbar-h) + env(safe-area-inset-bottom)); grid-template-areas: "head" "main" "tabs"; }
  .rail, .app-foot { display: none; }
  .shell.rail-open .rail { display: flex; position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw); z-index: 40; animation: slide-in .28s var(--ease) both; }
  @keyframes slide-in { from { transform: translateX(-100%); } }
  .app-head { padding: env(safe-area-inset-top) 12px 0; gap: 8px; }
  .menu-btn { display: inline-grid; }
  .collapse-btn { display: none; }
  main.app-main { padding: 16px 14px 28px; }
  .tabbar { grid-area: tabs; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface-glass); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent; color: var(--muted);
    font: 700 .68rem var(--font-ui); text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color var(--t-fast); }
  .tabbar .on { color: var(--primary); }
  .tabbar .on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
  .tabbar .count { position: absolute; top: 6px; right: calc(50% - 20px); background: var(--accent); color: #241600; border-radius: 8px; padding: 0 5px; font-size: .62rem; }

  h1 { font-size: 1.4rem; }
  .page-head { margin-bottom: 14px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar > * { min-width: 0; }
  .toolbar input:not([type=checkbox]):not([type=radio]), .toolbar select { min-width: 0; width: 100%; }
  .toolbar .full { grid-column: 1 / -1; }
  .panel { padding: 16px; border-radius: var(--r-m); }
  .tabs { width: 100%; }

  /* tables become cards */
  table.data.cardify thead { display: none; }
  table.data.cardify, table.data.cardify tbody, table.data.cardify tr, table.data.cardify td { display: block; width: 100%; }
  table.data.cardify tr { border-bottom: 1px solid var(--line); padding: 10px 14px; }
  table.data.cardify tr.area { padding: 6px 14px; }
  table.data.cardify td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; align-items: center; text-align: right; }
  table.data.cardify td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 700; text-align: left; flex: none; max-width: 45%; }
  table.data.cardify td[data-label=""]::before { display: none; }
  table.data.cardify td > * { max-width: 60%; }
  table.data.cardify td.wide { display: block; text-align: left; }
  table.data.cardify td.wide > * { max-width: 100%; }

  /* planning: day strip + dish cards */
  .plan-layout > .cal-panel { display: none; }
  .daystrip { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 2px 10px; margin: 0 -14px 10px; padding-inline: 14px; scrollbar-width: none; }
  .daystrip::-webkit-scrollbar { display: none; }
  .daystrip button { scroll-snap-align: center; flex: none; width: 58px; padding: 8px 0; border-radius: var(--r-m); border: 1px solid var(--line); background: var(--surface); display: grid; gap: 2px; justify-items: center; cursor: pointer; color: var(--ink); }
  .daystrip button small { font-size: .66rem; color: var(--muted); font-weight: 700; }
  .daystrip button b { font: 800 1.1rem var(--font-display); }
  .daystrip button i { font-style: normal; font-size: .68rem; color: var(--ink-2); min-height: 1em; }
  .daystrip button.has { background: var(--primary-wash); border-color: transparent; }
  .daystrip button.has.draft { background: var(--accent-wash); }
  .daystrip button.sel { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
  .day-head { flex-direction: column; align-items: stretch; }
  .total-field input { width: 100%; }
  .dish-table thead { display: none; }
  .dish-table, .dish-table tbody { display: block; }
  .dish-table tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name qty" "meta qty"; gap: 0 10px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
  .dish-table td { border: 0 !important; padding: 0 !important; }
  .dish-table td.dish { grid-area: name; font-weight: 700; }
  .dish-table td.no, .dish-table td.code { grid-area: meta; font-size: .78rem; }
  .dish-table td.code { display: none; }
  .dish-table td.qty { grid-area: qty; width: auto; }
  .stepper input { width: 76px; min-width: 0; }
  .stepper button { width: 40px; height: 40px; }
  .alloc { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); margin: 0; border-radius: var(--r-l) var(--r-l) 0 0; grid-template-columns: auto 1fr 1fr 1fr auto; gap: 2px 10px; padding: 10px 14px; z-index: 15; }
  .alloc-save { display: inline-flex !important; }
  .dish-table .stepper input { width: 70px; flex: none; padding-inline: 8px; }
  .dish-table .stepper button { width: 38px; height: 38px; }
  .alloc .plate { width: 48px; height: 48px; grid-row: span 2; }
  .alloc .v { font-size: 1.15rem; }
  .alloc .per { display: none; }
  .alloc .k { font-size: .66rem; }
  .plan-day { margin-bottom: 12px; }
  .plan-actions { padding-bottom: 96px; }
  .plan-actions .btn { flex: 1 1 calc(50% - 8px); }
  .plan-actions .btn.primary { display: none; }

  .grid-host { height: 60vh; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal, .modal.narrow { width: 100%; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; padding-bottom: env(safe-area-inset-bottom); animation: sheet-in .34s var(--ease) both; }
  .modal .grab { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 8px auto 0; }
  @keyframes sheet-in { from { transform: translateY(100%); } }
  .modal footer { position: sticky; bottom: 0; background: var(--surface); }
  .modal footer .btn { flex: 1; }
  .toasts { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); max-width: none; }
  .codes-grid { grid-template-columns: 1fr; }
  .auth-main { padding: calc(28px + env(safe-area-inset-top)) 20px 32px; justify-content: flex-start; }
}

@media print {
  body { overflow: visible; }
  .rail, .app-head, .app-foot, .tabbar, .toasts, .no-print { display: none !important; }
  .shell { display: block; height: auto; }
  main.app-main { overflow: visible; padding: 0; }
  .modal-back { position: static; background: none; backdrop-filter: none; }
  .modal { box-shadow: none; border: 0; }
}
