/* ============================================================
   HISAB KITAB - Main Stylesheet
   Dhakad Group © 2026
   ============================================================ */

:root {
    --primary:        #1565C0;
    --primary-dark:   #0D47A1;
    --primary-light:  #1976D2;
    --accent:         #42A5F5;
    --sidebar-bg:     #0f1b2d;
    --sidebar-text:   #a8b8d0;
    --sidebar-active: #1565C0;
    --content-bg:     #f0f4ff;
    --card-bg:        #ffffff;
    --text-dark:      #1a2035;
    --text-muted:     #6c757d;
    --border:         #e4eaf4;
    --shadow:         0 4px 24px rgba(21,101,192,0.10);
    --shadow-sm:      0 2px 12px rgba(0,0,0,0.07);
    --radius:         12px;
    --radius-sm:      8px;
    --sidebar-w:      265px;
    --navbar-h:       64px;
    --success:        #28a745;
    --danger:         #dc3545;
    --warning:        #fd7e14;
    --info:           #17a2b8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--content-bg);
    color: var(--text-dark);
    font-size: 0.875rem;
    overflow-x: hidden;
}

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

/* ======== SIDEBAR ======== */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #0f1b2d 0%, #0a1525 100%);
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 74px;
    background: rgba(21,101,192,0.12);
}

.sidebar-logo { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; }

.sidebar-brand { flex: 1; min-width: 0; }
.brand-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.3px;
}
.brand-sub {
    display: block;
    font-size: 0.68rem;
    color: var(--accent);
    font-weight: 500;
    letter-spacing: 0.5px;
}

.sidebar-close {
    background: none; border: none;
    color: var(--sidebar-text); font-size: 1.1rem;
    cursor: pointer; padding: 4px 8px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* ── NAV STYLES ─────────────────────────────────────────────── */
.nav-list { list-style: none; padding: 6px 0; margin: 0; }
.nav-list > li.nav-item { margin: 1px 8px; }

.nav-item > .nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.18s, color 0.18s;
}
.nav-item > .nav-link:hover { color: #fff; background: rgba(255,255,255,0.07); }
.nav-item.active > .nav-link,
.nav-item > .nav-link.active {
    color: #fff;
    background: linear-gradient(90deg, rgba(21,101,192,0.55), rgba(21,101,192,0.25));
    font-weight: 600;
}
.nav-item.active > .nav-link::before { display: none; }
.nav-icon  { width: 17px; text-align: center; font-size: 0.83rem; flex-shrink: 0; opacity: 0.85; }
.nav-label { flex: 1; font-size: 0.81rem; font-weight: 500; white-space: nowrap; }
.nav-chevron { font-size: 0.58rem; opacity: 0.5; transition: transform 0.22s ease; }
.nav-toggle:not(.collapsed) .nav-chevron { transform: rotate(180deg); }

.sub-menu { list-style: none; padding: 2px 0 4px 26px; margin: 0; }
.sub-link {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px;
    color: rgba(168,184,208,0.75);
    text-decoration: none;
    font-size: 0.78rem;
    border-radius: 6px;
    transition: background 0.18s, color 0.18s;
    margin-bottom: 1px;
}
.sub-link:hover  { color: #fff; background: rgba(255,255,255,0.07); }
.sub-link.active { color: #fff; background: rgba(21,101,192,0.4); font-weight: 600; }
.sub-icon { font-size: 0.72rem; width: 14px; text-align: center; opacity: 0.75; flex-shrink: 0; }
.nav-badge { background: var(--danger); color: #fff; font-size: 0.58rem; font-weight: 700; padding: 2px 6px; border-radius: 10px; min-width: 20px; text-align: center; line-height: 1.5; }

/* Sidebar scrollbar */
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 12px 16px;
}
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
}
.user-avatar-sm {
    width: 34px; height: 34px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.85rem; font-weight: 700;
    flex-shrink: 0;
}
.user-info-sm { flex: 1; min-width: 0; }
.user-name-sm {
    display: block; color: #fff;
    font-size: 0.78rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role-sm { display: block; color: var(--accent); font-size: 0.68rem; }
.logout-btn-sm {
    color: var(--sidebar-text); text-decoration: none;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px; transition: all 0.2s;
}
.logout-btn-sm:hover { background: rgba(220,53,69,0.2); color: #ff6b6b; }

/* ======== MAIN CONTENT ======== */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* ======== TOP NAVBAR ======== */
.top-navbar {
    height: var(--navbar-h);
    background: #fff;
    box-shadow: 0 2px 12px rgba(21,101,192,0.08);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 100;
}

.navbar-left { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle {
    background: none; border: 1px solid var(--border);
    border-radius: 8px;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-dark);
    transition: all 0.2s;
}
.sidebar-toggle:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.page-breadcrumb {
    display: flex; align-items: center; gap: 8px;
    color: var(--text-dark); font-weight: 600; font-size: 0.9rem;
}
.page-breadcrumb i { color: var(--primary); }

.navbar-right { display: flex; align-items: center; gap: 8px; }

.navbar-icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; border: 1px solid var(--border);
    color: var(--text-dark); text-decoration: none;
    position: relative; transition: all 0.2s;
}
.navbar-icon-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.alert-btn { color: var(--warning); border-color: rgba(253,126,20,0.3); background: rgba(253,126,20,0.05); }
.badge-alert {
    position: absolute; top: -4px; right: -4px;
    background: var(--danger); color: #fff;
    font-size: 0.6rem; font-weight: 700;
    width: 18px; height: 18px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
}

.navbar-user-btn {
    display: flex; align-items: center; gap: 8px;
    background: none; border: 1px solid var(--border);
    border-radius: 10px; padding: 5px 12px 5px 6px;
    cursor: pointer; transition: all 0.2s;
}
.navbar-user-btn:hover { background: rgba(21,101,192,0.05); border-color: var(--primary); }

.user-avatar {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.82rem; font-weight: 700;
}
.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--text-dark); line-height: 1.2; }
.user-role { font-size: 0.68rem; color: var(--primary); font-weight: 500; }

.user-menu { min-width: 180px; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.user-menu .dropdown-item { font-size: 0.82rem; padding: 8px 16px; }
.user-menu .dropdown-item:hover { background: rgba(21,101,192,0.08); color: var(--primary); }

/* ======== PAGE CONTENT ======== */
.page-content {
    flex: 1;
    padding: 28px 24px;
    background: var(--content-bg);
}

/* Page header pattern used on most pages */
.page-header-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header-row h5 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text-dark); }
.page-header-row small { color: var(--text-muted); font-size: 0.78rem; }

/* ======== STAT CARDS ======== */
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 16px;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none; color: inherit;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); color: inherit; }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(21,101,192,0.10); color: var(--primary); }
.stat-icon.green  { background: rgba(40,167,69,0.10);  color: var(--success); }
.stat-icon.orange { background: rgba(253,126,20,0.10); color: var(--warning); }
.stat-icon.red    { background: rgba(220,53,69,0.10);  color: var(--danger); }
.stat-icon.cyan   { background: rgba(23,162,184,0.10); color: var(--info); }
.stat-icon.purple { background: rgba(111,66,193,0.10); color: #6f42c1; }

.stat-info { min-width: 0; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text-dark); line-height: 1.1; }
.stat-label { font-size: 0.73rem; color: var(--text-muted); margin-top: 3px; font-weight: 500; }

/* ======== CARDS ======== */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    background: var(--card-bg);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0 !important;
    padding: 14px 20px;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 8px;
    min-height: 54px;
}
.card-title { font-size: 0.88rem; font-weight: 700; color: var(--text-dark); margin: 0; display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--primary); font-size: 0.85rem; }
.card-body { padding: 20px; }

/* ======== BUTTONS ======== */
.btn {
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-xs { padding: 3px 8px; font-size: 0.72rem; border-radius: 5px; }
.btn-icon { width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; }

/* ======== TABLES ======== */
.table { font-size: 0.82rem; }
.table th {
    font-weight: 600; font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); border-color: var(--border);
    padding: 11px 14px; background: #f8f9ff;
}
.table td { border-color: var(--border); vertical-align: middle; padding: 10px 14px; }
.table-hover tbody tr:hover { background-color: rgba(21,101,192,0.04); }
.card > .table-responsive > .table,
.card > .table { border-radius: 0; }

/* DataTables overrides */
.dataTables_wrapper { padding: 0; }
.dataTables_wrapper .dataTables_filter { margin-bottom: 0; }
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.8rem; margin-left: 6px;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 8px; font-size: 0.8rem;
}
.dataTables_wrapper .dataTables_length { font-size: 0.8rem; }
.dataTables_wrapper .dataTables_info  { font-size: 0.78rem; color: var(--text-muted); padding-top: 6px; }
div.dt-buttons { margin-bottom: 0; }
.dataTables_wrapper .dt-buttons .btn {
    font-size: 0.75rem !important;
    padding: 5px 12px !important;
    border-radius: 6px !important;
}

/* ======== BADGES ======== */
.badge { font-weight: 500; font-size: 0.72rem; border-radius: 6px; padding: 4px 8px; }
.badge-active  { background: rgba(40,167,69,0.12);  color: #1a7a31; }
.badge-inactive{ background: rgba(220,53,69,0.12);  color: #b02a37; }
.badge-admin   { background: rgba(21,101,192,0.12); color: var(--primary); }
.badge-staff   { background: rgba(23,162,184,0.12); color: var(--info); }

/* ======== FORMS ======== */
.form-label { font-size: 0.8rem; font-weight: 600; color: var(--text-dark); margin-bottom: 4px; }
.form-control, .form-select {
    font-size: 0.82rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.1);
}
.input-group-text { font-size: 0.82rem; border-color: var(--border); }

/* ======== MODALS ======== */
.modal-content { border-radius: var(--radius); border: none; box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
.modal-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: #fff; border-radius: var(--radius) var(--radius) 0 0;
    padding: 14px 20px;
}
.modal-title { font-size: 0.92rem; font-weight: 600; }
.modal-header .btn-close { filter: invert(1); opacity: 0.8; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-color: var(--border); }

/* ======== LOGIN PAGE ======== */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0a1525 0%, #0f1b2d 50%, #1a2a45 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute; top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(ellipse at center, rgba(21,101,192,0.15) 0%, transparent 60%);
    animation: pulse 8s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.login-card {
    background: rgba(255,255,255,0.97);
    border-radius: 20px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.4);
    padding: 44px 40px;
    width: 100%; max-width: 420px;
    position: relative; z-index: 1;
    animation: slideUp 0.5s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }

.login-logo { width: 90px; height: 90px; object-fit: contain; }
.login-title { font-size: 1.6rem; font-weight: 700; color: var(--text-dark); margin: 12px 0 4px; }
.login-subtitle { font-size: 0.78rem; color: var(--text-muted); }
.login-company { font-size: 0.72rem; color: var(--primary); font-weight: 600; letter-spacing: 0.5px; margin-top: 4px; }

/* ======== STOCK ENTRY TABLE ======== */
.stock-entry-table { font-size: 0.8rem; }
.stock-entry-table th { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%); color: #fff; font-weight: 600; font-size: 0.73rem; border: none; }
.row-total { font-weight: 600; color: var(--primary); }
.grand-total-row { background: rgba(21,101,192,0.06); font-weight: 700; }
.add-row-btn { border: 2px dashed var(--primary); background: rgba(21,101,192,0.05); color: var(--primary); border-radius: 8px; padding: 8px; width: 100%; transition: all 0.2s; }
.add-row-btn:hover { background: var(--primary); color: #fff; }

/* ======== CHARTS ======== */
.chart-card { padding: 16px; }
.chart-container { position: relative; }

/* ======== ALERTS ======== */
.alert-low-stock {
    background: rgba(253,126,20,0.1);
    border: 1px solid rgba(253,126,20,0.3);
    border-left: 4px solid var(--warning);
    border-radius: 8px;
    padding: 12px 16px;
    color: #7d4a00;
    font-size: 0.82rem;
}

/* ======== RESPONSIVE ======== */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
}

/* Tables - always scrollable on small screens */
.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}
.table {
    min-width: 600px;
}
/* Narrow tables don't need min-width */
.table.table-sm.no-min-width { min-width: unset; }

/* DataTables mobile fixes */
.dataTables_wrapper {
    overflow-x: auto;
}
.dataTables_wrapper .row {
    flex-wrap: wrap;
}
.dataTables_filter input {
    max-width: 180px;
}

@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0; }

    /* Stat cards */
    .stat-value { font-size: 1.3rem; }
    .stat-icon  { width: 46px; height: 46px; font-size: 1.1rem; }

    /* Page header wraps on mobile */
    .page-content { padding: 14px 10px; }
    .card-header { padding: 10px 12px; }
    .card-body   { padding: 12px; }

    /* Stock entry table - smaller on mobile */
    .stock-entry-table th,
    .stock-entry-table td { padding: 6px 4px; font-size: 0.75rem; }
    .stock-entry-table .form-control,
    .stock-entry-table .form-select { font-size: 0.75rem; padding: 4px 6px; }

    /* Modal full-width on mobile */
    .modal-dialog { margin: 8px; }
    .modal-dialog.modal-lg { max-width: 100%; margin: 8px; }

    /* Navbar adjustments */
    .page-breadcrumb { font-size: 0.78rem; }
    .user-details { display: none !important; }

    /* Buttons wrap */
    .d-flex.gap-2 { flex-wrap: wrap; }
}

@media (max-width: 576px) {
    .page-content { padding: 10px 8px; }
    .login-card   { padding: 28px 18px; }
    .stat-value   { font-size: 1.2rem; }
    .stat-icon    { width: 42px; height: 42px; font-size: 1rem; }

    /* Tables: allow horizontal scroll with indicator */
    .table-responsive::after {
        content: '';
        display: none;
    }
    .card-title { font-size: 0.82rem; }

    /* DataTables controls */
    .dataTables_length,
    .dataTables_filter { font-size: 0.75rem; }
    div.dt-buttons .btn { font-size: 0.7rem !important; padding: 3px 8px !important; }

    /* Top navbar */
    .top-navbar { padding: 0 10px; }
    .navbar-icon-btn { width: 32px; height: 32px; }
}

/* ======== PRINT ======== */
@media print {
    .sidebar, .top-navbar, .btn, .dt-buttons { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* ======== ANIMATIONS ======== */
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card-in { animation: cardIn 0.4s ease; }
@keyframes cardIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ======== MISC ======== */
.section-title {
    font-size: 1rem; font-weight: 700; color: var(--text-dark);
    margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.section-title::after {
    content: ''; flex: 1; height: 2px;
    background: linear-gradient(90deg, var(--border), transparent);
}

.info-row { display: flex; gap: 6px; align-items: flex-start; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 4px; }
.info-row strong { color: var(--text-dark); min-width: 120px; }

/* Select2 fixes */
.select2-container .select2-selection--single { height: 38px !important; border-color: var(--border) !important; }
.select2-container--bootstrap-5 .select2-selection { border-color: var(--border) !important; }

/* Toastr-like alerts using Bootstrap */
.toast-container { z-index: 9999; }
