/* =====================================================
   CSS VARIABLES & THEMES
   ===================================================== */
:root {
    /* Common Layout & Brand */
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --navbar-height: 60px;
    --header-height: 60px;
    /* Kept for legacy compatibility */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    /* Touch-friendly minimum (iPad/phone) */
    --touch-min: 44px;

    --primary: #1a2744;
    --primary-hover: #243556;
    --primary-light: rgba(26, 39, 68, 0.12);
    --secondary: #5a6e88;
    --success: #2ecc71;
    --success-light: rgba(46, 204, 113, 0.12);
    --danger: #e74c3c;
    --danger-light: rgba(231, 76, 60, 0.12);
    --warning: #f39c12;
    --warning-light: rgba(243, 156, 18, 0.15);
    --info: #3498db;
    --info-light: rgba(52, 152, 219, 0.12);
    --accent: #c9a84c;
    --accent-hover: #a88a35;
    --accent-light: rgba(201, 168, 76, 0.12);

    /* Light Theme (Default) */
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e0e3e8;
    --text-primary: #1a2744;
    --text-secondary: #5a6e88;
    --text-muted: #8899b0;
    --border-color: #d8dce3;
    --shadow-color: rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
    color-scheme: light;
}

/* Dark Theme Overrides */
[data-theme="dark"] {
    --bg-primary: #0f1a2e;
    --bg-secondary: #1a2744;
    --bg-tertiary: #243556;
    --text-primary: #e4e8ef;
    --text-secondary: #8899b0;
    --text-muted: #5a6e88;
    --border-color: #2d3f5a;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

/* Specific Light Theme override just in case data-theme="light" is explicitly set */
[data-theme="light"] {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f5;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.08);
    color-scheme: light;
}

/* Base Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: clamp(15px, 2.2vw, 16px);
    scroll-behavior: smooth;
    background-color: var(--bg-primary);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color 0.4s ease, color 0.4s ease;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* =====================================================
   THEME TOGGLE SWITCH
   ===================================================== */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.theme-switch {
    display: inline-block;
    height: 28px;
    min-height: var(--touch-min);
    position: relative;
    width: 50px;
}

@media (max-width: 767px) {
    .theme-switch {
        height: 32px;
        width: 56px;
    }

    .slider:before {
        height: 24px;
        width: 24px;
    }

    input:checked+.slider:before {
        transform: translateX(26px);
    }
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    background-color: white;
    bottom: 4px;
    content: "";
    height: 20px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 12px;
    color: #f1c40f;
}

/* Sun icon for light mode */
.slider:before {
    content: "\f185";
}

input:checked+.slider {
    background-color: var(--accent);
}

input:checked+.slider:before {
    transform: translateX(22px);
    content: "\f186";
    /* Moon icon for dark mode */
    color: #f1c40f;
}

.theme-label-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Theme toggle inside user dropdown */
.dropdown-item-theme {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: default;
    flex-wrap: nowrap;
}

.dropdown-item-theme .theme-label-text {
    text-transform: none;
    letter-spacing: 0;
    flex: 1;
}

.theme-switch-dropdown {
    flex-shrink: 0;
    margin-left: auto;
}

.dropdown-item-theme .theme-switch {
    width: 44px;
    height: 24px;
}

.dropdown-item-theme .slider:before {
    height: 16px;
    width: 16px;
}

.dropdown-item-theme input:checked+.slider:before {
    transform: translateX(20px);
}

/* =====================================================
   LAYOUT
   ===================================================== */
.app-wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
    margin-top: var(--navbar-height);
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
    min-height: calc(100vh - var(--navbar-height));
    background-color: var(--bg-primary);
}

@media (max-width: 991px) {
    .main-content {
        margin-left: 0;
    }

    .app-legal-links {
        margin-left: 0;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

.content-area {
    padding: 1.5rem;
    width: 100%;
}

.app-legal-links {
    margin-left: var(--sidebar-width);
    padding: 0 1.5rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
}

.app-legal-links a {
    color: var(--text-secondary);
    text-decoration: none;
}

.app-legal-links a:hover {
    color: var(--accent);
}

/* =====================================================
   NAVBAR
   ===================================================== */
.main-navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: var(--navbar-height);
    backdrop-filter: blur(12px);
    z-index: 1040;
    box-shadow: var(--shadow-sm);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    transition: var(--transition);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px 10px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    border-radius: var(--radius-sm);
}

.sidebar-toggle:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: none;
}

.navbar-brand:hover {
    color: var(--text-primary);
}

.navbar-brand .brand-icon {
    color: var(--accent);
    font-size: 1.2rem;
}

.brand-text {
    font-weight: 700;
    letter-spacing: -0.3px;
}

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

/* User Dropdown in Navbar */
.nav-user-dropdown {
    position: relative;
}

.nav-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-user-btn:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

.nav-user-btn .avatar {
    width: 32px;
    height: 32px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

.nav-user-btn .user-name {
    font-weight: 500;
    display: inline-block;
}

.nav-user-btn .fa-chevron-down {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: var(--transition);
}

.nav-user-dropdown.active .nav-user-btn .fa-chevron-down {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 240px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: var(--transition);
    z-index: 1050;
    overflow: hidden;
}

.nav-user-dropdown.active .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-dropdown-header {
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.nav-dropdown-header .user-name-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.nav-dropdown-header .role-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-dropdown-header .service-info {
    margin-top: 6px;
}

.nav-dropdown-header .service-info small {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
}

.nav-dropdown-header .service-info .expiry-date {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    display: block;
    margin-top: 2px;
}

.nav-dropdown-header .service-info .service-subscribe-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.nav-dropdown-header .service-info .service-subscribe-link:hover {
    color: var(--accent-hover);
    text-decoration: none;
}

.nav-account-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    color: var(--accent);
    font-size: 0.84rem;
    font-weight: 700;
    text-decoration: none;
}

.nav-account-link:hover {
    color: var(--accent-hover);
    text-decoration: none;
}

.nav-dropdown-divider {
    height: 1px;
    background: var(--border-color);
}

.nav-dropdown-links {
    padding: 8px 0;
}

.nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: none;
    transition: var(--transition);
}

.nav-dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.nav-dropdown-footer {
    padding: 8px;
}

.nav-dropdown-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-dropdown-btn {
    flex: 1 1 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    width: 100%;
    padding: 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    background: none;
    text-decoration: none;
}

.nav-dropdown-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.nav-dropdown-btn.logout {
    color: var(--danger);
}

.nav-dropdown-btn.logout:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.nav-dropdown-btn.theme-toggle-btn {
    color: var(--text-primary);
}

.nav-dropdown-btn.theme-toggle-btn:hover {
    color: var(--accent);
}

@media (max-width: 420px) {
    .nav-dropdown-footer-actions {
        flex-wrap: wrap;
    }

    .nav-dropdown-footer-actions .nav-dropdown-btn.theme-toggle-btn,
    .nav-dropdown-footer-actions .nav-dropdown-btn.logout {
        width: 100%;
        flex: 1 1 100%;
    }
}

/* =====================================================
   SIDEBAR
   ===================================================== */
.sidebar {
    position: fixed;
    left: 0;
    top: var(--navbar-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    transition: var(--transition);
    z-index: 1030;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-brand-inner {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-brand-inner i {
    font-size: 1.2rem;
    color: var(--accent);
}

.sidebar-nav {
    padding: 12px 0;
}

.nav-section-title {
    padding: 16px 20px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.sidebar-nav .nav-link {
    color: var(--text-secondary);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 400;
    transition: var(--transition);
    border-left: 3px solid transparent;
    text-decoration: none;
}

.sidebar-nav .nav-link .icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-left-color: var(--accent);
}

.sidebar-nav .nav-link.active {
    background: var(--accent-light);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500;
}

/* Sidebar collapsed / mobile logic */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1025;
        backdrop-filter: blur(2px);
    }

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

body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

body.sidebar-collapsed .main-content {
    margin-left: 0;
}

body.sidebar-collapsed .app-legal-links {
    margin-left: 0;
}

/* Branch Selector in Navbar */
.branch-selector select {
    appearance: none;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 2rem 0.5rem 1rem;
    min-height: 36px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238899b0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* =====================================================
   CARDS
   ===================================================== */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

/* Stat Cards */
.stat-card {
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.primary {
    background: var(--primary-light);
    color: var(--primary);
}

.stat-icon.success {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.warning {
    background: var(--warning-light);
    color: var(--warning);
}

.stat-icon.danger {
    background: var(--danger-light);
    color: var(--danger);
}

.stat-icon.accent {
    background: var(--accent-light);
    color: var(--accent);
}

.stat-content h3 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-content p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dashboard-hero {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 1.5rem;
    padding: 1.5rem;
    background:
        radial-gradient(circle at top right, rgba(201, 168, 76, 0.16), transparent 34%),
        linear-gradient(135deg, var(--bg-secondary), color-mix(in srgb, var(--primary) 12%, var(--bg-secondary)));
}

.dashboard-hero-copy h2 {
    font-size: clamp(1.65rem, 3vw, 2.4rem);
    line-height: 1.1;
    margin-bottom: 0.75rem;
}

.dashboard-hero-copy p {
    max-width: 58ch;
    color: var(--text-secondary);
}

.dashboard-eyebrow {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    margin-bottom: 0.85rem;
    border-radius: 999px;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dashboard-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.dashboard-hero-panel {
    display: grid;
    gap: 0.85rem;
    align-content: start;
    padding: 1.25rem;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--bg-secondary) 76%, transparent);
    border: 1px solid var(--border-color);
}

.hero-panel-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.hero-panel-metric {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.hero-panel-metric:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.hero-panel-metric strong {
    font-size: 1.35rem;
    line-height: 1.1;
}

.hero-panel-metric span {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    min-height: var(--touch-min);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition), background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    text-decoration: none;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 767px) {
    .btn:not(.btn-icon):not(.btn-sm) {
        padding: 0.75rem 1.25rem;
    }
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: #fff;
}

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

.btn-accent:hover {
    background: var(--accent-hover);
    color: #fff;
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-sm {
    padding: 0.5rem 0.875rem;
    min-height: 36px;
    font-size: 0.8rem;
}

@media (max-width: 767px) {
    .btn-sm {
        min-height: var(--touch-min);
        padding: 0.5rem 0.875rem;
    }
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
}

/* =====================================================
   FORMS
   ===================================================== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    min-height: var(--touch-min);
    font-size: 16px;
    /* prevents zoom on iOS when focus */
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition), background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

@media (min-width: 768px) {
    .form-control {
        font-size: 0.9rem;
        min-height: auto;
        padding: 0.625rem 0.875rem;
    }
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236c757d'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 20px;
    padding-right: 2.5rem;
}

/* Form Grid */
.form-row {
    display: grid;
    gap: 1rem;
}

.form-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-row-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 767px) {

    .form-row-2,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   TABLES
   ===================================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.table td {
    font-size: 0.9rem;
    vertical-align: middle;
}

.table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* =====================================================
   BADGES & STATUS
   ===================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 50px;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: #856404;
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-info {
    background: var(--info-light);
    color: #0c5460;
}

.badge-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* =====================================================
   DATA LIST (Mobile-friendly alternative to tables)
   ===================================================== */
.data-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.data-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.data-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.data-item-title {
    font-weight: 600;
    color: var(--text-primary);
}

.data-item-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.data-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.data-item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.data-item-actions .btn {
    min-height: 36px;
}

@media (max-width: 767px) {
    .data-item-actions .btn {
        min-height: var(--touch-min);
        flex: 1;
        justify-content: center;
    }
}

/* =====================================================
   UTILITIES
   ===================================================== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-secondary);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-accent {
    color: var(--accent);
}

.d-flex {
    display: flex;
}

.flex-wrap {
    flex-wrap: wrap;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.w-100 {
    width: 100%;
}

.hidden {
    display: none !important;
}

/* Grid System */
.row {
    display: grid;
    gap: 1.5rem;
}

.row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.row-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 991px) {
    .row-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-hero {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 575px) {

    .row-2,
    .row-3,
    .row-4 {
        grid-template-columns: 1fr;
    }

    .dashboard-hero {
        padding: 1.1rem;
    }

    .dashboard-hero-actions .btn {
        width: 100%;
    }
}

/* =====================================================
   EMPTY STATE
   ===================================================== */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state h4 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* =====================================================
   LOADING & ALERTS
   ===================================================== */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-success {
    background: var(--success-light);
    color: var(--success);
}

.alert-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.alert-warning {
    background: var(--warning-light);
    color: #856404;
}

.alert-info {
    background: var(--info-light);
    color: #0c5460;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* =====================================================
   MODAL
   ===================================================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* =====================================================
   SEARCH & FILTERS
   ===================================================== */
.search-box {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    min-height: var(--touch-min);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    background: var(--bg-primary);
    font-size: 16px;
    color: var(--text-primary);
}

@media (min-width: 768px) {
    .search-box input {
        font-size: 0.875rem;
        min-height: auto;
    }
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

/* =====================================================
   PAGINATION
   ===================================================== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    padding: 1rem 0;
}

.pagination a,
.pagination span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.pagination a:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* =====================================================
   PRINT STYLES
   ===================================================== */
@media print {

    .app-sidebar,
    .app-header,
    .btn,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* Consolidated with .nav-user-dropdown */

@media (max-width: 575px) {

    /* Keeping user-name visible on mobile if space permits, 
       or at least ensuring it's not hidden by mistake if it's the only one */
    .user-name {
        display: inline-block;
    }
}

/* =====================================================
   STAT GRID
   ===================================================== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-grid .stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

@media (max-width: 991px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 575px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }
}

/* Quick actions (dashboard): stack on small screens for easier tap */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 767px) {
    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn {
        width: 100%;
    }
}

/* Badge Accent */
.badge-accent {
    background: var(--accent-light);
    color: var(--accent);
}

/* Justify Center */
.justify-center {
    justify-content: center;
}

/* Hidden on mobile */
@media (max-width: 767px) {
    .hidden-mobile {
        display: none !important;
    }
}
