/* ==============================================================
   BKNS Payroll System — Design System v3.0
   Collapsible sidebar + Compact layout for 2K screens
   ============================================================== */

/* --- Custom Properties --- */




:root {
    --bg-main: #F4F7FA;
    --bg-surface: #ffffff;
    --bg-sidebar: #2A364E;
    --border-color: #E2E8F0;
    --border-sidebar: #3B4A6B;
    --border-hover: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-sidebar: #cbd5e1;
    --text-sidebar-muted: #94a3b8;
    --text-sidebar-hover: #ffffff;
    --text-sidebar-active: #ffffff;
    --accent-primary: #3B82F6;
    --accent-primary-hover: #2563EB;
    --accent-light: #eff6ff;
    --scrollbar-bg: transparent;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #9ca3af;
    --nav-hover-bg: rgba(255, 255, 255, 0.05);
    --nav-active-bg: rgba(59, 130, 246, 0.15);
    --nav-active-border: #3B82F6;
    --table-header-bg: #f8fafc;
    --table-even-bg: #ffffff;
    --table-hover-bg: #f8fafc;
    --input-bg: #ffffff;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);

    --bg-success: #dcfce7;
    --text-success: #16a34a;
    --border-success: #bbf7d0;

    --bg-danger: #fee2e2;
    --text-danger: #dc2626;
    --border-danger: #fecaca;

    --bg-warning: #fef3c7;
    --text-warning: #d97706;
    --border-warning: #fde68a;

    --bg-info: #e0e7ff;
    --text-info: #2563eb;
    --border-info: #bfdbfe;

    --btn-primary-bg: #3B82F6;
    --btn-primary-text: #ffffff;
    --btn-primary-hover: #2563EB;
}

[data-theme="dark"] {
    --bg-main: #0B1121;
    --bg-surface: #151E2F;
    --bg-sidebar: #0B1121;
    --border-color: #1E293B;
    --border-sidebar: #1E293B;
    --border-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-sidebar: #cbd5e1;
    --text-sidebar-muted: #94a3b8;
    --text-sidebar-hover: #FFFFFF;
    --text-sidebar-active: #0EA5E9;
    --accent-primary: #0EA5E9;
    --accent-primary-hover: #0284C7;
    --accent-light: rgba(14, 165, 233, 0.15);
    --scrollbar-bg: #0B1121;
    --scrollbar-thumb: #334155;
    --scrollbar-thumb-hover: #475569;
    --nav-hover-bg: rgba(14, 165, 233, 0.05);
    --nav-active-bg: rgba(14, 165, 233, 0.1);
    --nav-active-border: #0EA5E9;
    --table-header-bg: #0B1121;
    --table-even-bg: rgba(15, 23, 42, 0.3);
    --table-hover-bg: rgba(14, 165, 233, 0.04);
    --input-bg: #0B1121;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.4);

    --bg-success: rgba(34, 197, 94, 0.15);
    --text-success: #4ade80;
    --border-success: rgba(34, 197, 94, 0.3);

    --bg-danger: rgba(239, 68, 68, 0.15);
    --text-danger: #fca5a5;
    --border-danger: rgba(239, 68, 68, 0.3);

    --bg-warning: rgba(251, 191, 36, 0.15);
    --text-warning: #fbbf24;
    --border-warning: rgba(251, 191, 36, 0.3);

    --bg-info: rgba(14, 165, 233, 0.15);
    --text-info: #38bdf8;
    --border-info: rgba(14, 165, 233, 0.3);

    --btn-primary-bg: #0EA5E9;
    --btn-primary-text: #ffffff;
    --btn-primary-hover: #0284C7;
}



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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Global transitions for theme toggle */
body,
.topbar,
.card,
.stat-card,
.form-control,
.form-select,
.fb-display {
    transition-property: background-color, color, border-color;
    transition-duration: 0.3s;
    transition-timing-function: ease;
}

/* --- Sidebar --- */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* --- Sidebar Collapsed (Desktop) --- */
.sidebar.collapsed {
    width: 64px;
}

.sidebar.collapsed .sidebar-brand h1,
.sidebar.collapsed .sidebar-brand span {
    display: none;
}

.sidebar.collapsed .nav-section-toggle {
    justify-content: center;
    padding: 6px;
    font-size: 0;
}

.sidebar.collapsed .nav-section-toggle .chevron {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
    position: relative;
}

.sidebar.collapsed .nav-link span:not(.icon) {
    display: none;
}

/* Hide text nodes in nav-link when collapsed */
.sidebar.collapsed .nav-link .icon {
    width: 100%;
    font-size: 18px;
}

.sidebar.collapsed .sidebar-footer {
    font-size: 0;
    padding: 10px;
    text-align: center;
}

.sidebar.collapsed .sidebar-footer::before {
    content: 'v3.5';
    font-size: 9px;
    color: var(--text-secondary);
}

/* Tooltip on hover when collapsed */
.sidebar.collapsed .nav-link[data-title]:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    background: #334155;
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: none;
    border-bottom: 1px solid var(--border-sidebar);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand h1 {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-sidebar-hover);
    letter-spacing: -0.5px;
}

.sidebar-brand span {
    font-size: 12px;
    color: var(--text-sidebar);
}

.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar styling */
.sidebar-nav::-webkit-scrollbar {
    width: 5px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 10px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb);
}

/* Nav Sections — Collapsible groups */
.nav-section {
    margin-bottom: 4px;
}

.nav-section-label {
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-sidebar);
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-top: 10px;
}

.nav-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 12px 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-sidebar-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    user-select: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-section-toggle:hover {
    background: var(--nav-hover-bg);
    color: var(--text-sidebar-hover);
}

.nav-section-toggle .chevron {
    transition: transform 0.2s;
    font-size: 10px;
    color: var(--text-sidebar-muted);
}

.nav-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.nav-section.collapsed .nav-section-links {
    display: none;
}

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

/* Nav Links */
.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--text-sidebar);
    font-size: 13px;
    /* Slightly larger for better readability */
    text-decoration: none;
    transition: all 0.15s;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover {
    background: var(--nav-hover-bg);
    color: var(--text-sidebar-hover);
}

.nav-link.active {
    background: var(--nav-active-bg);
    color: var(--text-sidebar-active);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--nav-active-border);
}

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

.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border-sidebar);
    font-size: 11px;
    color: var(--text-sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    transition: font-size 0.25s;
}

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* --- Main Area --- */
.main {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed~.main {
    margin-left: 64px;
}

/* --- Topbar --- */
.topbar {
    height: 60px;
    background: var(--bg-main);
    border-bottom: none;
    padding-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 40;
    gap: 10px;
}

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

/* --- Global Search --- */
.global-search-container {
    position: relative;
    margin-left: 20px;
    width: 250px;
}

#globalSearchInput {
    padding-left: 30px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 38px;
    width: 320px;
    transition: border-color 0.2s;
}

#globalSearchInput:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--nav-hover-bg);
}

/* Focus styling extracted above */

.global-search-container::before {
    content: '🔍';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 10;
}

.global-search-loading {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border: 2px solid #555;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 320px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    list-style: none;
    z-index: 1000;
    max-height: 350px;
    overflow-y: auto;
}

.search-results-dropdown li {
    border-bottom: 1px solid var(--border-color);
}

.search-results-dropdown li:last-child {
    border-bottom: none;
}

.search-results-dropdown a {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.15s;
}

.search-results-dropdown a:hover,
.search-results-dropdown a.focused {
    background: var(--nav-hover-bg);
}

.search-results-dropdown .search-title {
    font-size: 13px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
}

.search-results-dropdown .search-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.search-results-dropdown .search-empty {
    padding: 14px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

@media (max-width: 768px) {
    .global-search-container {
        display: none;
        /* Hide on small mobile to save space */
    }
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
}

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

.user-info {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.user-info strong {
    color: var(--text-primary);
}

/* Hamburger — always visible */
.hamburger {
    display: flex;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 7px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.hamburger:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Logout */
.btn-logout {
    padding: 6px 14px;
    background: var(--bg-danger);
    border: 1px solid var(--border-danger);
    color: var(--text-danger);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.22);
}

/* --- Content --- */
.content {
    flex: 1;
    padding: 18px 20px;
    overflow-x: auto;
}

.content::-webkit-scrollbar {
    height: 10px;
}

.content::-webkit-scrollbar-track {
    background: var(--bg-surface);
    border-radius: 5px;
}

.content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
}

.content::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* --- App Footer --- */
.app-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px 20px;
    box-shadow: var(--card-shadow);
    transition: border-color 0.2s, transform 0.15s;
}

.stat-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.stat-card .label {
    font-size: 11.5px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .value {
    font-size: 24px;
    font-weight: 700;
    margin-top: 6px;
    color: var(--text-primary);
}

.stat-card .sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-card.indigo .value {
    color: var(--accent-primary);
}

.stat-card.green .value {
    color: var(--text-success);
}

.stat-card.amber .value {
    color: var(--text-warning);
}

.stat-card.rose .value {
    color: var(--text-danger);
}

/* --- Cards --- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

.card-header {
    padding: 16px 24px;
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 0;
}

.card-body.padded {
    padding: 24px;
}

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

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

table th {
    background: var(--table-header-bg);
    padding: 14px 16px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

table td {
    padding: 14px 16px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border-color);
    border-top: none;
    white-space: nowrap;
}

table tr:hover td {
    background: var(--table-hover-bg);
}

table tr:nth-child(even) td {
    background: var(--table-even-bg);
}

table tr:nth-child(even):hover td {
    background: var(--table-hover-bg);
}

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

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

.text-money {
    font-variant-numeric: tabular-nums;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
}

.btn-primary:hover {
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
}

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

.btn-success:hover {
    background: rgba(34, 197, 94, 0.25);
}

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

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

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

.btn-warning:hover {
    background: rgba(251, 191, 36, 0.25);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 11px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Loading state */
.btn.loading {
    pointer-events: none;
    opacity: 0.65;
}

.btn.loading::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 4px;
}

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

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

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

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

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

.badge-info {
    background: var(--nav-active-bg);
    color: var(--accent-primary);
}

/* --- Forms --- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
    padding: 16px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.form-group small.text-muted {
    display: block;
    font-size: 10.5px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.form-control {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
}

.form-control::placeholder {
    color: var(--text-primary);
    font-style: italic;
}

select.form-control {
    appearance: none;
}

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

/* Search Bar */
.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar .form-control {
    max-width: 260px;
    padding: 7px 12px;
    font-size: 13px;
}

.search-bar .btn {
    padding: 7px 14px;
}

/* --- Alerts --- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: var(--text-success);
}

.alert-danger {
    background: var(--bg-danger);
    border: 1px solid var(--border-danger);
    color: var(--text-danger);
}

.alert-info {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: var(--accent-primary);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.25);
    color: var(--text-warning);
}

/* --- Pagination --- */
.pagination-wrapper {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- Print View Helpers --- */
@media print {

    /* Hide navigational and interactive elements */
    .sidebar,
    .topbar,
    .breadcrumb-bar,
    .app-footer,
    .no-print,
    .search-bar,
    .pagination-wrapper,
    .alert {
        display: none !important;
    }

    /* Reset layout margins for full page utilization */
    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 11pt !important;
    }

    .main {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .content {
        padding: 0 !important;
        margin: 0 !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
        background: #fff !important;
        margin-bottom: 0 !important;
        border-radius: 0 !important;
    }

    .card-header {
        border-bottom: 2px solid #000 !important;
        padding: 0 0 10px 0 !important;
        margin-bottom: 15px !important;
        display: flex !important;
        background: #fff !important;
        color: #000 !important;
    }

    .card-header h2 {
        color: #000 !important;
    }

    /* Optimize tables for printing */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto !important;
    }

    tr {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }

    table th,
    table td {
        color: #000 !important;
        border: 1px solid #ccc !important;
        padding: 6px !important;
        font-size: 10pt !important;
        background: #fff !important;
    }

    table th {
        background: #f3f4f6 !important;
        font-weight: bold !important;
        print-color-adjust: exact !important;
        -webkit-print-color-adjust: exact !important;
    }

    /* Clean up badges */
    .badge {
        background: transparent !important;
        border: 1px solid #000 !important;
        color: #000 !important;
        padding: 2px 6px !important;
    }

    /* Links and bold text */
    strong,
    b {
        color: #000 !important;
    }

    a {
        text-decoration: none !important;
        color: #000 !important;
    }

    /* General print layout */
    @page {
        margin: 1.5cm 1cm;
        size: auto;
    }
}

.pagination-wrapper nav {
    display: flex;
    gap: 4px;
}

.pagination-wrapper nav a,
.pagination-wrapper nav span {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    text-decoration: none;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    transition: all 0.15s;
}

.pagination-wrapper nav a:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.pagination-wrapper nav span[aria-current] {
    background: var(--nav-active-bg);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    font-weight: 600;
}

/* --- Charts grid --- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.charts-grid .card-body {
    padding: 16px;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.empty-state p {
    font-size: 14px;
}

/* --- Utility --- */
.p-4 {
    padding: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.mt-4 {
    margin-top: 16px;
}

.d-flex {
    display: flex;
}

.gap-2 {
    gap: 8px;
}

.gap-3 {
    gap: 12px;
}

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

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

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

.hidden {
    display: none !important;
}

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

.text-sm {
    font-size: 13px;
}

.text-xs {
    font-size: 11px;
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.text-success {
    color: #4ade80 !important;
}

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

.text-warning {
    color: #fbbf24 !important;
}

.text-info {
    color: #818cf8 !important;
}

.text-primary {
    color: #818cf8 !important;
}

.w-full {
    width: 100%;
}

/* --- Table Small (compact) --- */
.table-sm {
    width: 100%;
    border-collapse: collapse;
}

.table-sm td {
    padding: 6px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}

.table-sm tr:last-child td {
    border-bottom: none;
}

/* --- Chart Loading Skeleton --- */
.chart-skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: 0 0 12px 12px;
    z-index: 5;
    transition: opacity 0.3s;
}

.chart-skeleton-text {
    color: var(--text-secondary);
    font-size: 13px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* --- Delete Confirm Modal --- */
.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: var(--bg-surface);
    border: 1px solid #475569;
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.confirm-box h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.confirm-box p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* --- Tooltip --- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #334155;
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 50;
    margin-bottom: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}


/* --- Breadcrumb --- */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumb-bar a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.15s;
    font-weight: 600;
}

.breadcrumb-bar a:hover {
    color: var(--text-secondary);
}

.breadcrumb-bar a::after,
.breadcrumb-bar span:not(:last-child)::after {
    content: '\00BB';
    margin-left: 8px;
    color: var(--text-muted);
    font-weight: 400;
}

.breadcrumb-bar span:last-child {
    color: var(--accent-primary);
    font-weight: 600;
}

.breadcrumb-bar span:last-child::after {
    content: none;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.collapsed {
        width: 260px;
    }

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

    .sidebar.open.collapsed {
        width: 260px;
    }

    /* Show all labels on mobile even if collapsed on desktop */
    .sidebar.collapsed .sidebar-brand h1,
    .sidebar.collapsed .sidebar-brand span,
    .sidebar.collapsed .nav-section-toggle .chevron {
        display: initial;
    }

    .sidebar.collapsed .nav-section-toggle {
        justify-content: space-between;
        padding: 8px 12px;
        font-size: 11px;
    }

    .sidebar.collapsed .nav-link {
        justify-content: flex-start;
        padding: 9px 12px;
        gap: 10px;
    }

    .sidebar.collapsed .nav-link span:not(.icon) {
        display: inline;
    }

    .sidebar.collapsed .nav-link .icon {
        width: 22px;
        font-size: 16px;
    }

    .sidebar.collapsed .sidebar-footer {
        font-size: 12px;
    }

    .sidebar.collapsed .sidebar-footer::before {
        display: none;
    }

    .main {
        margin-left: 0;
    }

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

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .topbar-title {
        font-size: 13px;
    }

    .content {
        padding: 12px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .user-info {
        display: none;
    }

    .card-header {
        padding: 10px 14px;
    }

    .card-header h2 {
        font-size: 13px;
    }
}

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

/* --- Print --- */
@media print {

    .sidebar,
    .topbar,
    .sidebar-backdrop,
    .app-footer,
    .hamburger,
    .btn-logout {
        display: none !important;
    }

    .main {
        margin-left: 0 !important;
    }

    body {
        background: white;
        color: #1e293b;
    }

    .card {
        border: 1px solid #ddd;
    }

    table th {
        background: #f1f5f9;
        color: #334155;
    }

    table td {
        border-top-color: var(--text-primary);
    }
}

/* === v2 Theme Addition: Formula Chips === */
.formula-chip-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
}

.formula-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    margin-right: 8px;
    margin-bottom: 8px;
    color: white;
}

.formula-chip.blue {
    background-color: #3b82f6;
}

.formula-chip.green {
    background-color: #10b981;
}

.formula-chip.orange {
    background-color: #f59e0b;
}

.formula-chip.red {
    background-color: #ef4444;
}

.formula-chip.purple {
    background-color: #8b5cf6;
}

.formula-chip.gray {
    background-color: #64748b;
}

.formula-operator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--bg-main);
    color: var(--text-primary);
    border-radius: 4px;
    font-weight: 600;
    margin: 0 4px;
    font-size: 14px;
}

/* Info Banner Update */
.alert-info.form-builder-guide {
    background: var(--bg-info);
    border: 1px solid var(--border-info);
    color: var(--text-info);
    border-radius: 8px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-info.form-builder-guide svg,
.alert-info.form-builder-guide i,
.alert-info.form-builder-guide .icon {
    font-size: 24px;
    opacity: 0.8;
}

/* Sidebar Icons */
.sidebar-icon {
    display: inline-flex;
    margin-right: 12px;
    width: 20px;
    height: 20px;
    opacity: 0.85;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.nav-link:hover .sidebar-icon {
    opacity: 1;
    color: var(--accent-primary);
}

.nav-link.active .sidebar-icon {
    opacity: 1;
    color: var(--accent-primary);
    transform: scale(1.05);
}

.nav-text {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* SaaS 2.0 - App Switcher & Module Navigation */
.module-switcher {
    display: flex;
    gap: 4px;
    background: var(--bg-main);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.module-tab {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.module-tab:hover {
    color: var(--text-primary);
    background: var(--sidebar-hover);
}

.module-tab.active {
    background: var(--bg-primary);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .module-tab.active {
    background: var(--sidebar-active-bg);
    color: #60a5fa;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.hide-on-mobile {
    display: flex;
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
}

/* SaaS 2.0 - Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    padding-bottom: 2px;
}

.settings-tab {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    margin-bottom: -1px;
    /* Overlap border */
}

.settings-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-radius: 6px 6px 0 0;
}

.settings-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}