/* =====================================================================
   POSnCRM — Banking-grade UI system
   Mobile-first, system fonts, tabular numbers, accessible contrast.
   ===================================================================== */

:root {
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --border:        #e2e8f0;
    --border-2:      #cbd5e1;

    --text:          #0f172a;
    --text-muted:    #475569;
    --text-subtle:   #94a3b8;

    --primary:       #1e40af; /* Corporate Blue */
    --primary-700:   #1e3a8a;
    --primary-50:    #eff6ff;

    --success:       #059669; /* Trust Green */
    --success-50:    #ecfdf5;
    --danger:        #dc2626; /* Warning Red */
    --danger-50:     #fef2f2;
    --warning:       #d97706;
    --warning-50:    #fffbeb;
    --info:          #0284c7;
    --info-50:       #f0f9ff;

    --sidebar-bg:    #0f172a; /* Midnight Blue */
    --sidebar-hover: #1e293b;
    --sidebar-text:  #f8fafc;
    --sidebar-muted: #94a3b8;

    --radius:        12px;
    --radius-sm:     8px;
    --shadow-sm:     0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow:        0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg:     0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --topbar-h:      64px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.2rem; margin-bottom: 0; }
h5 { font-size: 1rem; }
h6 { font-size: .9rem; }

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

code { color: var(--primary-700); background: var(--primary-50); padding: 1px 6px; border-radius: 4px; font-size: .85em; }

/* ----- Tabular numbers everywhere money or counts appear ----- */
.money, .table .money, .num, td.money, th.money {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
    text-align: right;
    white-space: nowrap;
}

/* ============ TOPBAR ============ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    box-shadow: var(--shadow-sm);
}
.topbar .brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -.01em;
}
.topbar .brand i { color: var(--primary); font-size: 1.3rem; }
.topbar .brand:hover { text-decoration: none; color: var(--text); }

.topbar .toggle-sidebar {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-muted);
}
.topbar .toggle-sidebar:hover { color: var(--text); background: var(--surface-2); }

.topbar .user-menu .username {
    color: var(--text);
    font-weight: 500;
    font-size: .9rem;
}
.topbar .user-menu .role-badge {
    font-size: .7rem;
    background: var(--info-50);
    color: var(--info);
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-left: 6px;
    font-weight: 600;
}

/* ============ LAYOUT (sidebar + content) ============ */
.app-shell {
    display: flex;
    min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-bg);
    padding: 16px 0;
    overflow-y: auto;
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    color: var(--sidebar-text);
}
.sidebar .nav-section {
    padding: 12px 20px 6px;
    font-size: .65rem;
    color: var(--sidebar-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 700;
}
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--sidebar-muted);
    border-radius: 0;
    font-size: .92rem;
    font-weight: 500;
    border-left: 4px solid transparent;
    transition: all .15s ease-in-out;
}
.sidebar .nav-link:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
    text-decoration: none;
}
.sidebar .nav-link.active {
    color: #ffffff;
    background: rgba(255,255,255,0.05);
    border-left-color: var(--primary);
}
.sidebar .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.content {
    flex: 1;
    padding: 20px;
    min-width: 0;
}

/* Mobile sidebar = offcanvas */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: var(--topbar-h) 0 0 0;
        background: rgba(15,23,42,.4);
        z-index: 1035;
    }
    .sidebar-backdrop.open { display: block; }
    .content { padding: 16px 12px; }
}

@media (min-width: 992px) {
    .topbar .toggle-sidebar { display: none; }
}

/* ============ PAGE HEADER ============ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-header h1, .page-header h2, .page-header h3 { margin: 0; line-height: 1.2; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-header .subtitle { color: var(--text-muted); font-size: .85rem; margin-top: 2px; }

/* ============ CARDS ============ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    font-weight: 600;
    font-size: .9rem;
    color: var(--text);
}
.card .card-body { padding: 16px; }

/* ============ KPI / STAT TILES ============ */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 96px;
    transition: transform .12s, box-shadow .12s;
}
.stat:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.stat .label {
    font-size: .72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    display: flex; align-items: center; gap: 6px;
}
.stat .label i { font-size: .9rem; opacity: .7; }
.stat .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
}
.stat .delta { font-size: .8rem; color: var(--text-muted); }
.stat.positive .value { color: var(--success); }
.stat.negative .value { color: var(--danger); }
.stat.muted .value { color: var(--text-muted); }

@media (max-width: 575.98px) {
    .stat { padding: 12px; min-height: auto; }
    .stat .value { font-size: 1.2rem; }
}

/* ============ TABLES ============ */
.table {
    margin: 0;
    color: var(--text);
    font-size: .88rem;
}
.table > :not(caption) > * > * { padding: 11px 12px; vertical-align: middle; }
.table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table-hover tbody tr:hover { background: var(--surface-2); }
.table tfoot th, .table tfoot td {
    background: var(--surface-2);
    border-top: 1px solid var(--border-2);
    font-weight: 600;
}

.table .row-void { color: var(--text-subtle); text-decoration: line-through; }

/* Mobile-friendly: hide low-priority columns on small screens */
@media (max-width: 767.98px) {
    .table > :not(caption) > * > * { padding: 9px 8px; }
    .table { font-size: .82rem; }
    .hide-sm { display: none !important; }
}
@media (max-width: 991.98px) {
    .hide-md { display: none !important; }
}

/* Force horizontal scroll on tables that have many columns */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive > .table { margin-bottom: 0; }

/* ============ BADGES ============ */
.badge {
    font-weight: 600;
    font-size: .72rem;
    letter-spacing: .04em;
    padding: 4px 9px;
    border-radius: 999px;
    text-transform: uppercase;
}
.badge.bg-success { background: var(--success-50) !important; color: var(--success) !important; }
.badge.bg-danger  { background: var(--danger-50)  !important; color: var(--danger)  !important; }
.badge.bg-warning { background: var(--warning-50) !important; color: var(--warning) !important; }
.badge.bg-info    { background: var(--info-50)    !important; color: var(--info)    !important; }
.badge.bg-primary { background: var(--primary-50) !important; color: var(--primary) !important; }
.badge.bg-secondary { background: #e9edf3 !important; color: var(--text-muted) !important; }
.badge.bg-dark    { background: #1f2937 !important; color: #fff !important; }

/* ============ FORMS ============ */
.form-label { font-weight: 500; color: var(--text); font-size: .85rem; margin-bottom: 4px; }
.form-label.small { font-size: .75rem; color: var(--text-muted); }
.form-control, .form-select {
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: .9rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color .12s, box-shadow .12s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, .15);
    outline: none;
}
.form-control-sm, .form-select-sm { padding: 6px 8px; font-size: .85rem; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-label { font-size: .88rem; }

/* Touch targets ≥ 44px on mobile */
@media (max-width: 767.98px) {
    .form-control, .form-select { min-height: 42px; font-size: 16px; } /* 16px prevents iOS zoom */
    .form-control-sm, .form-select-sm { min-height: 38px; font-size: 14px; }
}

/* ============ BUTTONS ============ */
.btn {
    font-weight: 500;
    font-size: .88rem;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: background-color .12s, border-color .12s, color .12s, transform .05s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-lg { padding: 11px 18px; font-size: 1rem; }
.btn i { font-size: 1em; }
@media (max-width: 767.98px) {
    .btn { min-height: 40px; }
    .btn-sm { min-height: 34px; }
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #065f46; border-color: #065f46; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { background: #92400e; border-color: #92400e; color: #fff; }

.btn-outline-primary { color: var(--primary); border-color: var(--border-2); background: var(--surface); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-outline-secondary { color: var(--text-muted); border-color: var(--border-2); background: var(--surface); }
.btn-outline-secondary:hover { background: var(--surface-2); border-color: var(--border-2); color: var(--text); }
.btn-outline-success { color: var(--success); border-color: var(--success); background: var(--surface); }
.btn-outline-success:hover { background: var(--success); border-color: var(--success); color: #fff; }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-outline-warning { color: var(--warning); border-color: var(--warning); background: var(--surface); }
.btn-outline-warning:hover { background: var(--warning); border-color: var(--warning); color: #fff; }

/* ============ ALERTS ============ */
.alert {
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: .88rem;
    margin-bottom: 14px;
}
.alert-success { background: var(--success-50); color: var(--success); border-color: #a7f3d0; }
.alert-danger  { background: var(--danger-50);  color: var(--danger);  border-color: #fecaca; }
.alert-warning { background: var(--warning-50); color: var(--warning); border-color: #fde68a; }
.alert-info    { background: var(--info-50);    color: var(--info);    border-color: #bae6fd; }

/* ============ TABS ============ */
.nav-tabs { border-bottom: 1px solid var(--border); }
.nav-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 10px 16px;
    font-weight: 500;
    font-size: .9rem;
}
.nav-tabs .nav-link:hover { color: var(--text); border-bottom-color: var(--border-2); }
.nav-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}
.tab-content.card { border-top-left-radius: 0; }

/* ============ CHARTS CONTAINER ============ */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-bottom: 16px;
}
.chart-card .chart-title {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chart-card canvas { max-height: 280px; }
@media (max-width: 767.98px) { .chart-card canvas { max-height: 220px; } }

/* ============ DROPDOWNS ============ */
.dropdown-menu {
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius-sm);
    padding: 6px;
    min-width: 200px;
}
.dropdown-item {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .88rem;
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--text); }
.dropdown-divider { border-color: var(--border); margin: 4px 0; }

/* ============ EMPTY STATES ============ */
.empty-state {
    text-align: center;
    padding: 36px 20px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 2rem;
    color: var(--text-subtle);
    display: block;
    margin-bottom: 8px;
}

/* ============ ACTION BUTTON GROUPS IN TABLES ============ */
td .btn-actions { display: inline-flex; gap: 4px; flex-wrap: nowrap; }
td .btn-actions .btn { padding: 4px 8px; }

/* ============ STICKY TABLE HEAD ============ */
.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 5;
}

/* ============ POS CART (sales/create) ============ */
.pos-grid { display: grid; gap: 16px; grid-template-columns: 1fr 360px; }
@media (max-width: 991.98px) { .pos-grid { grid-template-columns: 1fr; } }
.pos-cart-summary {
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
    align-self: start;
}
.pos-cart-summary table tr th, .pos-cart-summary table tr td { padding: 6px 0; border: none; }
.pos-cart-summary table tr.grand th, .pos-cart-summary table tr.grand td {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    font-size: 1.1rem;
}

/* ============ FOOTER ============ */
.footer {
    text-align: center;
    color: var(--text-subtle);
    font-size: .75rem;
    padding: 16px;
    margin-top: 20px;
}

/* ============ LOGIN ============ */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
      radial-gradient(800px 400px at 20% 30%, rgba(26, 86, 219, .14), transparent 60%),
      radial-gradient(900px 500px at 80% 70%, rgba(4, 120, 87, .10), transparent 60%),
      #f4f6fb;
    padding: 24px 16px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .08);
    padding: 28px;
}
.login-card .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.login-card .brand i { color: var(--primary); }
.login-card .subtitle { color: var(--text-muted); font-size: .88rem; margin-bottom: 22px; }
.login-card .form-control { padding: 11px 12px; font-size: .95rem; }

/* ============ PRINT ============ */
@media print {
    .no-print, .topbar, .sidebar, .footer, .actions, .alert { display: none !important; }
    body { background: #fff !important; font-size: 11pt; }
    .app-shell { display: block !important; min-height: auto; }
    .content { padding: 0 !important; }
    .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
    a { color: var(--text) !important; text-decoration: none !important; }
}
