:root {
    --ink: #101010;
    --paper: #FFFFFF;
    --paper-2: #F6F6F4;
    --line: #E4E4E0;
    --line-strong: #C9C9C4;
    --muted: #6E6E68;
    --danger: #B3261E;
    --radius: 10px;
    /* --accent injected per-page from settings */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
    font-family: 'Manrope', system-ui, sans-serif;
    background: var(--paper-2);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.rail {
    width: 224px;
    flex-shrink: 0;
    background: var(--ink);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 28px 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    padding: 0 24px 28px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    line-height: 1.5;
}

.rail nav { flex: 1; padding-top: 16px; }

.rail nav a {
    display: block;
    color: rgba(255,255,255,0.62);
    text-decoration: none;
    font-weight: 600;
    font-size: 14.5px;
    padding: 12px 24px;
    border-left: 3px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.rail nav a:hover { color: #fff; }

.rail nav a.active {
    color: #fff;
    border-left-color: var(--accent);
    background: rgba(255,255,255,0.05);
}

.signout {
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    padding: 12px 24px;
}
.signout:hover { color: #fff; }

.main { flex: 1; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 32px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
}

.topbar h1 { font-size: 21px; }

.who { font-size: 14px; font-weight: 600; color: var(--muted); }

.role-pill {
    display: inline-block;
    margin-left: 6px;
    padding: 3px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink);
}

.content { padding: 28px 32px 60px; }

/* ---------- Panels, fields, buttons ---------- */
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
}

.panel-title { font-size: 16px; margin-bottom: 14px; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.panel-head .panel-title { margin-bottom: 0; }

.field { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 14px; }

.field input, .field select, .field textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    font: inherit;
    font-weight: 500;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 10px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.btn {
    font: inherit;
    font-weight: 700;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, #fff); }

.btn-block { width: 100%; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line-strong);
}

.table td { padding: 10px; border-bottom: 1px solid var(--line); }

.table td input { font: inherit; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; width: 100%; }

/* ---------- POS ---------- */
.pos-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}

.pos-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.client-pick { position: relative; }

.client-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--paper);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(16,16,16,0.10);
    z-index: 40;
    overflow: hidden;
}

.client-results button {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
}

.client-results button:last-child { border-bottom: 0; }
.client-results button:hover { background: var(--paper-2); }
.client-results .cr-phone { color: var(--muted); font-weight: 500; }
.client-results .cr-new { color: var(--accent); font-weight: 800; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    font-size: 13.5px;
    border-radius: 999px;
    padding: 6px 8px 6px 14px;
    margin-bottom: 14px;
}

.chip button {
    background: rgba(255,255,255,0.18);
    color: #fff;
    border: 0;
    border-radius: 999px;
    width: 20px; height: 20px;
    font-weight: 800;
    cursor: pointer;
    line-height: 1;
}

.tabs { display: flex; gap: 8px; margin: 6px 0 14px; }

.tab {
    font: inherit;
    font-weight: 700;
    font-size: 13.5px;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--paper);
    cursor: pointer;
}

.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.catalog {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.cat-item {
    font: inherit;
    text-align: left;
    background: var(--paper);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.cat-item:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 4%, #fff); }

.cat-item .ci-name { font-weight: 700; font-size: 14px; display: block; margin-bottom: 4px; }
.cat-item .ci-meta { font-size: 12.5px; color: var(--muted); font-weight: 600; }

.cart-panel { position: sticky; top: 20px; }

.cart-lines { min-height: 120px; margin-bottom: 12px; }

.cart-empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }

.cart-line {
    display: grid;
    grid-template-columns: 1fr 82px 28px;
    gap: 8px;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.cart-line .cl-name { font-weight: 700; font-size: 14px; }
.cart-line .cl-qty { font-size: 12.5px; color: var(--muted); font-weight: 600; cursor: pointer; }
.cart-line .cl-price {
    font: inherit;
    font-weight: 700;
    font-size: 14px;
    text-align: right;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 5px 6px;
    width: 100%;
}
.cart-line .cl-price:hover, .cart-line .cl-price:focus { border-color: var(--line-strong); outline: none; }

.cart-line .cl-x {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
    border-radius: 6px;
}
.cart-line .cl-x:hover { color: var(--danger); }

.cart-adjust { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 19px;
    font-weight: 800;
    padding: 14px 0;
    border-top: 2px solid var(--ink);
    margin-top: 4px;
}

.till-hint { font-size: 13px; color: var(--danger); margin-top: 10px; font-weight: 600; }
.till-hint a { color: inherit; }

/* ---------- Till ---------- */
.stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-label {
    display: block;
    font-size: 11.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    margin-bottom: 6px;
}

.stat-val { font-size: 20px; font-weight: 800; }
.stat-val.strong { color: var(--accent); }

.ovr-pos { color: #1F6B3A; font-weight: 800; }
.ovr-neg { color: var(--danger); font-weight: 800; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

.color-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }

.color-row input[type=color] {
    width: 52px; height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 3px;
    background: var(--paper);
    cursor: pointer;
}

.swatches { display: flex; gap: 8px; }

.swatch {
    width: 30px; height: 30px;
    border-radius: 999px;
    border: 2px solid var(--paper);
    outline: 1px solid var(--line-strong);
    cursor: pointer;
}
.swatch:hover { outline-color: var(--ink); }

/* ---------- Auth ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--ink);
}

.auth-card {
    width: 380px;
    background: var(--paper);
    border-radius: 14px;
    padding: 38px 34px;
}

.auth-mark {
    font-weight: 800;
    font-size: 17px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1.5;
}

.auth-sub { color: var(--muted); font-size: 13.5px; font-weight: 600; margin: 4px 0 24px; }

.auth-err {
    background: color-mix(in srgb, var(--danger) 8%, #fff);
    border: 1px solid color-mix(in srgb, var(--danger) 40%, #fff);
    color: var(--danger);
    font-size: 13.5px;
    font-weight: 700;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 16px;
}

/* ---------- Modal (custom, not native) ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16,16,16,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.14s ease;
    padding: 20px;
}

.modal {
    background: var(--paper);
    border-radius: 14px;
    width: 100%;
    max-width: 420px;
    padding: 26px;
    animation: popIn 0.16s ease;
}

.modal h3 { font-size: 17px; margin-bottom: 6px; }
.modal .modal-text { color: var(--muted); font-size: 14px; margin-bottom: 16px; line-height: 1.55; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }

.pay-m {
    font: inherit;
    font-weight: 700;
    padding: 12px 0;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--paper);
    cursor: pointer;
}
.pay-m.active { background: var(--accent); border-color: var(--accent); color: #fff; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96) translateY(6px); } }

/* ---------- Toast ---------- */
#toast-root {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    border-radius: 999px;
    padding: 11px 22px;
    animation: toastIn 0.18s ease;
    box-shadow: 0 10px 30px rgba(16,16,16,0.25);
}

.toast.toast-err { background: var(--danger); }

@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .pos-grid, .settings-grid { grid-template-columns: 1fr; }
    .cart-panel { position: static; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
}


@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------- SVG icons ---------- */
.ico { width: 19px; height: 19px; flex-shrink: 0; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-ico { color: var(--accent); display: flex; }
.brand-ico .ico { width: 22px; height: 22px; }

.rail nav a, .signout { display: flex; align-items: center; gap: 11px; }

.btn-ico { width: 16px; height: 16px; vertical-align: -3px; margin-left: 4px; }

.auth-logo {
    width: 52px; height: 52px;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
}
.auth-logo svg { width: 26px; height: 26px; }

.auth-card form { margin-top: 4px; }
.auth-card .btn-block { margin-top: 6px; display: flex; align-items: center; justify-content: center; }

/* ---------- Input icons + eye toggle ---------- */
.input-ico-wrap { position: relative; display: block; margin-top: 6px; }

.input-ico {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.input-ico-wrap input { margin-top: 0; padding-left: 40px; padding-right: 42px; }

.input-ico-wrap input:focus ~ .input-ico { color: var(--accent); }

.eye-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 0;
    padding: 6px;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    border-radius: 6px;
}
.eye-btn:hover { color: var(--ink); }

/* ---------- Admin panel ---------- */
.nav-group {
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.35);
    padding: 16px 24px 6px;
}

.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

.badge {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 999px;
}
.badge-on { background: color-mix(in srgb, var(--accent) 12%, #fff); color: var(--accent); }
.badge-off { background: var(--paper-2); color: var(--muted); }

.btn-sm { padding: 6px 12px; font-size: 13px; margin-left: 6px; }
.row-act { text-align: right; white-space: nowrap; }

.modal-check { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; margin: 12px 0 4px; cursor: pointer; }
.modal-check input { width: 17px; height: 17px; accent-color: var(--accent); }

.rep-controls { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.rep-date { margin-bottom: 0; }
.rep-controls .tab { margin-bottom: 2px; }

@media (max-width: 1000px) {
    .dash-cols { grid-template-columns: 1fr; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Admin panel ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.head-tools { display: flex; align-items: center; gap: 10px; }

.search-input {
    font: inherit; font-weight: 500;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 9px 12px;
    width: 230px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.row-link { cursor: pointer; }
.row-link:hover td { background: var(--paper-2); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.sub-title { font-size: 13.5px; margin: 16px 0 8px; }

.note-item { border-left: 3px solid var(--accent); padding: 8px 12px; margin-bottom: 8px; background: var(--paper-2); border-radius: 0; }
.note-text { font-weight: 600; font-size: 14px; }
.note-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.note-add { display: grid; grid-template-columns: 130px 1fr auto; gap: 8px; margin-top: 12px; }
.note-add select, .note-add input {
    font: inherit; font-weight: 500;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 9px 10px;
}

.rep-controls { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; }
.rep-controls .field { margin-bottom: 0; }
.rep-quick { display: flex; gap: 8px; padding-bottom: 2px; }

@media (max-width: 1000px) {
    .dash-grid { grid-template-columns: 1fr; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .note-add { grid-template-columns: 1fr; }
}

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 240px; margin-bottom: 14px; }
.chart-box.chart-wide { height: 260px; margin-bottom: 0; }
.chart-box.chart-donut { height: 220px; }

/* ---------- Responsive hardening ---------- */
/* Stats: flow to available width instead of fixed 4 columns (reports has 5) */
.stat-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* Tables scroll sideways inside their panel instead of breaking the page */
.panel { overflow-x: auto; }
.table { min-width: 480px; }
#movements.table, #till-history.table { min-width: 520px; }

@media (max-width: 1000px) {
    .content { padding: 22px 20px 50px; }
    .catalog { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

@media (max-width: 720px) {

    .topbar { padding: 14px 16px; }
    .topbar h1 { font-size: 18px; }
    .who { font-size: 12.5px; }
    .role-pill { display: none; }

    .stat-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat { padding: 12px 14px; }
    .stat-val { font-size: 17px; }

    .panel { padding: 16px; }
    .panel-head { flex-wrap: wrap; gap: 10px; }
    .head-tools { flex-wrap: wrap; width: 100%; }
    .search-input { width: 100%; }

    .rep-controls { flex-direction: column; align-items: stretch; }
    .rep-quick { flex-wrap: wrap; }

    .chart-box { height: 200px; }
    .chart-box.chart-wide { height: 210px; }
    .chart-box.chart-donut { height: 240px; }

    .cart-adjust { grid-template-columns: 1fr 1fr; }
    .pos-row { grid-template-columns: 1fr; }
    .catalog { grid-template-columns: repeat(auto-fill, minmax(46%, 1fr)); gap: 8px; }
    .cat-item { padding: 11px 12px; }

    .modal { max-width: none; padding: 20px; }
    .modal-overlay { padding: 12px; align-items: flex-end; }
    .modal { animation-name: sheetIn; border-radius: 14px 14px 0 0; max-height: 86vh; overflow-y: auto; }

    .table { font-size: 13px; }
    .table th, .table td { padding: 8px 8px; }
    .row-actions { flex-wrap: wrap; justify-content: flex-start; }
}

@keyframes sheetIn { from { opacity: 0; transform: translateY(24px); } }

@media (max-width: 400px) {
    .stat-row { grid-template-columns: 1fr 1fr; }
    .cart-line { grid-template-columns: 1fr 72px 24px; }
}


/* ---------- Mobile drawer nav ---------- */
.nav-toggle {
    display: none;
    background: none;
    border: 0;
    color: var(--ink);
    padding: 6px;
    margin-right: 4px;
    cursor: pointer;
    border-radius: 8px;
}
.nav-toggle:hover { background: var(--paper-2); }

.rail-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16,16,16,0.45);
    z-index: 59;
}

@media (max-width: 720px) {
    .nav-toggle { display: flex; }
    .topbar { gap: 4px; }
    .topbar h1 { flex: 1; }

    .rail {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        height: 100vh;
        width: 240px;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: none;
    }
    body.nav-open .rail { transform: translateX(0); box-shadow: 12px 0 40px rgba(16,16,16,0.3); }
    body.nav-open .rail-overlay { display: block; }
    body.nav-open { overflow: hidden; }

    .content { padding: 18px 16px 50px; }
    .pos-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .rail { transition: none; }
}

.rep-dl { margin-left: auto; display: inline-flex; align-items: center; }
@media (max-width: 720px) { .rep-dl { margin-left: 0; width: 100%; justify-content: center; } }