/* ============================================
   ExpenseFlow v2 — Premium CSS
   Dark/Light themes, responsive design
   ============================================ */

/* CSS Variables — Growth Nerve brand tokens
   Cobalt drives, Green sparks (used sparingly, per brand guideline balance:
   Neutral 62% / Cobalt 26% / Ink 8% / Green 4%). */
:root {
    /* Raw brand palette */
    --gn-cobalt: #0E33E6;
    --gn-cobalt-deep: #0B29B8;
    --gn-green: #45E237;
    --gn-ink: #13171F;
    --gn-slate: #303030;
    --gn-mist: #F4F4F4;
    --gn-sky: #5678F0;

    --bg-primary: #F4F4F4;
    --bg-secondary: #ffffff;
    --bg-tertiary: #EAEAEC;
    --bg-hover: #E1E1E4;
    --text-primary: #13171F;
    --text-secondary: #303030;
    --text-muted: #74747C;
    --border-color: #E3E3E6;
    --border-light: #EFEFF1;
    --shadow-sm: 0 1px 2px rgba(19,23,31,0.06);
    --shadow-md: 0 4px 6px -1px rgba(19,23,31,0.10), 0 2px 4px -2px rgba(19,23,31,0.08);
    --shadow-lg: 0 10px 15px -3px rgba(19,23,31,0.12), 0 4px 6px -4px rgba(19,23,31,0.08);
    --shadow-xl: 0 20px 25px -5px rgba(19,23,31,0.14), 0 8px 10px -6px rgba(19,23,31,0.10);

    --primary: #0E33E6;
    --primary-hover: #0B29B8;
    --primary-light: #E6ECFC;
    --accent-green: #45E237;
    --accent-green-light: #E1FBDD;
    --success: #178C43;
    --success-light: #DCF6E3;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #E23445;
    --danger-light: #FBE1E4;
    --info: #5678F0;
    --info-light: #E8EDFC;

    /* Income/Expense specific colors */
    --income-color: #178C43;
    --income-light: #DCF6E3;
    --expense-color: #E23445;
    --expense-light: #FBE1E4;
    --net-color: #0E33E6;
    --net-light: #E6ECFC;

    /* Sidebar — always on Ink, regardless of light/dark mode (matches the
       kit's "white reversed / on cobalt or dark" lockup guidance) */
    --sidebar-bg: #13171F;
    --sidebar-text: #E7E7EA;
    --sidebar-text-muted: #83868F;
    --sidebar-hover: #1D222D;
    --sidebar-active: #0E33E6;
    --sidebar-accent: #45E237;

    --sidebar-width: 260px;
    --header-height: 72px;
    --border-radius: 16px;
    --border-radius-sm: 10px;
    --border-radius-lg: 20px;
}

[data-theme="dark"] {
    --bg-primary: #13171F;
    --bg-secondary: #1B2029;
    --bg-tertiary: #232935;
    --bg-hover: #2B3240;
    --text-primary: #F4F4F4;
    --text-secondary: #C7C9CE;
    --text-muted: #83868F;
    --border-color: #2B3240;
    --border-light: #1F2530;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.4);
    --primary-light: #1B2A66;
    --accent-green-light: rgba(69, 226, 55, 0.18);
    --success-light: rgba(23, 140, 67, 0.25);
    --warning-light: rgba(245, 158, 11, 0.2);
    --danger-light: rgba(226, 52, 69, 0.22);
    --info-light: rgba(86, 120, 240, 0.2);
    --income-light: rgba(23, 140, 67, 0.25);
    --expense-light: rgba(226, 52, 69, 0.22);
    --net-light: rgba(14, 51, 230, 0.25);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-mark { flex-shrink: 0; }
.logo-wordmark {
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: #fff;
    line-height: 1.15;
}
.logo-wordmark small {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--sidebar-text-muted);
    text-transform: none;
}
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
}
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--sidebar-accent);
}
.nav-item i { font-size: 1.25rem; }
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: var(--sidebar-hover);
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); }
.theme-toggle i { font-size: 1.25rem; }

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}
.header {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 32px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 50;
    backdrop-filter: blur(8px);
}
.header-left { display: flex; flex-direction: column; gap: 2px; }
.page-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; }
.page-subtitle { font-size: 0.875rem; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-icon { padding: 10px; background: transparent; color: var(--text-secondary); }
.btn-icon:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* ============================================
   STATS GRID
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    padding: 24px 32px;
}
.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card.stat-income { background: linear-gradient(135deg, var(--income-color), #059669); border: none; color: #fff; }
.stat-card.stat-expense { background: linear-gradient(135deg, var(--expense-color), #dc2626); border: none; color: #fff; }
.stat-card.stat-net { background: linear-gradient(135deg, var(--net-color), #8b5cf6); border: none; color: #fff; }
.stat-card.stat-income .stat-label,
.stat-card.stat-expense .stat-label,
.stat-card.stat-net .stat-label,
.stat-card.stat-income .stat-change,
.stat-card.stat-expense .stat-change,
.stat-card.stat-net .stat-change { color: rgba(255,255,255,0.8); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: var(--bg-tertiary);
}
.stat-card.stat-income .stat-icon,
.stat-card.stat-expense .stat-icon,
.stat-card.stat-net .stat-icon { background: rgba(255,255,255,0.2); }
.stat-content { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 0.875rem; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-card.stat-income .stat-value,
.stat-card.stat-expense .stat-value,
.stat-card.stat-net .stat-value { color: #fff; }
.stat-change { font-size: 0.75rem; color: var(--text-muted); }
.stats-grid-4 { grid-template-columns: repeat(4, 1fr) !important; }

/* Dashboard Section Headers */
.dashboard-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 32px 8px;
}
.dashboard-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
.dashboard-section-title i { color: var(--primary-color); }
.dashboard-section-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 2px 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}
.dashboard-section-gap { padding: 0 32px; margin-bottom: 20px; }

/* Cash Position */
.cash-position-row { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.cash-chan-label { font-size: 0.75rem; color: var(--text-muted); width: 60px; flex-shrink: 0; }
.cash-input {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    color: #fff;
    padding: 2px 6px;
    width: 80px;
    font-size: 0.85rem;
}
.cash-channel-breakdown {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.cash-chan-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.cash-chan-row .cash-chan-name { display: flex; align-items: center; gap: 4px; }
.cash-chan-row .cash-chan-amount { color: #a78bfa; font-weight: 600; }

/* ============================================
   DASHBOARD GRID
   ============================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding: 0 32px 24px;
}
.dashboard-grid-2 {
    grid-template-columns: repeat(2, 1fr) !important;
}
.dashboard-grid-3 {
    grid-template-columns: repeat(3, 1fr) !important;
}

/* Net Profit Grid */
.net-profit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}
.net-profit-card {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 16px;
    border: 1px solid var(--border-color);
}
.net-profit-card .np-agency { font-weight: 600; font-size: 0.95rem; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.net-profit-card .np-row { display: flex; justify-content: space-between; font-size: 0.8rem; padding: 3px 0; }
.net-profit-card .np-row span:first-child { color: var(--text-muted); }
.net-profit-card .np-row span:last-child { font-weight: 500; }
.net-profit-card .np-row.np-profit { border-top: 1px solid var(--border-color); margin-top: 6px; padding-top: 6px; font-weight: 700; }
.net-profit-card .np-row.np-profit span:last-child { color: var(--income-color); }
.net-profit-card .np-row.np-loss span:last-child { color: var(--expense-color); }
.net-profit-card .np-row.np-subtotal { border-top: 1px dashed var(--border-color); margin-top: 4px; padding-top: 4px; font-weight: 600; }
.net-profit-card .np-row.np-subtotal span:first-child { color: var(--text-primary) !important; }
.net-profit-card .np-clients { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; }

/* Parent company card (Growth Nerve) — fuller deduction chain, distinct visual */
.net-profit-card.np-parent {
    border: 1px solid rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(99, 102, 241, 0.02));
}
.np-parent-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #6366f1;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.np-sublabel {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 4px;
}

/* Founder Salary Grid */
.founder-section-title { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.founder-salary-grid { display: flex; flex-direction: column; gap: 8px; }
.founder-salary-row { display: flex; align-items: center; gap: 10px; }
.founder-salary-row label { flex: 1; font-size: 0.85rem; }
.founder-salary-input { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 6px; padding: 6px 10px; width: 100px; font-size: 0.85rem; color: var(--text-color); text-align: right; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* Client Status */
.client-status-list { display: flex; flex-direction: column; gap: 12px; }
.client-status-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-color); }
.client-status-row:last-child { border-bottom: none; }
.client-status-dot { width: 10px; height: 10px; border-radius: 50%; }
.client-status-name { flex: 1; font-size: 0.85rem; font-weight: 500; }
.client-status-counts { display: flex; gap: 8px; font-size: 0.75rem; }
.client-status-counts span { padding: 2px 8px; border-radius: 10px; }
.count-active { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.count-paused { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.count-churned { background: rgba(107, 114, 128, 0.15); color: #6b7280; }

/* Yearly P&L */
#yearlyPlTable th { background: var(--bg-primary); }
#yearlyPlTable tbody tr.current-month { background: rgba(99, 102, 241, 0.1); font-weight: 600; }
#yearlyPlTable tfoot td { font-weight: 700; background: var(--bg-primary); border-top: 2px solid var(--border-color); }

/* Executive Distribution Dashboard Card */
.exec-dist-grid { display: flex; flex-direction: column; gap: 8px; }
.exec-dist-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border-color); }
.exec-dist-row:last-child { border-bottom: none; }
.exec-dist-row .exec-name { flex: 1; font-size: 0.85rem; font-weight: 500; }
.exec-dist-row .exec-amount { font-size: 0.9rem; font-weight: 700; color: #8b5cf6; }
.exec-dist-row .exec-empty { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }



/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-header h3 i { color: var(--primary); }
.card-body { padding: 24px; }

/* ============================================
   AGENCY INCOME/EXPENSE LISTS
   ============================================ */
.agency-income-list,
.agency-expense-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.agency-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    transition: all 0.2s ease;
}
.agency-item:hover { background: var(--bg-hover); }
.agency-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.agency-name { flex: 1; font-weight: 600; font-size: 0.9rem; }
.agency-amount { font-weight: 700; font-size: 0.9rem; }
.agency-meta { font-size: 0.75rem; color: var(--text-muted); }
.income-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}
.income-badge.paid { background: var(--success-light); color: var(--success); }
.income-badge.partial { background: var(--warning-light); color: var(--warning); }
.income-badge.pending { background: var(--bg-tertiary); color: var(--text-muted); }

/* ============================================
   UPCOMING SPLIT
   ============================================ */
.upcoming-split {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}
.upcoming-section h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}
.upcoming-section h4 i { font-size: 1.1rem; }
.upcoming-section h4 .income-color { color: var(--income-color); }
.upcoming-section h4 .expense-color { color: var(--expense-color); }
.upcoming-list { display: flex; flex-direction: column; gap: 10px; }
.upcoming-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    transition: all 0.2s ease;
}
.upcoming-item:hover { background: var(--bg-hover); }
.upcoming-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.upcoming-info { flex: 1; min-width: 0; }
.upcoming-name { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upcoming-meta { font-size: 0.7rem; color: var(--text-muted); }
.upcoming-date {
    padding: 4px 10px;
    background: var(--warning-light);
    color: var(--warning);
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
[data-theme="dark"] .upcoming-date { background: rgba(245, 158, 11, 0.2); }

/* ============================================
   EXPENSE TABLE
   ============================================ */
.expense-table-wrapper { overflow-x: auto; }
.expense-table { width: 100%; border-collapse: collapse; }
.expense-table th,
.expense-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.expense-table th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
}
.expense-table tbody tr { transition: background 0.2s ease; }
.expense-table tbody tr:hover { background: var(--bg-tertiary); }
.expense-table td { font-size: 0.875rem; }
.expense-name { font-weight: 600; }
.expense-agency {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}
.expense-category {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 500;
}
.expense-amount { font-weight: 700; }
.expense-billing { font-size: 0.75rem; color: var(--text-muted); text-transform: capitalize; }
.expense-renewal { font-size: 0.8rem; color: var(--text-secondary); }
.expense-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}
.expense-status.paid { background: var(--success-light); color: var(--success); }
.expense-status.partial { background: var(--warning-light); color: var(--warning); }
.expense-status.pending { background: var(--bg-tertiary); color: var(--text-muted); }
.payment-cycle-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
.payment-cycle-badge i { font-size: 0.85rem; line-height: 1; }
.payment-cycle-badge.cycle-monthly { background: var(--primary-light); color: var(--primary); }
.payment-cycle-badge.cycle-biweekly { background: var(--warning-light); color: #b45309; }
.expense-actions { display: flex; gap: 4px; }
.expense-actions button {
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
}
.expense-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.expense-actions button.delete:hover { background: var(--danger-light); color: var(--danger); }

/* ============================================
   FILTERS
   ============================================ */
.table-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}
.search-box { position: relative; flex: 1; min-width: 180px; }
.search-box i {
    position: absolute;
    left: 14px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.search-box input {
    width: 100%;
    padding: 10px 14px 10px 42px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}
.search-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.filter-select {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--primary); }

/* ============================================
   CLIENTS GRID
   ============================================ */
/* Client section split (Current / Past) */
.clients-section { margin-bottom: 8px; }
.clients-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0 12px;
}
.clients-section-header h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-secondary);
}
.clients-section-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0 24px;
}
.clients-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}
#currentClientsGrid,
#pastClientsGrid { margin-top: 4px; }

/* Client card */
.client-card,
.agency-card {
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: all 0.2s ease;
}
.client-card:hover,
.agency-card:hover { background: var(--bg-hover); }
.client-avatar,
.agency-avatar {
    width: 48px; height: 48px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}
.client-info,
.agency-info { flex: 1; min-width: 0; }
.clients-grid,
.agencies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.client-name,
.agency-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.client-meta,
.agency-meta { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.client-actions,
.agency-actions { display: flex; gap: 4px; }
.client-actions button,
.agency-actions button {
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
}
.client-actions button:hover,
.agency-actions button:hover { background: var(--bg-secondary); color: var(--text-primary); }
.client-actions button.delete:hover,
.agency-actions button.delete:hover { background: var(--danger-light); color: var(--danger); }

/* ============================================
   CATEGORIES GRID
   ============================================ */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.category-card {
    padding: 18px;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.2s ease;
}
.category-card:hover { background: var(--bg-hover); }
.category-icon {
    width: 44px; height: 44px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    overflow: hidden;
    line-height: 1;
    text-align: center;
    vertical-align: middle;
}
.category-info { flex: 1; }
.category-name { font-weight: 600; font-size: 0.95rem; }
.category-count { font-size: 0.75rem; color: var(--text-muted); }
.category-actions { display: flex; gap: 4px; }
.category-actions button {
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
}
.category-actions button:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 0.875rem; }

/* ============================================
   VIEWS
   ============================================ */
.view {
    display: none;
    padding: 0 32px 32px;
    animation: fadeIn 0.3s ease;
}
.view.active { display: block; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   MODAL
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal.active { display: flex; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 24px;
    margin: 20px;
    animation: modalSlide 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}
@keyframes modalSlide {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.modal-header h3 { font-size: 1.25rem; font-weight: 700; }
.modal-close {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ============================================
   FORM
   ============================================ */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.2s ease;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-group select:disabled { opacity: 0.6; cursor: not-allowed; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    font-weight: 500;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 300;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast i { font-size: 1.25rem; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-tertiary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .upcoming-split { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .main-content { margin-left: 0; }
    .header { padding: 0 16px; }
    .header-actions { gap: 8px; }
    .btn span { display: none; }
    .btn { padding: 10px 12px; }
    .stats-grid { padding: 16px; grid-template-columns: 1fr 1fr; }
    .view { padding: 0 16px 24px; }
    .card-header { flex-direction: column; align-items: flex-start; }
    .table-filters { flex-direction: column; }
    .search-box { width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .expense-table th:nth-child(6),
    .expense-table td:nth-child(6),
    .expense-table th:nth-child(7),
    .expense-table td:nth-child(7) { display: none; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-title { font-size: 1.25rem; }
    .stat-card { padding: 16px; }
    .stat-value { font-size: 1.5rem; }
    .clients-grid,
    .agencies-grid,
    .categories-grid { grid-template-columns: 1fr; }
}

/* ============================================
   Payroll View — embedded SPA
   ============================================ */
.payroll-view { padding: 32px; overflow-y: auto; box-sizing: border-box; }
.payroll-view .page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 24px; color: var(--text-primary); display: flex; align-items: center; gap: 10px; }

/* Section headers */
.payroll-view .section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.payroll-view .section-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.payroll-view .section-title i { font-size: 1.1rem; }
.payroll-view .section-title.exec i { color: #8b5cf6; }
.payroll-view .section-title.emp i { color: #10b981; }
.payroll-view .section-badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--bg-tertiary); color: var(--text-secondary); }
.payroll-view .section-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Executive cards */
.payroll-view .exec-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 32px; }
.payroll-view .exec-card { background: var(--bg-tertiary); border-radius: var(--border-radius); padding: 20px; border-left: 4px solid #8b5cf6; transition: all 0.2s; }
.payroll-view .exec-card:hover { background: var(--bg-hover); }
.payroll-view .exec-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.payroll-view .exec-avatar { width: 44px; height: 44px; border-radius: 50%; background: #8b5cf620; color: #8b5cf6; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.payroll-view .exec-name { font-weight: 700; font-size: 1rem; }
.payroll-view .exec-role { font-size: 0.8rem; color: var(--text-secondary); }
.payroll-view .exec-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.payroll-view .exec-stat { background: var(--bg-primary); border-radius: 8px; padding: 10px 12px; }
.payroll-view .exec-stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.payroll-view .exec-stat-value { font-size: 0.95rem; font-weight: 600; }
.payroll-view .emp-actions { display: flex; gap: 6px; margin-top: 12px; }
.payroll-view .emp-actions .btn { font-size: 0.75rem; padding: 5px 10px; }

/* Employee cards */
.payroll-view .emp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 32px; }
.payroll-view .emp-card { background: var(--bg-tertiary); border-radius: var(--border-radius); padding: 20px; border-left: 4px solid #10b981; transition: all 0.2s; }
.payroll-view .emp-card:hover { background: var(--bg-hover); }
.payroll-view .emp-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.payroll-view .emp-avatar { width: 44px; height: 44px; border-radius: 50%; background: #10b98120; color: #10b981; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.payroll-view .emp-name { font-weight: 700; font-size: 0.95rem; }
.payroll-view .emp-role { font-size: 0.8rem; color: var(--text-secondary); }
.payroll-view .emp-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.payroll-view .emp-badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 6px; font-weight: 500; }
.payroll-view .emp-badge.dept { background: #3b82f620; color: #3b82f6; }
.payroll-view .emp-badge.emp-type { background: #f5910a20; color: #f5910a; }
.payroll-view .emp-badge.company { background: #6366f120; color: #6366f1; }
.payroll-view .emp-badge.active { background: #10b98120; color: #10b981; }
.payroll-view .emp-badge.inactive { background: #ef444420; color: #ef4444; }
.payroll-view .emp-salary { background: var(--bg-primary); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.payroll-view .emp-salary-row { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 4px; }
.payroll-view .emp-salary-row:last-child { margin-bottom: 0; }
.payroll-view .emp-salary-label { color: var(--text-secondary); }
.payroll-view .emp-salary-value { font-weight: 600; }

/* Log tables */
.payroll-view .log-section { margin-top: 32px; }
.payroll-view .log-table-wrap { overflow-x: auto; border-radius: var(--border-radius); background: var(--bg-tertiary); }
.payroll-view .log-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 700px; }
.payroll-view .log-table th { background: var(--bg-primary); padding: 12px 14px; text-align: left; font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); white-space: nowrap; border-bottom: 1px solid var(--border-color); }
.payroll-view .log-table td { padding: 10px 14px; border-top: 1px solid var(--border-color); vertical-align: middle; }
.payroll-view .log-table tr:hover td { background: var(--bg-hover); }
.payroll-view .log-table .source-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 600; }
.payroll-view .log-table .source-executive { background: #8b5cf620; color: #8b5cf6; }
.payroll-view .log-table .source-employee { background: #10b98120; color: #10b981; }
.payroll-view .log-table .type-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 500; }
.payroll-view .log-table .type-salary { background: #3b82f620; color: #3b82f6; }
.payroll-view .log-table .type-profit-share { background: #f5910a20; color: #f5910a; }
.payroll-view .log-table .type-project { background: #6366f120; color: #6366f1; }
.payroll-view .log-table .amount-col { font-weight: 600; text-align: right; }
.payroll-view .log-table .actions-col { text-align: right; white-space: nowrap; }
.payroll-view .log-table .actions-col button { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 4px; color: var(--text-secondary); font-size: 0.9rem; }
.payroll-view .log-table .actions-col button:hover { background: var(--bg-primary); color: var(--text-primary); }
.payroll-view .log-table .actions-col button.delete:hover { background: #ef444420; color: #ef4444; }
.payroll-view .log-table .company-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.7rem; background: var(--bg-primary); color: var(--text-secondary); }
.payroll-view .log-table .empty-log { text-align: center; padding: 40px; color: var(--text-muted); }
.payroll-view .log-divider { border-top: 1px solid var(--border-color); margin: 40px 0 32px; }

/* Payroll modals — inside .modal (shared with main app) */
#execModal .modal-body,
#empModal .modal-body,
#empPayrollModal .modal-body,
#execDistModal .modal-body { padding: 0; }
#execModal .form-row,
#empModal .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
#execModal .form-row.three-col,
#empModal .form-row.three-col { grid-template-columns: 1fr 1fr 1fr; }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-weight: 500;
}
.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #4f46e5;
}
.form-hint {
    margin: 6px 0 0 26px;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.4;
}
.auto-generated-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
    padding: 2px 8px;
    background: #ddd6fe;
    color: #5b21b6;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 600;
    vertical-align: middle;
}
.auto-generated-badge i { font-size: 0.75rem; line-height: 1; }
.schedule-card { border-left: 3px solid #6366f1; }
.schedule-card.paused { border-left-color: #9ca3af; opacity: 0.7; }
.schedule-meta { font-size: 0.75rem; color: var(--text-muted); }
.schedule-action-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}
.schedule-action-btn:hover { background: var(--bg-tertiary); }
.schedule-action-btn.danger { color: #dc2626; border-color: #fecaca; }
.schedule-action-btn.danger:hover { background: #fee2e2; }
.schedule-action-btn.primary { background: #4f46e5; color: white; border-color: #4f46e5; }
.schedule-action-btn.primary:hover { background: #4338ca; }

/* ============================================
   DASHBOARD: This Month highlight card
   ============================================ */
.this-month-card {
    border: 1px solid #c7d2fe;
    background: linear-gradient(135deg, #eef2ff 0%, #faf5ff 50%, #fef3c7 100%);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.12);
    margin-bottom: 18px;
    overflow: hidden;
}
body[data-theme="dark"] .this-month-card,
.dark-mode .this-month-card {
    background: linear-gradient(135deg, #1e1b4b 0%, #2e1065 50%, #422006 100%);
    border-color: #4338ca;
}
.this-month-header {
    background: linear-gradient(90deg, #4f46e5 0%, #7c3aed 50%, #f59e0b 100%);
    color: #fff;
    padding: 14px 20px;
    margin: -1px -1px 0 -1px;
    border-bottom: none;
}
.this-month-header h2,
.this-month-header h3 {
    color: #fff;
    font-size: 1.25rem;
    margin: 0;
}
.this-month-title { display: flex; align-items: center; gap: 8px; }
.this-month-subtitle {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 500;
    margin-left: auto;
}
.this-month-grid { grid-template-columns: repeat(4, 1fr) !important; }
.this-month-grid-2 { grid-template-columns: repeat(4, 1fr) !important; }
.this-month-grid-3 { grid-template-columns: repeat(3, 1fr) !important; }
.stat-card.stat-payroll { border-left: 3px solid #a855f7; }
.stat-card.stat-gross { border-left: 3px solid #06b6d4; }

/* ============================================
   DASHBOARD: Previous Month at a Glance
   ============================================ */
.prev-month-card { margin-bottom: 18px; }
.prev-month-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}
.prev-month-tile {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
    border-top: 3px solid var(--border-color);
}
.prev-month-tile .prev-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}
.prev-month-tile .prev-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}
.prev-month-tile.prev-income { border-top-color: #10b981; }
.prev-month-tile.prev-expense { border-top-color: #ef4444; }
.prev-month-tile.prev-payroll { border-top-color: #a855f7; }
.prev-month-tile.prev-net { border-top-color: #06b6d4; }
.prev-month-tile.prev-clients { border-top-color: #6366f1; }
.prev-month-tops {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.prev-tops-col h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.prev-tops-list { list-style: none; padding: 0; margin: 0; }
.prev-tops-list li {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.85rem;
    border-bottom: 1px dashed var(--border-color);
}
.prev-tops-list li:last-child { border-bottom: none; }
.prev-tops-list li.empty-mini {
    color: var(--text-muted);
    font-style: italic;
    justify-content: center;
    border: none;
}
.prev-tops-list li .amt { font-weight: 700; color: var(--text-primary); }

/* Fix Cash Position opening input border in light mode */
body:not(.dark-mode) .cash-input,
body:not([data-theme="dark"]) .cash-input,
.cash-input {
    background: #ffffff !important;
    border: 1px solid #d1d5db !important;
    color: #111827 !important;
}
body:not(.dark-mode) .cash-input:focus,
body:not([data-theme="dark"]) .cash-input:focus,
.cash-input:focus {
    border-color: #4f46e5 !important;
    outline: none;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.dark-mode .cash-input,
body[data-theme="dark"] .cash-input {
    background: #1f2937 !important;
    border: 1px solid #374151 !important;
    color: #f9fafb !important;
}
.dark-mode .cash-input:focus,
body[data-theme="dark"] .cash-input:focus {
    border-color: #818cf8 !important;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.25);
}
