:root, [data-theme="light"] {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --sidebar: #0f172a;
    --sidebar-muted: #94a3b8;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #e11d48;
    --primary-dark: #be123c;
    --primary-soft: #ffe4e6;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --success-text: #166534;
    --table-head: #f8fafc;
    --row-hover: #fafafa;
    --input-bg: #ffffff;
    --chip-bg: #ffffff;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111827;
    --sidebar: #020617;
    --sidebar-muted: #94a3b8;
    --border: #1f2a3d;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #fb7185;
    --primary-dark: #fda4af;
    --primary-soft: rgba(251, 113, 133, .18);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .16);
    --success-text: #86efac;
    --table-head: #0f172a;
    --row-hover: #0f172a;
    --input-bg: #0f172a;
    --chip-bg: #0f172a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }

.boot-splash {
    display: flex; align-items: center; justify-content: center;
    height: 100vh; color: var(--muted); font-family: inherit;
}

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

.app-sidebar {
    width: 248px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    gap: 10px;
    max-height: 100vh;
    overflow: hidden;
}
.app-sidebar .nav-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-inline-end: 4px;
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

/* Thin overlay scrollbar — Chrome / Edge / Safari */
.app-sidebar .nav-list::-webkit-scrollbar {
    width: 5px;
}
.app-sidebar .nav-list::-webkit-scrollbar-track {
    background: transparent;
    margin-block: 4px;
}
.app-sidebar .nav-list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.28);
    border-radius: 999px;
}
.app-sidebar .nav-list::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.55);
}
.app-sidebar .nav-list::-webkit-scrollbar-corner {
    background: transparent;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 8px 10px 18px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #fb7185);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 20px; color: #fff;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .06em; }

.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.nav-list .nav-section {
    margin: 16px 12px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}
.nav-list .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 9px;
    color: var(--sidebar-muted);
    font-size: 14.5px;
    font-weight: 500;
    transition: background .12s, color .12s;
}
.nav-list .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-list .nav-link.active { background: var(--primary); color: #fff; }
.nav-list .nav-link .nav-ico,
.nav-group-toggle .nav-ico {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .85;
}
.nav-list .nav-link.active .nav-ico { opacity: 1; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--sidebar-muted);
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    text-align: start;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.nav-group-toggle:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-group-toggle.has-active { color: #fff; }
.nav-group-label { flex: 1; min-width: 0; }
.nav-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: .7;
    transition: transform .18s ease;
}
.nav-group.is-open > .nav-group-toggle .nav-chevron { transform: rotate(180deg); }
html[dir="rtl"] .nav-group.is-open > .nav-group-toggle .nav-chevron { transform: rotate(-180deg); }

.nav-sub {
    list-style: none;
    margin: 0 0 4px;
    padding: 2px 0 4px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-inline-start: 1px solid rgba(255,255,255,.08);
    margin-inline-start: 20px;
}
.nav-sub-link {
    padding: 8px 10px !important;
    font-size: 13.5px !important;
    font-weight: 500 !important;
}
.nav-sub-link .nav-ico {
    width: 16px !important;
    height: 16px !important;
}

/* ---- Main ---- */
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
    height: 62px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
}
.topbar-scope { font-weight: 600; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.branch-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.branch-picker select {
    border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
    background: var(--input-bg); font-size: 13.5px; color: var(--text);
}

.chrome-toggles { display: flex; align-items: center; gap: 6px; }
.icon-chip {
    width: 36px; height: 36px; border-radius: 9px;
    border: 1px solid var(--border); background: var(--chip-bg); color: var(--text);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 0;
}
.icon-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.lang-chip { font-weight: 700; font-size: 13px; width: auto; min-width: 36px; padding: 0 10px; }

.user-chip { display: flex; flex-direction: column; align-items: end; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 14px; }
.user-role { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.btn-logout {
    border: 1px solid var(--border); background: var(--chip-bg); color: var(--text);
    padding: 8px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13.5px;
}
.btn-logout:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

.app-content { padding: 26px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; }
.page-sub { color: var(--muted); margin-top: 4px; font-size: 14px; }
.field-hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---- Cards / KPIs ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 18px 20px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); color: var(--text); }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; color: var(--text); }
.kpi-value.pos { color: var(--success); }
.kpi-value.neg { color: var(--primary); }

.dash-panels { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.dash-panel-title { margin: 0 0 10px; font-size: 14px; font-weight: 600; color: var(--text); }
@media (max-width: 960px) {
    .dash-panels { grid-template-columns: 1fr; }
}

/* ---- Tables ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
    text-align: start; padding: 12px 16px; background: var(--table-head); color: var(--muted);
    font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--row-hover); }
.num { text-align: end; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--success-soft); color: var(--success-text); }
.badge.gray { background: #e2e8f0; color: #475569; }
.badge.red { background: var(--primary-soft); color: var(--primary-dark); }
[data-theme="dark"] .badge.gray { background: #1f2a3d; color: #cbd5e1; }

/* ---- Buttons / forms ---- */
.btn {
    border: none; border-radius: 9px; padding: 9px 16px; font-weight: 600; cursor: pointer;
    font-size: 14px; background: var(--primary); color: #fff; transition: background .12s;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--chip-bg); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--table-head); }
.btn.danger { background: var(--primary); color: #fff; }
.btn.danger:hover { background: var(--primary-dark); }

/* Print: hide chrome when printing list pages */
@media print {
    .app-sidebar, .app-topbar, .btn-logout, .branch-picker, .chrome-toggles { display: none !important; }
    .app-shell { display: block; }
    .app-content { padding: 12px; }
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.form-grid-1 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (max-width: 960px) {
    .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
    .form-grid-4 { grid-template-columns: 1fr; }
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
    border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 14px;
    background: var(--input-bg); color: var(--text);
}
.field textarea { min-height: 72px; resize: vertical; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field input[readonly] { background: var(--surface-2, #f3f4f6); color: var(--muted); cursor: default; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }
.perm-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.perm-module { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; }

.alert { padding: 11px 14px; border-radius: 9px; font-size: 14px; margin: 12px 0; }
.alert.error { background: var(--primary-soft); color: var(--primary-dark); }
.alert.warn { background: #fef3c7; color: #92400e; }
.alert.info { background: #e0f2fe; color: #075985; }
[data-theme="dark"] .alert.warn { background: #422006; color: #fde68a; }
[data-theme="dark"] .alert.info { background: #0c4a6e; color: #bae6fd; }
.alert-success { background: var(--success-soft); color: var(--success-text); }
.muted { color: var(--muted); }
.spinner { color: var(--muted); padding: 20px; }

/* ---- Cloud Kitchen Display ---- */
.kds-page { padding: 8px 4px 24px; }
.kds-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.kds-toolbar h1 { margin: 0; font-size: 22px; }
.kds-sub { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.kds-toolbar-actions { display: flex; gap: 8px; align-items: center; }
.kds-toolbar-actions select { min-width: 160px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); }
.kds-empty { padding: 40px; text-align: center; color: var(--muted); }
.kds-recall { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border, #e2e8f0); }
.kds-recall h2 { margin: 0 0 10px; font-size: 1.05rem; }
.kds-recall-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.kds-recall-list li { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--surface, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 8px; }
.kds-recall-list .muted { color: var(--muted); font-size: 0.85rem; }
.kds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.kds-ticket { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; transition: box-shadow .2s, border-color .2s; }
.kds-ticket.age-warn { border-color: #d97706; box-shadow: 0 0 0 2px rgba(217,119,6,.25); }
.kds-ticket.age-critical { border-color: #dc2626; box-shadow: 0 0 0 2px rgba(220,38,38,.3); }
.kds-ticket.is-new { animation: kds-flash 1.2s ease 2; }
@keyframes kds-flash { 0%,100% { transform: scale(1); } 50% { transform: scale(1.02); box-shadow: 0 0 0 3px rgba(37,99,235,.35); } }
.kds-page.is-fullscreen { position: fixed; inset: 0; z-index: 80; background: var(--bg, #f8fafc); padding: 16px; overflow: auto; }
.kds-ticket header { display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px; background: #0f172a; color: #fff; font-size: 14px; }
.kds-guest-flags { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
.kds-vip { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: #92400e; background: #fef3c7; border-radius: 999px; padding: 2px 8px; }
.kds-allergy { font-size: 11px; font-weight: 700; color: #9f1239; background: #ffe4e6; border-radius: 999px; padding: 2px 8px; }
.kds-ticket ul { list-style: none; margin: 0; padding: 0; flex: 1; }
.kds-line { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.kds-line-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kds-line .qty { font-weight: 700; }
.kds-line .name { flex: 1; font-weight: 600; }
.kds-line .badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 999px; background: #e2e8f0; }
.kds-line.status-sent .badge { background: #fef3c7; color: #92400e; }
.kds-line.status-ready .badge { background: #dcfce7; color: #166534; }
.kds-line.status-served .badge { background: #dbeafe; color: #1e40af; }
.kds-line-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.kds-line-actions { margin-top: 8px; }
.kds-ticket footer { padding: 10px 14px; border-top: 1px solid var(--border); }

/* ---- Login ---- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 20% -10%, #1e293b, #0f172a); padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.35); padding: 34px 32px; position: relative; }
.login-chrome { position: absolute; inset-block-start: 14px; inset-inline-end: 14px; display: flex; gap: 6px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-title { font-size: 22px; font-weight: 700; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 12px; }

[dir="rtl"] .page-num,
[dir="rtl"] .sort-mark { font-variant-numeric: tabular-nums; }
