/* ===========================
   SV DG Billing System
   Dark Theme Stylesheet
   =========================== */

:root {
    --bg-dark: #1a1a2e;
    --bg-sidebar: #16213e;
    --bg-card: #1f2940;
    --bg-input: #253352;
    --bg-table-header: #243050;
    --text-primary: #e0e0e0;
    --text-heading: #ffffff;
    --text-muted: #99aabb;
    --accent-blue: #5b8def;
    --accent-green: #2ecc71;
    --accent-red: #e74c3c;
    --accent-orange: #fd7e14;
    --border-color: #2e4068;
    --navbar-height: 52px;
}

/* ===========================
   Base / Body
   =========================== */
body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* ===========================
   Top Navbar
   =========================== */
.navbar {
    background-color: var(--bg-sidebar) !important;
    border-bottom: 1px solid var(--border-color);
    padding: 0.4rem 0.75rem;
    height: var(--navbar-height);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.navbar-brand {
    color: #fff !important;
    font-weight: 700;
    font-size: 1.1rem;
}

.navbar-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.6);
    background: #fff;
}

/* Flat number badge in navbar */
.flat-badge {
    background: rgba(91, 141, 239, 0.15);
    border: 1px solid rgba(91, 141, 239, 0.35);
    color: #8ab4ff;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 20px;
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.flat-badge i {
    font-size: 0.7rem;
    opacity: 0.75;
}

.navbar .btn-outline-danger {
    color: var(--accent-red) !important;
    border-color: var(--accent-red) !important;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
}

.navbar .btn-outline-danger:hover {
    background-color: var(--accent-red) !important;
    color: #fff !important;
}

/* ===========================
   User Avatar & Dropdown
   =========================== */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #7c4dff);
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.user-avatar-lg {
    width: 40px;
    height: 40px;
    font-size: 0.85rem;
}

#userMenuBtn::after {
    display: none; /* hide default dropdown caret */
}

.user-dropdown {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 220px;
    padding: 0.5rem 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    margin-top: 0.35rem;
}

.user-dropdown .dropdown-header {
    padding: 0.6rem 1rem;
}

.user-dropdown .dropdown-divider {
    border-color: var(--border-color);
    margin: 0.25rem 0;
}

.user-dropdown .dropdown-item {
    color: var(--text-primary);
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
}

.user-dropdown .dropdown-item:hover,
.user-dropdown .dropdown-item:focus {
    background-color: rgba(91, 141, 239, 0.12);
    color: #fff;
}

.user-dropdown .dropdown-item.text-danger {
    color: var(--accent-red) !important;
}

.user-dropdown .dropdown-item.text-danger:hover {
    background-color: rgba(231, 76, 60, 0.15);
}

.sidebar-toggle {
    text-decoration: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

/* ===========================
   Sidebar — Desktop
   =========================== */
.sidebar {
    width: 220px;
    min-width: 220px;
    background-color: var(--bg-sidebar);
    min-height: calc(100vh - var(--navbar-height));
    padding: 0.75rem 0;
    border-right: 1px solid var(--border-color);
    position: sticky;
    top: var(--navbar-height);
    align-self: flex-start;
    overflow-y: auto;
    max-height: calc(100vh - var(--navbar-height));
    z-index: 1020;
}

.sidebar .menu {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.sidebar .menu:hover,
.sidebar .menu:focus {
    background-color: rgba(91, 141, 239, 0.12);
    color: #fff;
    border-left-color: var(--accent-blue);
}

.sidebar .menu i {
    width: 20px;
    text-align: center;
    margin-right: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.sidebar .menu:hover i {
    color: var(--accent-blue);
}

/* Sidebar collapsible groups */
.sidebar-group {
    margin: 0;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

.sidebar-group-header:hover {
    color: #fff;
}

.sidebar-group-header .sidebar-chevron {
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.sidebar-group-header.collapsed .sidebar-chevron {
    transform: rotate(-90deg);
}

.sidebar-group-items {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.25s ease-in-out;
}

.sidebar-group-items.collapsed {
    max-height: 0;
}

.sidebar .menu.sub {
    padding-left: 2.2rem;
    font-size: 0.85rem;
}

.sidebar .menu.sub i {
    font-size: 0.8rem;
}

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

.sidebar-overlay.open {
    display: block;
}

/* ===========================
   Main Content Area
   =========================== */
.main-content {
    flex: 1;
    padding: 1.25rem 1.5rem;
    min-height: calc(100vh - var(--navbar-height));
    overflow-x: auto;
    min-width: 0; /* crucial for flex shrink on mobile */
}

/* ===========================
   Card UI
   =========================== */
.card-ui {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Dashboard stat cards — equal height */
.dashboard-row {
    display: flex;
    flex-wrap: wrap;
}
.dashboard-row > [class*="col-"] {
    display: flex;
}
.dash-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0;
}
.dash-card h2 {
    margin: 0;
    font-size: 1.6rem;
}

/* ===========================
   Tables — READABILITY FIX
   =========================== */
.table {
    color: var(--text-primary) !important;
    border-color: var(--border-color);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-bg: rgba(91, 141, 239, 0.08);
    font-size: 0.9rem;
}

/* Target ALL th elements — with or without <thead> */
.table th,
.table thead th {
    background-color: var(--bg-table-header) !important;
    color: #cdd9e5 !important;
    border-bottom: 2px solid var(--border-color) !important;
    border-color: var(--border-color) !important;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.6rem 0.75rem;
    white-space: nowrap;
}

.table td {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
    vertical-align: middle;
    padding: 0.55rem 0.75rem;
}

.table > :not(caption) > * > * {
    border-color: var(--border-color) !important;
    background-color: transparent;
}

.table-bordered > :not(caption) > * > * {
    border-color: var(--border-color) !important;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
}

/* Exempt / Common area rows — dark-theme override for table-secondary */
.table tr.table-secondary > * {
    background-color: rgba(108, 117, 125, 0.15) !important;
    color: var(--text-muted) !important;
}
.table-striped > tbody > tr.table-secondary:nth-of-type(odd) > * {
    background-color: rgba(108, 117, 125, 0.20) !important;
    color: var(--text-muted) !important;
}

/* Wrap tables for horizontal scroll on mobile */
.table-responsive {
    border-radius: 6px;
}

/* ===========================
   Forms / Inputs
   =========================== */
.form-control,
.form-select {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 0.2rem rgba(91, 141, 239, 0.25);
}

.form-control::placeholder {
    color: var(--text-muted) !important;
    opacity: 1;
}

/* Fix raw inputs that lack .form-control (e.g., cycles.html) */
.card-ui input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not(.form-control):not(.form-select),
.card-ui select:not(.form-select) {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.9rem;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}

.card-ui input:not(.form-control):focus {
    border-color: var(--accent-blue);
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(91, 141, 239, 0.25);
}

/* ===========================
   Buttons
   =========================== */
.btn-primary {
    background-color: var(--accent-blue);
    border-color: var(--accent-blue);
}

.btn-primary:hover {
    background-color: #4a7ad8;
    border-color: #4a7ad8;
}

.btn-success {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
}

.btn-warning {
    background-color: var(--accent-orange);
    border-color: var(--accent-orange);
    color: #fff;
}

.btn-warning:hover {
    color: #fff;
}

.btn-danger {
    background-color: var(--accent-red);
    border-color: var(--accent-red);
}

.btn-sm {
    font-size: 0.8rem;
}

/* ===========================
   Badges (Paid / Unpaid)
   =========================== */
.badge.bg-success {
    background-color: var(--accent-green) !important;
    color: #fff !important;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

.badge.bg-danger {
    background-color: var(--accent-red) !important;
    color: #fff !important;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

/* ===========================
   Alerts
   =========================== */
.alert-info {
    background-color: rgba(91, 141, 239, 0.15);
    color: #8ab4f8;
    border-color: var(--border-color);
}

.alert-success {
    background-color: rgba(46, 204, 113, 0.15);
    color: #81c784;
    border-color: var(--border-color);
}

.alert-danger {
    background-color: rgba(231, 76, 60, 0.15);
    color: #ef9a9a;
    border-color: var(--border-color);
}

.alert-warning {
    background-color: rgba(255, 193, 7, 0.15);
    color: #ffd54f;
    border-color: var(--border-color);
}

/* ===========================
   Text Utilities
   =========================== */
.text-muted {
    color: var(--text-muted) !important;
}

.text-success {
    color: #81c784 !important;
}

.text-danger {
    color: #ef9a9a !important;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-heading);
}

a {
    color: var(--accent-blue);
}

a:hover {
    color: #7eaaff;
}

p, li, span, label {
    color: var(--text-primary);
}

/* ===========================
   Login Page
   =========================== */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    overflow-x: hidden;
}

.login-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    box-sizing: border-box;
}

.login-container .card-ui h4 {
    color: #fff;
    margin-bottom: 0.25rem;
}

/* ===========================
   Dashboard Cards
   =========================== */
.row .card-ui h3 {
    color: #fff;
    font-size: 1.8rem;
    margin: 0;
}

.row .card-ui .text-muted {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

/* ===========================
   Scrollbar (Dark)
   =========================== */

/* Sort arrows on sortable table headers */
.table thead th[style*="cursor: pointer"]::after {
    content: ' \2195';
    font-size: 0.7em;
    opacity: 0.35;
}
.table thead th.sort-asc::after {
    content: ' \25B2';
    opacity: 0.85;
}
.table thead th.sort-desc::after {
    content: ' \25BC';
    opacity: 0.85;
}

/* Sidebar logo section for mobile */
.sidebar-logo {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
}

/* ===========================
   Accordion (Dark Theme)
   =========================== */
.accordion-item {
    background-color: transparent;
    border-color: var(--border-color) !important;
}

.accordion-button {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: none;
    box-shadow: none !important;
    font-size: 0.95rem;
}

.accordion-button:not(.collapsed) {
    background-color: var(--bg-input) !important;
    color: #fff !important;
}

.accordion-button::after {
    filter: invert(0.8);
}

.accordion-body {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
}

.accordion-body code {
    color: var(--accent-blue);
    background: rgba(91, 141, 239, 0.12);
    padding: 1px 5px;
    border-radius: 3px;
}

::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3d5580;
}

/* ===========================
   Responsive / Mobile
   =========================== */
@media (max-width: 991.98px) {
    /* Sidebar: off-canvas on mobile */
    .sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: -260px;
        width: 240px;
        min-width: 240px;
        height: calc(100vh - var(--navbar-height));
        transition: left 0.25s ease;
        z-index: 1020;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
    }

    .main-content {
        padding: 1rem 0.75rem;
        width: 100%;
    }

    /* Tables scroll horizontally */
    .table {
        font-size: 0.82rem;
    }

    .table th,
    .table td {
        padding: 0.45rem 0.5rem;
    }

    .card-ui {
        padding: 0.85rem;
    }

    h4 {
        font-size: 1.15rem;
    }
}

@media (max-width: 575.98px) {
    .main-content {
        padding: 0.75rem 0.5rem;
    }

    .table {
        font-size: 0.78rem;
    }

    .btn-sm {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .badge {
        font-size: 0.68rem;
    }

    .row .card-ui h3 {
        font-size: 1.4rem;
    }
}

/* ===========================
   Dark Modals
   =========================== */
.bg-dark-card {
    background-color: var(--bg-card);
    color: var(--text-primary);
}
.bg-dark-card .card-header {
    background-color: rgba(0,0,0,0.15);
}

.bg-dark-modal {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

.bg-dark-modal .modal-header {
    border-bottom-color: var(--border-color);
}

.bg-dark-modal .modal-footer {
    border-top-color: var(--border-color);
}

.bg-dark-modal .modal-title {
    color: var(--text-heading);
}

.bg-dark-modal .form-label {
    color: var(--text-primary);
    font-size: 0.85rem;
}

/* ===========================
   Compact / Detailed View Toggle
   =========================== */
.compact-view .col-detail {
    display: none !important;
}

/* ===========================
   Table Search Bar
   =========================== */
.input-group-text {
    border-color: var(--border-color);
}

.input-group .form-control:focus + .input-group-text,
.input-group .form-control:focus {
    border-color: var(--accent-blue);
}

/* ===========================
   Filter Button Active Check Icon
   Shows ✓ before the active button in btn-groups
   and standalone filter toggle buttons
   =========================== */
.btn-group > .btn.active::before,
.btn-group > a.btn.active::before,
.btn.active[id^="filter"]::before {
    content: "\f00c";               /* fa-check */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    margin-right: 0.35em;
    font-size: 0.75em;
}
