/* VLXD Sales Management - Main Stylesheet */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 60px;
    --primary-color: #2563eb;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;
    --sidebar-hover: #334155;

    /* Light mode surface tokens */
    --surface-bg: #f8fafc;
    --surface-card: #ffffff;
    --surface-border: #e5e7eb;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --topbar-bg: #ffffff;
}

/* ── Dark Mode ── */
body.dark-theme {
    --surface-bg: #0f172a;
    --surface-card: #1e293b;
    --surface-border: #334155;
    --text-primary: #e2e8f0;
    --text-muted: #94a3b8;
    --topbar-bg: #1e293b;
    background-color: var(--surface-bg);
    color: var(--text-primary);
}

body.dark-theme .topbar {
    background: var(--topbar-bg);
    border-bottom-color: var(--surface-border);
}

body.dark-theme .main-content {
    background: var(--surface-bg);
}

body.dark-theme .card,
body.dark-theme .table-container {
    background: var(--surface-card);
    border-color: var(--surface-border);
}

body.dark-theme .card-header {
    background: var(--surface-card) !important;
    border-bottom-color: var(--surface-border);
    color: var(--text-primary);
}

body.dark-theme .card-footer {
    background: var(--surface-card) !important;
    border-top-color: var(--surface-border);
}

body.dark-theme .table {
    color: var(--text-primary);
}

body.dark-theme .table-hover > tbody > tr:hover > td {
    background-color: rgba(255,255,255,0.04);
}

body.dark-theme .table-light {
    background-color: rgba(255,255,255,0.06);
}

body.dark-theme .form-control,
body.dark-theme .form-select {
    background-color: #0f172a;
    border-color: var(--surface-border);
    color: var(--text-primary);
}

body.dark-theme .form-control:focus,
body.dark-theme .form-select:focus {
    background-color: #0f172a;
    color: var(--text-primary);
}

body.dark-theme .dropdown-menu {
    background: var(--surface-card);
    border-color: var(--surface-border);
}

body.dark-theme .dropdown-item {
    color: var(--text-primary);
}

body.dark-theme .dropdown-item:hover {
    background-color: rgba(255,255,255,0.06);
}

body.dark-theme h1,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme h4,
body.dark-theme h5,
body.dark-theme h6 {
    color: var(--text-primary);
}

body.dark-theme .page-header h1 {
    color: var(--text-primary);
}

body.dark-theme .nav-tabs .nav-link {
    color: var(--text-muted);
}

body.dark-theme .nav-tabs .nav-link.active {
    background: var(--surface-card);
    border-color: var(--surface-border) var(--surface-border) var(--surface-card);
    color: var(--text-primary);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1040;
    overflow-y: auto;
    transition: width 0.3s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    gap: 10px;
}

.sidebar-brand i { font-size: 1.4rem; color: var(--sidebar-active); }

.sidebar-nav { padding: 10px 0; list-style: none; margin: 0; }

.sidebar-nav .nav-item { margin: 2px 8px; }

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .nav-link i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar-nav .nav-divider { border-top: 1px solid rgba(255,255,255,0.08); margin: 10px 16px; }

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    transition: left 0.3s ease;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar .btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
    display: none;
}

.notification-badge {
    position: relative;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
}

.notification-badge .badge {
    position: absolute;
    top: -5px;
    right: -8px;
    font-size: 0.65rem;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
    background: #f8fafc;
    transition: margin-left 0.3s ease;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; color: #1e293b; margin: 0; }

/* Cards */
.stat-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}

.stat-card:hover { transform: translateY(-4px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.stat-card .stat-value { font-size: 1.15rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-card .stat-label { font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 575.98px) {
    .stat-card .stat-icon { width: 32px; height: 32px; font-size: 0.9rem; border-radius: 7px; }
    .stat-card .stat-value { font-size: clamp(0.7rem, 3.8vw, 0.88rem); white-space: normal; word-break: break-all; line-height: 1.2; }
    .stat-card .stat-label { font-size: 0.63rem; }
    .dash-chart-wrap { min-height: 200px !important; }
    .dash-orders th, .dash-orders td { font-size: 0.75rem; padding: 0.35rem 0.4rem; }
    .qty-filter-header { flex-direction: column; align-items: flex-start !important; gap: 0.4rem !important; }
    .qty-filter-header .btn-group { align-self: stretch; }
    .qty-filter-header .btn-group .btn { flex: 1; font-size: 0.72rem; padding: 0.2rem 0.3rem; }
}

/* ── Mobile: product items table → responsive card rows ── */
@media (max-width: 767.98px) {
    #items-table { display: block; width: 100%; }
    #items-table > thead { display: none !important; }
    #items-table > tbody { display: block; padding: 0.5rem; }
    #items-table > tbody > tr {
        display: block;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        margin-bottom: 0.75rem;
        padding: 0.6rem 0.75rem;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,.06);
    }
    #items-table > tbody > tr > td {
        display: block;
        border: none !important;
        padding: 0.15rem 0 0.2rem;
        font-size: 0.82rem;
    }
    #items-table > tbody > tr > td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.65rem;
        font-weight: 700;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        margin-bottom: 2px;
    }
    #items-table > tbody > tr > td.td-remove {
        text-align: right;
        padding-top: 0.5rem !important;
        margin-top: 0.25rem;
        border-top: 1px dashed #e2e8f0 !important;
    }
    #items-table > tbody > tr > td.td-remove::before { display: none; }
    /* tfoot (deposit form) */
    #items-table > tfoot { display: block; }
    #items-table > tfoot > tr {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-top: 2px solid #dee2e6;
        padding: 0.5rem 0.75rem;
        font-weight: 700;
    }
    #items-table > tfoot > tr > td { border: none !important; padding: 0; }
    #items-table > tfoot > tr > td:empty { display: none; }
    /* Summary action buttons full-width */
    .form-action-bar { justify-content: stretch !important; }
    .form-action-bar .btn { flex: 1; }
    /* Order summary totals */
    .order-summary-row { flex-direction: column-reverse; }
    .order-summary-row > [class*="col-md"] { width: 100% !important; max-width: 100% !important; }
}

/* Tables */
.table-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 20px;
}

.table th { font-weight: 600; color: #475569; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .topbar { left: 0; }
    .main-content { margin-left: 0; }
    .topbar .btn-toggle-sidebar { display: block; }
    .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1035; display: none; }
    .sidebar-overlay.show { display: block; }
}

/* Flash messages */
.flash-container { margin-bottom: 16px; }
.flash-container .alert { border-radius: 8px; border: none; }

/* Footer */
.main-footer { text-align: center; padding: 16px; color: #94a3b8; font-size: 0.8rem; border-top: 1px solid #e5e7eb; margin-top: 40px; }

/* ── Global Search ── */
.global-search-wrapper {
    position: relative;
}

#global-search-input {
    width: 220px;
    font-size: 0.85rem;
    transition: width 0.2s;
}

#global-search-input:focus { width: 300px; }

#global-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    min-width: 320px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 2000;
    overflow: hidden;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    text-decoration: none;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.875rem;
    transition: background 0.15s;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f0f7ff; color: #2563eb; }

.search-result-type {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #94a3b8;
    width: 70px;
    flex-shrink: 0;
}

.search-result-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-code { flex-shrink: 0; }

body.dark-theme #global-search-results {
    background: var(--surface-card);
    border-color: var(--surface-border);
}

body.dark-theme .search-result-item {
    color: var(--text-primary);
    border-bottom-color: var(--surface-border);
}

body.dark-theme .search-result-item:hover {
    background: rgba(59,130,246,0.12);
}

/* ── Dark mode toggle button ── */
#btn-toggle-theme {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

#btn-toggle-theme:hover { background: #f1f5f9; }
