:root {
    --bg: #f3f4f6;
    --panel: #ffffff;
    --panel-soft: #f9fafb;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --sidebar: #111827;
    --sidebar-soft: #1f2937;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #d97706;
    --shadow: 0 12px 28px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-width: 320px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .08), transparent 26rem),
        var(--bg);
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: 0; }
p { line-height: 1.55; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(37, 99, 235, .12), rgba(255,255,255,.88)),
        #eef2ff;
}
.login-card {
    width: min(440px, 100%);
    background: rgba(255,255,255,.94);
    border: 1px solid rgba(229,231,235,.9);
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 24px 70px rgba(17, 24, 39, .16);
}
.login-card h1 { margin: 0 0 8px; font-size: 27px; }
.login-card p, .topbar p { margin: 0; color: var(--muted); }
.public-page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 36px;
}
.public-hero {
    min-height: 240px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
    padding: 30px;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(17,24,39,.94), rgba(37,99,235,.82)),
        #111827;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.public-hero h1 {
    max-width: 720px;
    margin: 0 0 10px;
    font-size: 44px;
    line-height: 1.05;
}
.public-hero p {
    max-width: 620px;
    margin: 0;
    color: #dbeafe;
    font-size: 16px;
}
.public-hero .eyebrow {
    color: #bfdbfe;
}
.public-stats .stat p {
    margin: 8px 0 0;
    position: relative;
    z-index: 1;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    padding: 18px 14px;
    background: var(--sidebar);
    color: #fff;
    z-index: 20;
    overflow-y: auto;
    box-shadow: 14px 0 40px rgba(17, 24, 39, .18);
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,.10);
    margin-bottom: 14px;
}
.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    border-radius: 8px;
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .35);
}
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; margin-top: 3px; color: #aeb8c9; text-transform: uppercase; font-size: 11px; font-weight: 700; }
.sidebar nav { display: grid; gap: 4px; }
.nav-label {
    margin: 14px 10px 5px;
    color: #8b96a8;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.sidebar nav a {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #d1d5db;
    font-weight: 700;
}
.sidebar nav a:hover,
.sidebar nav a.active {
    background: var(--sidebar-soft);
    color: #fff;
}
.sidebar nav a.active {
    box-shadow: inset 3px 0 0 var(--primary);
}
.logout-link { margin-top: 10px; color: #fecaca !important; }

.main {
    margin-left: 270px;
    padding: 24px;
    min-height: 100vh;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px 18px;
    background: rgba(255,255,255,.88);
    border: 1px solid rgba(229,231,235,.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: 25px; letter-spacing: 0; }
.menu-toggle { display: none; }
.canteen-switch { min-width: 240px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
    background: var(--panel);
    border: 1px solid rgba(229,231,235,.95);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat {
    position: relative;
    overflow: hidden;
}
.stat::after {
    content: "";
    position: absolute;
    right: -28px;
    top: -28px;
    width: 92px;
    height: 92px;
    border-radius: 999px;
    background: var(--primary-soft);
}
.stat strong { display: block; font-size: 28px; margin-top: 7px; position: relative; z-index: 1; }
.stat span { color: var(--muted); font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; position: relative; z-index: 1; }

form.stack, .stack { display: grid; gap: 12px; }
label {
    display: grid;
    gap: 7px;
    font-weight: 800;
    font-size: 13px;
    color: #374151;
}
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}
textarea { min-height: 88px; resize: vertical; }
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    padding: 10px 15px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .18);
    min-height: 42px;
    text-align: center;
}
button:hover, .btn:hover { background: var(--primary-dark); }
.btn.secondary, button.secondary {
    background: #f3f4f6;
    color: #111827;
    border: 1px solid var(--line);
    box-shadow: none;
}
.btn.danger, button.danger {
    background: var(--danger);
    color: #fff;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
    margin-top: 8px;
}
.check-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-weight: 700;
}
.check-card input {
    width: auto;
}
.template-panel {
    padding: 12px;
    border: 1px dashed #bfdbfe;
    border-radius: 8px;
    background: var(--primary-soft);
}
.template-panel p {
    margin: 6px 0 10px;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 8px;
}
table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    background: #fff;
}
th, td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th {
    background: #f9fafb;
    font-size: 12px;
    text-transform: uppercase;
    color: #4b5563;
    letter-spacing: .04em;
}
tbody tr:hover td { background: #f9fafb; }
tr:last-child td { border-bottom: 0; }
small { font-size: 12px; }

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: #dbeafe;
    color: #1e3a8a;
    border: 1px solid #bfdbfe;
    font-weight: 700;
}
.alert.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert.success { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.low { color: var(--danger); font-weight: 800; }
.ok { color: var(--success); font-weight: 800; }
.muted { color: var(--muted); }
.eyebrow {
    display: inline-flex;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, .62);
}
.modal-card {
    width: min(520px, 100%);
    max-height: calc(100dvh - 36px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 28px 90px rgba(15, 23, 42, .28);
}
.modal-large {
    width: min(680px, 100%);
    padding: 32px;
}
.modal-large h2 {
    margin-bottom: 8px;
    font-size: 34px;
}
.modal-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 16px 0;
}
.modal-tabs .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.manager-sales-pane {
    padding-top: 4px;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 8px;
    background: #f3f4f6;
    color: var(--ink);
    box-shadow: none;
    font-size: 24px;
}
.modal-close:hover {
    background: #e5e7eb;
}

.pos-layout { grid-template-columns: 1.5fr .9fr; }
.product-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}
.product-tile {
    text-align: left;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
    box-shadow: none;
}
.product-tile:hover {
    background: var(--primary-soft);
    color: var(--ink);
    border-color: #bfdbfe;
}
.product-tile small { display: block; color: var(--muted); margin-top: 5px; line-height: 1.35; }
.receipt-line {
    display: grid;
    grid-template-columns: 1fr 72px 96px 36px;
    gap: 8px;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

@media print {
    .sidebar, .topbar, .no-print, .alert { display: none !important; }
    .main { margin: 0; padding: 0; }
    .card, table, .table-wrap { border: 0; box-shadow: none; }
}
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    body { background: var(--bg); }
    .sidebar {
        width: min(300px, 86vw);
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main {
        margin-left: 0;
        padding: max(12px, env(safe-area-inset-top)) 12px 18px;
    }
    .menu-toggle { display: inline-flex; }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        align-items: stretch;
        flex-direction: column;
        padding: 12px;
        margin-bottom: 12px;
    }
    .topbar h1 { font-size: 21px; }
    .canteen-switch { min-width: 100%; }
    .grid-2, .grid-3, .grid-4, .pos-layout { grid-template-columns: 1fr; }
    .card { padding: 14px; }
    .stat strong { font-size: 24px; }
    .actions, .modal-tabs {
        align-items: stretch;
        flex-direction: column;
    }
    .actions > *, .modal-tabs > *, button, .btn {
        width: 100%;
    }
    input, select, textarea {
        min-height: 44px;
        font-size: 16px;
    }
    .modal-backdrop {
        align-items: start;
        padding: 10px;
    }
    .modal-card, .modal-large {
        width: 100%;
        max-height: calc(100dvh - 20px);
        padding: 18px;
    }
    .modal-large h2 { font-size: 26px; }
    .modal-close {
        width: 42px;
        height: 42px;
    }
    .product-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .product-tile {
        min-height: 92px;
        padding: 10px;
    }
    .receipt-line {
        grid-template-columns: 1fr;
        gap: 6px;
        align-items: stretch;
    }
    .receipt-line input {
        width: 100%;
    }
    .public-page {
        width: min(100% - 20px, 1180px);
        padding: 10px 0 24px;
    }
    .public-hero {
        align-items: flex-start;
        flex-direction: column;
        min-height: auto;
        padding: 20px;
    }
    .public-hero h1 {
        font-size: 31px;
    }
    .public-hero p { font-size: 15px; }
}
@media (max-width: 520px) {
    .product-list { grid-template-columns: 1fr; }
    .check-grid { grid-template-columns: 1fr; }
    th, td { padding: 10px; }
    table { min-width: 620px; }
}
