:root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --ink: #251f1a;
    --muted: #776f66;
    --line: #e2e5ec;
    --brand: #e30613;
    --brand-dark: #a8000b;
    --accent: #0b8bd8;
    --sun: #f4c400;
    --green: #157a4f;
    --yellow: #a96e00;
    --blue: #285f9f;
    --shadow: 0 18px 42px rgba(64, 45, 28, .12);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea {
    font: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 72px;
    padding: 12px clamp(16px, 4vw, 42px);
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.brand img {
    width: 64px;
    height: 42px;
    object-fit: contain;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
}

.nav a, .icon-btn {
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
}

.nav a:hover, .icon-btn:hover {
    border-color: var(--line);
    color: var(--ink);
}

.logout-form {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.page {
    width: min(1380px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.page-heading.compact {
    margin-bottom: 10px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--brand);
    font-weight: 800;
    text-transform: uppercase;
    font-size: .76rem;
}

h1, h2, p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 4vw, 3.8rem);
    line-height: 1;
}

h2 {
    font-size: 1.1rem;
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 700;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 12px 13px;
}

textarea {
    resize: vertical;
}

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 12px 18px;
    border: 0;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

.primary-btn:hover {
    background: var(--brand-dark);
}

.primary-btn.wide {
    width: 100%;
}

.ghost-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
}

.ghost-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ghost-btn.wide {
    width: 100%;
}

.danger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid rgba(227, 6, 19, .24);
    border-radius: 8px;
    background: rgba(227, 6, 19, .08);
    color: var(--brand);
    font-weight: 800;
    cursor: pointer;
}

.danger-btn:hover {
    background: var(--brand);
    color: #fff;
}

.flash {
    padding: 14px 16px;
    margin-bottom: 18px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel);
    font-weight: 700;
}

.flash.success { border-color: rgba(21, 122, 79, .28); color: var(--green); }
.flash.error { border-color: rgba(179, 38, 30, .28); color: var(--brand); }

.auth-shell {
    min-height: calc(100vh - 140px);
    display: grid;
    place-items: center;
}

.auth-card, .panel-form, .table-panel, .metric, .ticket, .lane {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-card {
    width: min(420px, 100%);
    display: grid;
    gap: 16px;
    padding: 28px;
}

.demo-access, .sync-note {
    color: var(--muted);
    font-size: .9rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.metric {
    padding: 18px;
}

.metric span {
    color: var(--muted);
    font-weight: 700;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 2rem;
}

.table-panel {
    padding: 18px;
}

.responsive-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 13px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: .82rem;
    text-transform: uppercase;
}

.status, .live-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #efe7dc;
    color: var(--muted);
    font-weight: 800;
    font-size: .78rem;
}

.status.ready { background: rgba(21, 122, 79, .12); color: var(--green); }
.status.preparing, .status.accepted { background: rgba(169, 110, 0, .14); color: var(--yellow); }
.status.sent { background: rgba(40, 95, 159, .12); color: var(--blue); }
.status.open { background: rgba(21, 122, 79, .12); color: var(--green); }
.status.closed { background: rgba(32, 37, 48, .1); color: var(--muted); }

.panel-heading-line {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.panel-heading-line h2,
.panel-heading-line p {
    margin: 0;
}

.panel-heading-line p {
    margin-top: 4px;
    color: var(--muted);
}

.date-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(227, 6, 19, .08);
    color: var(--brand);
    font-weight: 800;
}

.open-tables-panel,
.dashboard-actions,
.history-panel {
    margin-bottom: 22px;
}

.open-table-grid,
.history-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 14px;
}

.open-table-card,
.history-table-card {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.open-table-card {
    border-top: 4px solid var(--brand);
}

.open-table-card > header,
.history-table-card > header,
.visual-order-card summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}

.table-number {
    display: block;
    font-size: 2.3rem;
    line-height: 1;
    font-weight: 900;
    color: var(--ink);
}

.table-number.small {
    font-size: 1.7rem;
}

.table-total {
    text-align: right;
}

.table-total strong,
.history-stats strong,
.table-total small,
.history-stats small,
.open-table-card header small,
.history-table-card header small {
    display: block;
}

.table-total small,
.history-stats small,
.open-table-card header small,
.history-table-card header small,
.visual-order-card small,
.order-note,
.empty-state {
    color: var(--muted);
}

.visual-order-stack,
.history-orders {
    display: grid;
    gap: 10px;
}

.visual-order-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfbfc;
    overflow: hidden;
}

.visual-order-card summary {
    grid-template-columns: minmax(0, 1fr) auto auto;
    padding: 12px;
    cursor: pointer;
}

.visual-order-card summary::marker {
    color: var(--brand);
}

.visual-order-card .order-note {
    padding: 0 12px;
}

.order-item-list.visual {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    padding: 0 12px 12px;
}

.order-note {
    margin: 0;
    font-size: .92rem;
}

.order-item-list {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.order-item-list li {
    display: grid;
    gap: 3px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.order-item-list span {
    font-weight: 800;
}

.history-stats,
.dashboard-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.history-stats span {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfbfc;
}

.dashboard-actions {
    grid-template-columns: minmax(260px, .75fr) minmax(320px, 1.25fr);
    align-items: stretch;
}

.action-panel {
    display: grid;
    align-content: start;
}

.stacked-tool-form,
.history-filter-form {
    display: grid;
    gap: 12px;
}

.history-filter-form {
    grid-template-columns: minmax(160px, 1fr) minmax(150px, .8fr) auto;
    align-items: end;
}

.session-close-form.compact {
    display: flex;
    justify-content: flex-end;
}

.empty-state {
    margin: 0;
    padding: 12px;
}

.split-grid {
    display: grid;
    grid-template-columns: minmax(280px, .8fr) minmax(320px, 1.2fr);
    gap: 18px;
    margin-bottom: 22px;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(240px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.panel-form {
    display: grid;
    align-content: start;
    gap: 14px;
    padding: 18px;
}

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

.inline-check {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inline-check.compact {
    gap: 6px;
    color: var(--muted);
    font-size: .86rem;
    white-space: nowrap;
}

.inline-check input {
    width: auto;
}

.editable-table input,
.editable-table select,
.editable-table textarea {
    min-width: 120px;
    padding: 9px 10px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.row-actions .primary-btn,
.row-actions .ghost-btn {
    min-height: 38px;
    padding: 8px 12px;
}

.admin-list {
    display: grid;
    gap: 10px;
}

.inline-editor {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.inline-editor input,
.inline-editor select {
    padding: 9px 10px;
}

.compact-list {
    display: grid;
    gap: 10px;
}

.compact-list article {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.compact-list span {
    font-weight: 800;
}

.compact-list small {
    display: block;
    color: var(--muted);
}

.admin-modal {
    width: min(560px, calc(100vw - 28px));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0;
    box-shadow: var(--shadow);
}

.admin-modal::backdrop {
    background: rgba(20, 24, 33, .45);
    backdrop-filter: blur(3px);
}

.admin-modal form {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.admin-modal header,
.admin-modal footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.admin-modal header {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.admin-modal header button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 800;
}

.admin-modal footer {
    padding-top: 8px;
    border-top: 1px solid var(--line);
    justify-content: flex-end;
}

.confirm-modal p {
    margin: 0;
    color: var(--muted);
}

.toast-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 100;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 36px));
}

.toast {
    padding: 13px 14px;
    border: 1px solid rgba(21, 122, 79, .22);
    border-radius: 8px;
    background: #fff;
    color: var(--green);
    box-shadow: var(--shadow);
    font-weight: 800;
}

.toast.error {
    border-color: rgba(227, 6, 19, .22);
    color: var(--brand);
}

.toast.info {
    border-color: rgba(11, 139, 216, .22);
    color: var(--accent);
}

.order-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
    gap: 18px;
    align-items: start;
    height: calc(100dvh - 128px);
    min-height: 620px;
    overflow: hidden;
}

.menu-browser {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
    scrollbar-gutter: stable;
}

.category-title {
    margin: 22px 0 10px;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}

.menu-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 118px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.menu-item.combo-item {
    border-color: rgba(11, 139, 216, .32);
    background: linear-gradient(180deg, #ffffff 0%, #f2f8ff 100%);
}

.menu-item:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
}

.menu-item strong, .menu-item small {
    display: block;
}

.menu-item small {
    margin-top: 7px;
    color: var(--muted);
    line-height: 1.35;
}

.menu-item em {
    flex: 0 0 auto;
    color: var(--brand);
    font-style: normal;
    font-weight: 800;
}

.option-hint {
    display: inline-flex !important;
    width: fit-content;
    margin-top: 10px !important;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(244, 196, 0, .25);
    color: #6a5000 !important;
    font-weight: 800;
}

.ticket {
    display: grid;
    gap: 14px;
    max-height: 100%;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    scrollbar-gutter: stable;
}

.table-picks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-picks button, .chip {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-weight: 800;
}

.table-picks button {
    cursor: pointer;
}

.table-picks button.active, .table-picks button:hover {
    border-color: var(--brand);
    background: rgba(227, 6, 19, .08);
    color: var(--brand);
}

.ticket-head, .ticket-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.ticket-lines {
    display: grid;
    gap: 10px;
    overflow: visible;
    padding-right: 4px;
}

.ticket-line {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) 44px;
    gap: 12px;
    align-items: start;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.ticket-line > input[type="number"] {
    width: 64px;
    min-width: 64px;
    height: 48px;
    padding: 0 6px;
    text-align: center;
    font-weight: 800;
    font-size: 1rem;
}

.ticket-line > div {
    min-width: 0;
}

.line-option {
    margin-top: 8px;
    gap: 5px;
    font-size: .86rem;
}

.line-option select {
    padding: 9px 10px;
}

.ticket-line button {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 1.3rem;
    font-weight: 800;
    line-height: 1;
}

.ticket-line textarea {
    margin-top: 8px;
    padding: 9px;
    min-height: 74px;
}

.empty-state {
    margin: 0;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.ticket-total {
    padding-top: 12px;
    border-top: 1px solid var(--line);
    font-size: 1.15rem;
}

.waiter-alerts {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid rgba(11, 139, 216, .25);
    border-radius: 8px;
    background: rgba(11, 139, 216, .08);
    color: var(--accent);
}

.waiter-alerts span {
    color: var(--ink);
    font-size: .92rem;
}

.heading-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

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

.lane {
    min-height: 55vh;
    padding: 16px;
}

.lane > div {
    display: grid;
    gap: 12px;
}

.kitchen-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.kitchen-card header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.kitchen-card h3 {
    margin: 0 0 5px;
    font-size: 1.25rem;
}

.kitchen-card ul {
    margin: 0;
    padding-left: 20px;
}

.kitchen-card li {
    margin: 7px 0;
}

.kitchen-card small {
    color: var(--muted);
}

.selected-options {
    display: inline-flex;
    margin-top: 3px;
    color: var(--brand);
    font-weight: 800;
}

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

.kitchen-actions button {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-weight: 800;
}

.kitchen-actions button:hover {
    border-color: var(--brand);
}

@media (max-width: 960px) {
    .topbar, .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        margin-left: 0;
    }

    .logout-form {
        width: 100%;
        justify-content: space-between;
    }

    .order-shell, .split-grid, .kanban, .metric-grid, .dashboard-actions, .history-filter-form {
        grid-template-columns: 1fr;
    }

    .order-shell {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .menu-browser,
    .ticket {
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .catalog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .page {
        width: min(100% - 20px, 1380px);
        padding-top: 18px;
    }

    .form-row, .kitchen-actions, .visual-order-card summary, .open-table-card > header, .history-table-card > header {
        grid-template-columns: 1fr;
    }

    .table-total {
        text-align: left;
    }

    .history-stats {
        grid-template-columns: 1fr;
    }

    .catalog-grid {
        grid-template-columns: 1fr;
    }

    .compact-list article {
        grid-template-columns: 1fr;
    }

    .row-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .ticket-line {
        grid-template-columns: 58px minmax(0, 1fr) 42px;
        gap: 10px;
        padding: 10px;
    }

    .ticket-line > input[type="number"] {
        width: 58px;
        min-width: 58px;
        height: 44px;
    }

    .ticket-line button {
        width: 42px;
        height: 42px;
    }
}
