/* =====================================================
   Yeti Trade - Car Accessories Store Management System
   Main Stylesheet
   ===================================================== */

:root {
    --cz-primary: #E50914;
    --cz-primary-dark: #b8070f;
    --cz-navy: #101820;
    --cz-navy-light: #1a2530;
    --cz-white: #FFFFFF;
    --cz-bg: #F5F7FA;
    --cz-success: #16a34a;
    --cz-warning: #f59e0b;
    --cz-danger: #dc2626;
    --cz-info: #2563eb;
    --cz-border: #e5e9f0;
    --cz-text-muted: #6b7280;
    --sidebar-width: 260px;
    --sidebar-collapsed: 80px;
    --topbar-height: 64px;
}

* { box-sizing: border-box; }

body {
    background: var(--cz-bg);
    font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    color: #1f2937;
    font-size: 14.5px;
}

a { text-decoration: none; }

/* ================= LOGIN PAGE ================= */
.login-page {
    background: linear-gradient(135deg, var(--cz-navy) 0%, #1c2b3a 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-wrapper { width: 100%; max-width: 420px; }
.login-card {
    background: var(--cz-white);
    border-radius: 16px;
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.brand-icon {
    width: 64px; height: 64px; border-radius: 16px;
    background: linear-gradient(135deg, var(--cz-primary), var(--cz-primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 28px; margin: 0 auto 14px;
    box-shadow: 0 8px 20px rgba(229,9,20,0.35);
}
.login-brand h1 { font-weight: 800; letter-spacing: 1px; color: var(--cz-navy); margin-bottom: 2px; }
.login-brand p { color: var(--cz-text-muted); font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 1px; }
.btn-login {
    background: var(--cz-primary); border: none; padding: 11px; font-weight: 600;
    border-radius: 8px; transition: 0.2s;
}
.btn-login:hover { background: var(--cz-primary-dark); }
.toggle-pass { cursor: pointer; background: #fff; }
.login-footer { text-align: center; margin-top: 20px; color: var(--cz-text-muted); }

/* ================= APP LAYOUT ================= */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--cz-navy);
    color: #cbd5e1;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, transform 0.25s ease;
    overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: #2a3744; border-radius: 10px; }

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 18px; border-bottom: 1px solid #1f2b38;
    color: #fff;
}
.sidebar-brand i { font-size: 26px; color: var(--cz-primary); }
.brand-text strong { display: block; font-size: 17px; letter-spacing: 1px; }
.brand-text small { color: #94a3b8; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; }

.sidebar-menu { padding: 10px 0; flex: 1; }
.sidebar-menu ul { list-style: none; margin: 0; padding: 0; }
.sidebar-menu > ul > li > a, .sidebar-menu .nav-group-toggle {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 20px; color: #cbd5e1; font-size: 13.5px; font-weight: 500;
    border-left: 3px solid transparent;
    transition: 0.15s;
}
.sidebar-menu > ul > li > a i:first-child, .nav-group-toggle i:first-child { width: 18px; text-align: center; font-size: 15px; }
.sidebar-menu > ul > li > a:hover, .nav-group-toggle:hover { background: #1a2530; color: #fff; }
.sidebar-menu > ul > li.active > a {
    background: rgba(229,9,20,0.12); color: #fff; border-left-color: var(--cz-primary);
}
.sidebar-menu > ul > li.active > a i:first-child { color: var(--cz-primary); }

.nav-group .chev { margin-left: auto; font-size: 11px; transition: transform 0.2s; }
.nav-group.open .chev { transform: rotate(180deg); }
.nav-group .submenu { max-height: 0; overflow: hidden; transition: max-height 0.25s ease; background: #0c1219; }
.nav-group.open .submenu { max-height: 300px; }
.nav-group .submenu li a { display: block; padding: 9px 20px 9px 52px; color: #94a3b8; font-size: 13px; }
.nav-group .submenu li a:hover { color: #fff; }
.nav-group.open > a, .nav-group.active > a { color: #fff; background: #1a2530; }
.nav-group .submenu li.active a { color: var(--cz-primary); font-weight: 600; }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1020;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    transition: margin-left 0.25s ease;
    display: flex;
    flex-direction: column;
}
body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); }
body.sidebar-collapsed .sidebar .brand-text, 
body.sidebar-collapsed .sidebar span:not(.chev),
body.sidebar-collapsed .sidebar .chev { display: none; }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed); }

.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--cz-border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 22px;
    position: sticky; top: 0; z-index: 1010;
}
.btn-icon { border: none; background: transparent; font-size: 18px; color: var(--cz-navy); width: 38px; height: 38px; border-radius: 8px; }
.btn-icon:hover { background: var(--cz-bg); }

.topbar-search {
    flex: 1; max-width: 380px; align-items: center; gap: 10px;
    background: var(--cz-bg); border-radius: 8px; padding: 8px 14px; color: #94a3b8;
}
.topbar-search input { border: none; background: transparent; outline: none; flex: 1; font-size: 13.5px; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.role-badge { padding: 6px 12px; border-radius: 20px; font-weight: 600; font-size: 11.5px; }
.btn-user { border: none; background: transparent; display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--cz-navy); }
.avatar-circle {
    width: 34px; height: 34px; border-radius: 50%; background: var(--cz-primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.page-body { padding: 22px; flex: 1; }
.page-header { margin-bottom: 18px; }
.page-header h4 { font-weight: 700; color: var(--cz-navy); margin-bottom: 4px; }
.breadcrumb { margin: 0; font-size: 12.5px; }

/* ================= CARDS ================= */
.card { border: 1px solid var(--cz-border); border-radius: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03); }
.card-header { background: #fff; border-bottom: 1px solid var(--cz-border); border-radius: 14px 14px 0 0 !important; font-weight: 700; color: var(--cz-navy); }

.kpi-card {
    border-radius: 14px; border: 1px solid var(--cz-border); background: #fff;
    padding: 18px 20px; display: flex; align-items: center; gap: 16px;
    height: 100%;
}
.kpi-icon {
    width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: #fff; flex-shrink: 0;
}
.kpi-content .kpi-value { font-size: 21px; font-weight: 800; color: var(--cz-navy); line-height: 1.2; }
.kpi-content .kpi-label { font-size: 12px; color: var(--cz-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }

.bg-icon-red { background: linear-gradient(135deg,#E50914,#b8070f); }
.bg-icon-navy { background: linear-gradient(135deg,#101820,#2a3744); }
.bg-icon-green { background: linear-gradient(135deg,#16a34a,#0d7a37); }
.bg-icon-orange { background: linear-gradient(135deg,#f59e0b,#c97c05); }
.bg-icon-blue { background: linear-gradient(135deg,#2563eb,#1743a8); }
.bg-icon-purple { background: linear-gradient(135deg,#7c3aed,#5b21b6); }

/* ================= TABLES ================= */
.table-card { border-radius: 14px; overflow: hidden; }
table.table { margin-bottom: 0; font-size: 13.5px; }
table.table thead th {
    background: #fafbfc; color: #64748b; font-weight: 700; text-transform: uppercase; font-size: 11px;
    letter-spacing: 0.4px; border-bottom: 1px solid var(--cz-border); white-space: nowrap;
}
table.table td { vertical-align: middle; white-space: nowrap; }
table.table tbody tr:hover { background: #fafbfc; }

.badge-status { padding: 5px 10px; border-radius: 20px; font-weight: 600; font-size: 11px; }
.status-active, .status-paid, .status-received, .status-instock { background: #dcfce7; color: #15803d; }
.status-inactive, .status-cancelled { background: #fee2e2; color: #b91c1c; }
.status-low, .status-partial, .status-pending { background: #fef3c7; color: #b45309; }
.status-out, .status-due { background: #fee2e2; color: #b91c1c; }
.status-returned { background: #e0e7ff; color: #3730a3; }

.text-debit { color: var(--cz-danger); font-weight: 700; }
.text-credit { color: var(--cz-success); font-weight: 700; }

/* ================= FORMS / MODALS ================= */
.modal-content { border-radius: 14px; border: none; }
.modal-header { border-bottom: 1px solid var(--cz-border); }
.form-label { font-weight: 600; font-size: 13px; color: #374151; }
.form-control, .form-select { border-radius: 8px; border: 1px solid var(--cz-border); font-size: 13.5px; }
.form-control:focus, .form-select:focus { border-color: var(--cz-primary); box-shadow: 0 0 0 0.2rem rgba(229,9,20,0.1); }

.btn-primary { background: var(--cz-primary); border-color: var(--cz-primary); }
.btn-primary:hover { background: var(--cz-primary-dark); border-color: var(--cz-primary-dark); }
.btn-outline-primary { color: var(--cz-primary); border-color: var(--cz-primary); }
.btn-outline-primary:hover { background: var(--cz-primary); border-color: var(--cz-primary); }

.action-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--cz-border); background: #fff; display: inline-flex; align-items: center; justify-content: center; margin-right: 4px; color: #475569; }
.action-btn:hover { background: var(--cz-bg); }
.action-btn.btn-view:hover { color: var(--cz-info); }
.action-btn.btn-edit:hover { color: var(--cz-warning); }
.action-btn.btn-delete:hover { color: var(--cz-danger); }

/* ================= POS ================= */
.pos-wrapper { display: flex; gap: 16px; height: calc(100vh - 160px); }
.pos-products { flex: 1.4; overflow-y: auto; padding-right: 4px; }
.pos-cart { flex: 1; background: #fff; border-radius: 14px; border: 1px solid var(--cz-border); display: flex; flex-direction: column; }
.pos-product-card {
    border: 1px solid var(--cz-border); border-radius: 12px; padding: 12px; background: #fff;
    cursor: pointer; transition: 0.15s; text-align: center; height: 100%;
}
.pos-product-card:hover { border-color: var(--cz-primary); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.08); }
.pos-product-card .prod-img { width: 100%; height: 80px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: var(--cz-bg); }
.pos-product-card .prod-name { font-size: 12.5px; font-weight: 600; color: var(--cz-navy); margin-bottom: 2px; line-height:1.3; height: 32px; overflow:hidden; }
.pos-product-card .prod-price { color: var(--cz-primary); font-weight: 700; font-size: 13px; }
.pos-product-card .prod-stock { font-size: 10.5px; color: var(--cz-text-muted); }

.cart-header { padding: 16px; border-bottom: 1px solid var(--cz-border); }
.cart-items { flex: 1; overflow-y: auto; padding: 8px 16px; }
.cart-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--cz-border); }
.cart-item .ci-name { font-weight: 600; font-size: 13px; }
.cart-item .ci-price { color: var(--cz-text-muted); font-size: 12px; }
.qty-control { display: flex; align-items: center; border: 1px solid var(--cz-border); border-radius: 8px; overflow: hidden; }
.qty-control button { border: none; background: var(--cz-bg); width: 26px; height: 26px; }
.qty-control input { width: 40px; text-align: center; border: none; font-weight: 600; }
.cart-footer { padding: 16px; border-top: 1px solid var(--cz-border); background: #fafbfc; border-radius: 0 0 14px 14px; }
.cart-total-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; }
.cart-total-row.grand { font-size: 18px; font-weight: 800; color: var(--cz-navy); border-top: 1px solid var(--cz-border); margin-top: 6px; padding-top: 10px; }

/* ================= UTILITIES ================= */
.cursor-pointer { cursor: pointer; }
.fw-700 { font-weight: 700; }
.stock-badge { display:inline-block; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.spinner-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,0.6); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
}
.empty-state { text-align: center; padding: 50px 20px; color: var(--cz-text-muted); }
.empty-state i { font-size: 42px; margin-bottom: 12px; opacity: 0.4; }

.tab-pills .nav-link { border-radius: 8px; font-weight: 600; font-size: 13px; color: #475569; }
.tab-pills .nav-link.active { background: var(--cz-primary); color: #fff; }

/* ================= RESPONSIVE ================= */
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); z-index: 1050; }
    body.sidebar-mobile-open .sidebar { transform: translateX(0); }
    body.sidebar-mobile-open .sidebar-overlay { display: block; }
    .main-content { margin-left: 0 !important; }
    .pos-wrapper { flex-direction: column; height: auto; }
    .pos-cart { min-height: 400px; }
}

@media (max-width: 576px) {
    .page-body { padding: 14px; }
    .kpi-card { padding: 14px; }
    .topbar { padding: 0 12px; gap: 8px; }
}

/* ================= PURE-CSS INTERACTIONS (no JavaScript) ================= */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
label.sidebar-overlay { cursor: default; }
.nav-toggle:checked ~ .app-wrapper .sidebar { transform: translateX(0); }
.nav-toggle:checked ~ .app-wrapper .sidebar-overlay { display: block; }
@media (min-width: 992px) { .nav-toggle:checked ~ .app-wrapper .sidebar-overlay { display: none; } }

/* Sidebar supplier group uses <details> */
details.nav-group > summary { list-style: none; cursor: pointer; }
details.nav-group > summary::-webkit-details-marker { display: none; }
details.nav-group[open] .chev { transform: rotate(180deg); }
details.nav-group .submenu { max-height: none; overflow: visible; background: #0c1219; list-style: none; margin: 0; padding: 0; }
details.nav-group[open] > summary { color: #fff; background: #1a2530; }
.sidebar-menu .nav-group-item { list-style: none; }

/* User dropdown using <details> */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; list-style: none; margin: 0; padding: 6px;
    background: #fff; border: 1px solid var(--cz-border); border-radius: 10px; box-shadow: 0 10px 24px rgba(0,0,0,.12); z-index: 1100;
}
.user-menu-list a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--cz-navy); font-size: 13.5px; text-decoration: none; }
.user-menu-list a:hover { background: var(--cz-bg); }

/* Flash messages: success ones fade out on their own */
.flash-auto { animation: flashFade .6s ease 6s forwards; }
@keyframes flashFade { to { opacity: 0; max-height: 0; padding: 0; margin: 0; border-width: 0; overflow: hidden; } }

/* Pure CSS charts */
.css-chart { display: flex; align-items: flex-end; gap: 14px; height: 220px; padding: 10px 6px 0; border-bottom: 1px solid var(--cz-border); }
.css-chart .grp { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 100%; }
.css-chart .bar { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; }
.css-chart .bar.sales { background: var(--cz-primary); }
.css-chart .bar.purch { background: var(--cz-navy); }
.css-chart-labels { display: flex; gap: 14px; padding: 6px 6px 0; }
.css-chart-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--cz-text-muted); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.hbar-row { margin-bottom: 12px; }
.hbar-row .hbar-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.hbar-track { background: var(--cz-bg); border-radius: 6px; height: 10px; overflow: hidden; }
.hbar-fill { background: var(--cz-primary); height: 100%; border-radius: 6px; }

/* Server-rendered POS */
.pos-products-scroll { overflow-y: auto; max-height: calc(100vh - 230px); }
.pos-product-card form { margin: 0; }
.pos-product-card { cursor: default; }
.cart-item form { margin: 0; }
.sr-default-submit { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.line-qty { width: 64px; }

/* Print-friendly view (open with ?print=1 and use the browser's print) */
.print-mode .sidebar, .print-mode .topbar, .print-mode .sidebar-overlay, .print-mode .no-print { display: none !important; }
.print-mode .main-content { margin-left: 0 !important; }
@media print {
    .sidebar, .topbar, .sidebar-overlay, .no-print, .page-header .breadcrumb { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* POS cart: never let the item list collapse; the cart panel scrolls instead */
.pos-cart { overflow-y: auto; }
.pos-cart .cart-items { flex: 1 0 auto; min-height: 180px; overflow: visible; }
.pos-cart .cart-header, .pos-cart .cart-footer { flex: 0 0 auto; }
@media (max-width: 991px) {
    .pos-cart { min-height: 0; overflow: visible; }
    .pos-products-scroll { max-height: 70vh; }
}

/* Print only the section marked .print-area (invoice body) */
@media print {
    body * { visibility: hidden !important; }
    .print-area, .print-area * { visibility: visible !important; }
    .print-area { position: absolute !important; left: 0; top: 0; width: 100%; padding: 0 !important; margin: 0 !important; }
    .card { border: 0 !important; box-shadow: none !important; }
    @page { margin: 12mm; }
}
