/* =========================================================
   Sanitary POS — global styles. One file, no preprocessor.
   Design language: dark sidebar, white workspace, indigo accents.
   ========================================================= */

:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --sidebar: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #2563eb;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
    --shadow: 0 4px 12px rgba(15,23,42,.08);
    --shadow-lg: 0 12px 32px rgba(15,23,42,.12);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ----- Layout shell ----- */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky; top: 0;
    height: 100vh;
}
.sidebar .brand {
    padding: 20px 20px 14px;
    font-weight: 700; font-size: 18px;
    color: #fff;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid #1e293b;
}
.sidebar .brand-mark {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, #2563eb, #06b6d4);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700;
}
.sidebar nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    color: #cbd5e1;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s ease;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .sidebar-foot {
    padding: 16px;
    border-top: 1px solid #1e293b;
    color: #94a3b8;
    font-size: 12px;
}
.sidebar .user-chip {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px;
}
.sidebar .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}

.workspace { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .net-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    background: #ecfdf5; color: #047857; font-size: 12px; font-weight: 600;
}
.topbar .net-pill.offline { background: #fef2f2; color: #b91c1c; }
.topbar .net-pill .dot {
    width: 8px; height: 8px; border-radius: 50%; background: currentColor;
}
.topbar .sync-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    background: #eff6ff; color: var(--primary); font-size: 12px; font-weight: 600;
    cursor: pointer;
}
.topbar .sync-pill[hidden] { display: none !important; }

.main { padding: 22px; flex: 1; overflow: auto; }

/* ----- Cards & panels ----- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }
.card-head {
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

/* ----- Buttons ----- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-ghost   { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ----- Forms ----- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
input, select, textarea {
    width: 100%;
    font: inherit;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea { resize: vertical; min-height: 80px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ----- Tables ----- */
.table-wrap { overflow-x: auto; }
table.t {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
table.t th, table.t td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
table.t th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .04em;
    position: sticky; top: 0;
}
table.t tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.muted { color: var(--text-muted); }
.badge {
    display: inline-block; padding: 3px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #047857; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-muted   { background: #e2e8f0; color: #475569; }

/* ----- Stat cards (dashboard) ----- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px;
    display: flex; flex-direction: column; gap: 6px;
    position: relative; overflow: hidden;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-card .sub { font-size: 12px; color: var(--text-muted); }
.stat-card.accent-blue::after, .stat-card.accent-green::after,
.stat-card.accent-orange::after, .stat-card.accent-red::after {
    content: ''; position: absolute; top: 0; left: 0; height: 4px; width: 100%;
}
.stat-card.accent-blue::after { background: var(--primary); }
.stat-card.accent-green::after { background: var(--success); }
.stat-card.accent-orange::after { background: var(--warning); }
.stat-card.accent-red::after { background: var(--danger); }

/* ----- Modal ----- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.55);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff; border-radius: var(--radius);
    width: 100%; max-width: 560px;
    max-height: 92vh; overflow: auto;
    box-shadow: var(--shadow-lg);
}
.modal.lg { max-width: 900px; }
.modal-head {
    padding: 16px 22px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .x {
    margin-left: auto;
    background: none; border: none; cursor: pointer;
    font-size: 22px; color: var(--text-muted); padding: 0 6px;
}
.modal-body { padding: 22px; }
.modal-foot {
    padding: 14px 22px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ----- Toast ----- */
#toast-root {
    position: fixed; top: 20px; right: 20px; z-index: 1000;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: var(--text); color: #fff;
    padding: 12px 18px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px; font-weight: 500;
    min-width: 220px; max-width: 360px;
    animation: tslide .25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warning); }
@keyframes tslide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----- Login page ----- */
.login-shell {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%; max-width: 400px;
    padding: 36px 32px;
}
.login-card .brand {
    text-align: center; margin-bottom: 28px;
}
.login-card .brand-mark {
    width: 56px; height: 56px; border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #06b6d4);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 22px; margin-bottom: 12px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { color: var(--text-muted); font-size: 13px; }

/* ===========================================================
   POS-specific layout
   =========================================================== */
.pos-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 16px;
    height: calc(100vh - 60px);
    padding: 16px;
}
@media (max-width: 1100px) {
    .pos-layout { grid-template-columns: 1fr; height: auto; }
    .pos-cart { position: sticky; bottom: 0; }
}
.pos-products { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.pos-search {
    display: flex; gap: 8px; align-items: center;
    background: #fff; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.pos-search input { border: none; padding: 4px 6px; font-size: 15px; }
.pos-search input:focus { box-shadow: none; }
.pos-cats {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 6px 0;
}
.pos-cats .chip {
    padding: 6px 12px; border-radius: 999px;
    background: #fff; border: 1px solid var(--border);
    cursor: pointer; font-size: 12px; font-weight: 600;
}
.pos-cats .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding: 4px;
    flex: 1;
}
.product-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all .15s ease;
    display: flex; flex-direction: column; gap: 6px;
    user-select: none;
    position: relative;
}
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.product-card .pname {
    font-weight: 600; font-size: 13px;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    min-height: 36px;
}
.product-card .pprice { color: var(--primary); font-weight: 700; font-size: 14px; }
.product-card .pstock {
    font-size: 11px;
    color: var(--text-muted);
}
.product-card.low .pstock { color: var(--danger); font-weight: 600; }
.product-card.out { opacity: .55; pointer-events: none; }

.pos-cart {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex; flex-direction: column;
    overflow: hidden;
    height: 100%;
}
.pos-cart-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
}
.pos-cart-head h2 { margin: 0; font-size: 15px; }
.pos-cart-items {
    flex: 1; overflow-y: auto; padding: 8px;
}
.cart-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}
.cart-item:hover { background: #f8fafc; }
.cart-item .ci-name { font-weight: 600; font-size: 13px; }
.cart-item .ci-meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.cart-item .ci-total { font-weight: 700; align-self: center; white-space: nowrap; }
.qty-ctrl { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; }
.qty-ctrl button {
    width: 26px; height: 26px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 4px; cursor: pointer;
    font-weight: 700;
}
.qty-ctrl input {
    width: 50px; text-align: center; padding: 3px;
}
.cart-empty {
    padding: 60px 20px;
    text-align: center; color: var(--text-muted);
}

.cart-totals { padding: 12px 16px; border-top: 1px solid var(--border); background: #f8fafc; }
.cart-totals .row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.cart-totals .row.grand { font-size: 18px; font-weight: 700; padding-top: 8px; border-top: 1px dashed var(--border); margin-top: 4px; }

.cart-actions { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.cart-actions .pay-row { display: flex; gap: 6px; }
.cart-actions .pay-row .btn { flex: 1; }
.pay-methods { display: flex; gap: 6px; }
.pay-methods .chip {
    flex: 1; padding: 8px; text-align: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; font-weight: 600; font-size: 12px;
}
.pay-methods .chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Receipt (80mm thermal) */
.receipt-paper {
    width: 72mm;       /* 80mm minus side margins */
    margin: 0 auto;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 12px;
    color: #000;
    line-height: 1.35;
}
.receipt-paper h2, .receipt-paper h3, .receipt-paper p { margin: 0; }
.receipt-paper .center { text-align: center; }
.receipt-paper .row { display: flex; justify-content: space-between; }
.receipt-paper .sep { border-top: 1px dashed #000; margin: 6px 0; }
.receipt-paper table { width: 100%; border-collapse: collapse; font-size: 11px; }
.receipt-paper table td { padding: 2px 0; vertical-align: top; }

@media print {
    @page { size: 80mm auto; margin: 4mm; }
    body * { visibility: hidden; }
    .receipt-paper, .receipt-paper * { visibility: visible; }
    .receipt-paper {
        position: absolute; left: 0; top: 0; width: 72mm;
    }
    .no-print { display: none !important; }
}

/* ----- Misc utilities ----- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.w-100 { width: 100%; }
.hidden { display: none !important; }
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #cbd5e1; border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile: collapse sidebar to top bar */
@media (max-width: 768px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        height: auto; position: relative;
        flex-direction: row; align-items: center;
        padding: 8px;
    }
    .sidebar nav {
        display: flex; gap: 4px; padding: 0 8px;
        flex-wrap: nowrap; overflow-x: auto;
    }
    .sidebar nav a { padding: 8px 10px; font-size: 12px; white-space: nowrap; }
    .sidebar .sidebar-foot { display: none; }
    .sidebar .brand { padding: 8px 12px; border: none; }
}
