:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --accent: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-bg: #0f172a;
    --sidebar-surface: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-width: 248px;
    --sidebar-collapsed: 72px;
    --radius: 12px;
    --shadow: 0 4px 18px -2px rgba(15, 23, 42, 0.07);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 13.5px;
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
}

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

/* App Shell & Collapsible Scrollable Sidebar */
.pos-shell {
    display: flex;
    min-height: 100vh;
}

.pos-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #111c36 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transition: width 0.22s ease, transform 0.25s ease;
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 62px;
}

.brand-logo-wrap {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 9px;
    overflow: hidden;
    background: linear-gradient(135deg, #4f46e5, #06b6d4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-logo-img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.brand-logo-fallback { color: #fff; font-weight: 800; font-size: 12px; letter-spacing: 0.5px; }

.brand-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-weight: 700;
    color: #fff;
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-role-pill {
    display: inline-block;
    width: fit-content;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 1px 7px;
    border-radius: 999px;
    margin-top: 2px;
}
.role-superadmin { background: rgba(168, 85, 247, 0.25); color: #d8b4fe; }
.role-admin { background: rgba(14, 165, 233, 0.25); color: #7dd3fc; }
.role-user { background: rgba(16, 185, 129, 0.25); color: #6ee7b7; }

.sidebar-collapse-btn {
    background: rgba(255,255,255,0.08);
    border: none;
    color: #cbd5e1;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, background 0.2s ease;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.16); color: #fff; }
.sidebar-collapse-btn svg { width: 15px; height: 15px; }

/* Scrollable Menu Section */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 10px 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.35); border-radius: 4px; }

.nav-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 10px 10px 4px;
    white-space: nowrap;
}

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8.5px 11px;
    border-radius: 9px;
    color: #cbd5e1;
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
    transition: all 0.16s ease;
    white-space: nowrap;
}

.nav-link-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link-item.active {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    box-shadow: 0 4px 12px rgba(79,70,229,0.4);
}

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 18px; height: 18px; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 10px 12px;
}

.user-card { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 8px;
    background: #334155; color: #fff; font-weight: 700; font-size: 13px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: #f8fafc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 11px; color: #94a3b8; }

/* Collapsed Sidebar State on Desktop */
.pos-shell.sidebar-collapsed .pos-sidebar { width: var(--sidebar-collapsed); }
.pos-shell.sidebar-collapsed .pos-main { margin-left: var(--sidebar-collapsed); }
.pos-shell.sidebar-collapsed .brand-text,
.pos-shell.sidebar-collapsed .nav-title,
.pos-shell.sidebar-collapsed .nav-group-label,
.pos-shell.sidebar-collapsed .user-meta { display: none; }
.pos-shell.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 12px 8px; }
.pos-shell.sidebar-collapsed .brand-logo-wrap { display: none; }
.pos-shell.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.pos-shell.sidebar-collapsed .nav-link-item { justify-content: center; padding: 10px; }
.pos-shell.sidebar-collapsed .user-card { justify-content: center; }

/* Main Area */
.pos-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.22s ease;
}

.pos-topbar {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.page-heading {
    margin: 0;
    font-size: 16.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Right-Top User, Password & Logout Dropdown */
.topbar-user-wrap { position: relative; }
.topbar-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 5px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    color: var(--text);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.topbar-user-btn:hover { border-color: var(--primary); background: var(--surface-muted); }

.topbar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: linear-gradient(135deg, #4f46e5, #0ea5e9);
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topbar-user-text { display: flex; flex-direction: column; text-align: left; line-height: 1.15; }
.topbar-user-name { font-size: 12px; font-weight: 700; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user-role { font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.topbar-caret { width: 14px; height: 14px; color: var(--text-muted); }

.topbar-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    width: 215px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
    padding: 6px;
    z-index: 60;
}
.topbar-user-dropdown.open { display: block; }

.dropdown-user-info {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
}
.dropdown-user-info strong { font-size: 13px; color: var(--text); }
.dropdown-user-info span { font-size: 11px; color: var(--text-muted); }

.dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.dropdown-item:hover { background: var(--surface-muted); }
.dropdown-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.dropdown-logout { color: var(--danger); }
.dropdown-logout:hover { background: #fef2f2; }

.mobile-menu-trigger {
    display: none;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.mobile-menu-trigger svg { width: 19px; height: 19px; }

.firm-select {
    padding: 6px 9px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12.5px;
    font-weight: 600;
    max-width: 170px;
}

.pos-content {
    padding: 18px 20px 32px;
    flex: 1;
}

/* Cards, Buttons, Tables, Forms */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 15px; font-weight: 700; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8.5px 15px;
    border-radius: 9px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 36px;
}
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; min-height: 30px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-muted); }

.grid { display: grid; gap: 14px; }
.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)); }
.col-span-2 { grid-column: span 2; }

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.kpi-card::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}
.kpi-card.kpi-green::after { background: linear-gradient(90deg, #10b981, #34d399); }
.kpi-card.kpi-amber::after { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.kpi-card.kpi-purple::after { background: linear-gradient(90deg, #8b5cf6, #ec4899); }
.kpi-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 22px; font-weight: 800; margin: 5px 0 2px; color: var(--text); }
.kpi-hint { font-size: 11.5px; color: var(--text-muted); }

.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: #334155; margin-bottom: 4px; }
.form-control {
    width: 100%;
    padding: 8.5px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13.5px;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.14);
}
.text-danger { color: var(--danger); font-size: 12px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.pos-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
table.pos-table th {
    text-align: left;
    padding: 9px 10px;
    background: var(--surface-muted);
    border-bottom: 2px solid var(--border);
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    white-space: nowrap;
}
table.pos-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.pos-table tr:hover td { background: #f8fafc; }
.text-right { text-align: right !important; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

.alert {
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-weight: 600;
    font-size: 12.5px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Mobile Bottom Nav (App-Style Docked Tab Bar) */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding: 4px 6px env(safe-area-inset-bottom, 0px);
    background: rgba(15, 23, 42, 0.97);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 50;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -6px 24px rgba(15,23,42,0.28);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 600;
    background: none;
    border: none;
    padding: 5px 8px;
    border-radius: 10px;
    cursor: pointer;
    min-width: 54px;
}
.mobile-nav-item.active { color: #38bdf8; background: rgba(56,189,248,0.14); }
.mobile-nav-icon { width: 19px; height: 19px; display: flex; }
.mobile-nav-icon svg { width: 19px; height: 19px; }
.mobile-nav-label { max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-backdrop { display: none; }

/* Login Page with Products, POS Barcode & Billing Background */
.pos-auth-body {
    min-height: 100vh;
    background: #0b1120;
    color: #fff;
    overflow-x: hidden;
}

.login-stage {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    overflow: hidden;
    background:
        radial-gradient(circle at 12% 18%, rgba(14, 165, 233, 0.28), transparent 42%),
        radial-gradient(circle at 86% 20%, rgba(99, 102, 241, 0.30), transparent 44%),
        radial-gradient(circle at 75% 88%, rgba(16, 185, 129, 0.22), transparent 42%),
        linear-gradient(145deg, #070d19 0%, #0f172a 52%, #172554 100%);
}

.login-grid-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.08) 1px, transparent 1px);
    background-size: 38px 38px;
    mask-image: radial-gradient(circle at center, rgba(0,0,0,0.85), transparent 85%);
}

.login-shell {
    position: relative;
    z-index: 5;
    width: 100%;
    max-width: 960px;
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 24px;
    align-items: center;
}

.login-showcase { padding: 10px 4px; }

.showcase-eyebrow {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: rgba(56, 189, 248, 0.16);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.3);
    margin-bottom: 12px;
}

.showcase-title {
    margin: 0 0 10px;
    font-size: 28px;
    line-height: 1.18;
    font-weight: 800;
    color: #f8fafc;
}

.showcase-desc {
    margin: 0 0 20px;
    font-size: 13.5px;
    color: #cbd5e1;
    max-width: 460px;
}

.showcase-tiles { display: flex; flex-direction: column; gap: 10px; }

.showcase-tile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 13px;
    background: rgba(15, 23, 42, 0.68);
    border: 1px solid rgba(148, 163, 184, 0.22);
    backdrop-filter: blur(10px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25);
}

.tile-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tile-icon svg { width: 20px; height: 20px; }
.tile-icon-products { background: rgba(99, 102, 241, 0.24); color: #a5b4fc; }
.tile-icon-barcode { background: rgba(236, 72, 153, 0.22); color: #f9a8d4; }
.tile-icon-billing { background: rgba(16, 185, 129, 0.22); color: #6ee7b7; }

.tile-body { flex: 1; min-width: 0; }
.tile-title { font-size: 13.5px; font-weight: 700; color: #f8fafc; }
.tile-sub { font-size: 11.5px; color: #94a3b8; }

.tile-badge {
    font-size: 10.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px;
    background: rgba(99, 102, 241, 0.24); color: #c7d2fe;
}
.tile-badge-green { background: rgba(16, 185, 129, 0.24); color: #6ee7b7; }
.tile-mini-qr { width: 34px; height: 34px; flex-shrink: 0; border-radius: 5px; }

.scan-beam {
    height: 2px;
    margin-top: 5px;
    background: linear-gradient(90deg, transparent, #f43f5e, #fb7185, transparent);
    box-shadow: 0 0 10px #f43f5e;
    animation: scanPulse 2.2s ease-in-out infinite;
}
@keyframes scanPulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 1; }
}

.login-card {
    position: relative;
    z-index: 5;
    width: 100%;
    max-width: 410px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
    border-radius: 18px;
    padding: 26px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255,255,255,0.5);
}

.login-demo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.demo-pill {
    padding: 7px 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
}
.demo-pill:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* Responsive Breakpoints (Tablet & Mobile App View) */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .col-span-2 { grid-column: span 1 !important; }
}

@media (max-width: 768px) {
    html, body { font-size: 13px; }
    .pos-sidebar {
        transform: translateX(-100%);
        width: 256px !important;
    }
    .pos-shell.mobile-sidebar-open .pos-sidebar { transform: translateX(0); }
    .pos-shell.mobile-sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 35;
    }
    .pos-main {
        margin-left: 0 !important;
        padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    }
    .pos-topbar {
        padding: 8px 12px;
        min-height: 52px;
    }
    .page-heading { font-size: 15px; }
    .firm-select { max-width: 115px; font-size: 11.5px; padding: 5px 6px; }
    .topbar-user-text { display: none; }
    .topbar-user-btn { padding: 3px 6px 3px 3px; }
    .mobile-menu-trigger { display: inline-flex; }
    .sidebar-collapse-btn { display: none; }
    .mobile-bottom-nav { display: flex; }
    .topbar-pos-cta { display: none; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; gap: 12px; }
    .col-span-2 { grid-column: span 1 !important; }
    .pos-content { padding: 12px; }
    .card { padding: 14px; border-radius: 14px; margin-bottom: 12px; }
    .card-title { font-size: 14px; }
    .kpi-card { padding: 13px; }
    .kpi-value { font-size: 20px; }
    .btn { padding: 8px 12px; font-size: 12.5px; }
    .form-control { font-size: 14px; padding: 9px 10px; }
    .login-shell { grid-template-columns: 1fr; gap: 16px; }
    .login-showcase { padding: 0; }
    .showcase-title { font-size: 21px; }
    .showcase-desc { display: none; }
    .showcase-tiles { display: none; }
    .login-card { padding: 20px; }
}

@media print {
    .no-print { display: none !important; }
}
