/*
==================================================
  InvoicePunjabi - Main Stylesheet (Consolidated)
==================================================
*/

/* --- 1. BASE & ROOT STYLES --- */
:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent-blue: #2f81f7;
    --accent-blue-hover: #4895ff;
    --btn-primary-bg: #0280D5;
    --btn-primary-hover-bg: #026bb1;
    --btn-primary-border: #2d6d36;
    --danger-red: #da3633;
    --danger-hover-bg: rgba(218, 54, 51, 0.1);
    --nav-bg-hover: #09304F;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: var(--accent-blue);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* --- 2. REUSABLE COMPONENTS --- */

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 24px;
    margin-bottom: 24px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.25rem;
    font-weight: 600;
}

.card-header .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-blue);
}
.card-header .orange-dot {
    background-color: #F77825;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
    box-sizing: border-box;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.4);
}
textarea.form-control { min-height: 120px; resize: vertical; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 16px;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: background-color 0.2s, border-color 0.2s;
    background-color: #21262d;
    color: var(--text-primary);
    white-space: nowrap;
}
.btn:hover {
    background-color: #30363d;
    border-color: var(--text-secondary);
    text-decoration: none;
}

.btn-primary {
    background-color: var(--btn-primary-bg);
    color: #fff;
    border-color: var(--btn-primary-border);
}
.btn-primary:hover {
    background-color: var(--btn-primary-hover-bg);
    border-color: var(--btn-primary-border);
}

.btn-danger {
    color: var(--danger-red);
    background-color: transparent;
    border: none;
    padding: 8px;
    line-height: 1;
}
.btn-danger:hover {
    background-color: var(--danger-hover-bg);
}

/* Alert Messages */
.alert {
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 6px;
}
.alert-danger {
    color: #ffb3b3;
    background-color: rgba(218, 54, 51, 0.15);
    border-color: rgba(218, 54, 51, 0.3);
}
.alert-success {
    color: #7ee787;
    background-color: #1c3223;
    border-color: #264930;
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- 3. PAGE-SPECIFIC STYLES --- */

/* Header & Navigation */
.main-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo-icon { width: 28px; height: 28px; flex-shrink: 0; vertical-align: middle;}
.main-nav { display: flex; align-items: center; gap: 8px; }
.main-nav a {
    color: var(--text-primary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
    border: 1px solid transparent;
}
.main-nav a:hover {
    background-color: var(--nav-bg-hover);
    color: var(--btn-primary-bg);
    text-decoration: none;
}
.main-nav a.active {
    background-color: var(--accent-blue);
    color: white;
}
.main-nav .btn { padding: 8px 16px; font-weight: bold; }
.main-nav .btn-primary { background-color: var(--accent-blue); border-color: transparent;}
.main-nav .btn-primary:hover { background-color: var(--accent-blue-hover); }

.mobile-nav-toggle {
    display: none;
    background: transparent;
    border: 0;
    padding: 0.5rem;
    cursor: pointer;
}
.mobile-nav-toggle .icon-close { display: none; }
.mobile-nav-toggle .icon-hamburger { display: block; }
.mobile-nav-toggle[aria-expanded="true"] .icon-close { display: block; color: var(--text-primary); }
.mobile-nav-toggle[aria-expanded="true"] .icon-hamburger { display: none; }

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}
.desktop-invoice-table { width: 100%; border-collapse: collapse; }
.desktop-invoice-table th, .desktop-invoice-table td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border-color); }
.desktop-invoice-table th { color: var(--text-secondary); font-size: 0.9rem; text-transform: uppercase; }
.desktop-invoice-table tr:last-child td { border-bottom: none; }
.desktop-invoice-table td .btn { padding: 5px 10px; font-size: 0.9rem; }
.mobile-invoice-list { display: none; } /* Hidden on desktop */
.mobile-invoice-card { padding: 1rem 0; border-bottom: 1px solid var(--border-color); }
.mobile-invoice-card:last-child { border-bottom: none; padding-bottom: 0; }
.mobile-invoice-card:first-child { padding-top: 0; }
.mobile-invoice-row { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0; }
.mobile-invoice-row .label { color: var(--text-secondary); font-size: 0.9rem; }
.mobile-invoice-row .value { font-weight: 600; text-align: right; }
.mobile-invoice-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; }
.mobile-invoice-actions .btn { flex-grow: 1; text-align: center; }

/* Invoice Generator */
.invoice-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 24px; }
.invoice-header h1 { margin: 0; }
.invoice-header .card-header { margin-bottom: 0; border: none; padding: 0; }
.invoice-header-actions { display: flex; gap: 0.5rem; }
.invoice-details-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.service-items-container { overflow-x: auto; }
.service-items-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.service-items-table th, .service-items-table td { padding: 12px; text-align: left; vertical-align: top; }
.service-items-table thead { color: var(--text-secondary); border-bottom: 2px solid var(--border-color); }
.service-items-table th { font-size: 0.9rem; }
.service-items-table tbody tr { border-bottom: 1px solid var(--border-color); }
.service-items-table tbody tr:last-child { border-bottom: none; }
.service-items-table input { font-size: 1rem; padding: 8px; }
.item-total-display { font-weight: bold; padding-top: 20px !important; }
.item-actions-cell { text-align: right !important; }
.totals-section { margin-left: auto; width: 100%; max-width: 350px; margin-top: 24px; }
.totals-section div { display: flex; justify-content: space-between; padding: 8px 0; font-size: 1.1rem; }
.totals-section .grand-total { font-weight: bold; font-size: 1.3rem; border-top: 2px solid var(--border-color); margin-top: 8px; padding-top: 16px; }

.invoice-main-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.invoice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }

/* --- 4. RESPONSIVE STYLES --- */
/* Tablet (and down) */
@media (max-width: 900px) { 
    .invoice-details-grid,
    .invoice-main-grid,
    .invoice-grid { 
        grid-template-columns: 1fr; 
        }
}

/* Mobile (and down) */
@media (max-width: 768px) {
    /* Responsive Header */
    .main-header {
        flex-direction: row;
        justify-content: space-between;
        padding: 1rem 1.5rem;
    }
    .mobile-nav-toggle {
        display: block;
        color: var(--text-primary);
        z-index: 1000;
    }
    .main-nav {
        position: fixed;
        z-index: 999;
        inset: 0 0 0 30%; /* top, right, bottom, left */
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 1.5rem;
        padding: 6rem 2rem;
        background: hsl(212 28% 12% / 0.8);
        backdrop-filter: blur(1rem);
        transform: translateX(100%);
        transition: transform 350ms ease-out;
    }
    .main-nav[data-visible="true"] { transform: translateX(0%); }
    .main-nav a { font-size: 1rem; width: 80%; }
    .main-nav .btn-primary { width: 100%; text-align: center; padding: 1rem; }
    .main-nav .nav-logout { color: var(--text-secondary); }

    /* Responsive Dashboard */
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
    }
    .dashboard-header > a { text-align: center; }
    .desktop-invoice-table { display: none; }
    .mobile-invoice-list { display: block; }

    /* Responsive Invoice Generator */
    .invoice-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    .invoice-header h1 { font-size: 1.8rem; text-align: center; }
    .invoice-header-actions { justify-content: center; }
    .service-items-table thead { display: none; }
    .service-items-table, .service-items-table tbody, .service-items-table tr, .service-items-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }
    .service-items-table tr.item-row { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); }
    .service-items-table tbody tr:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
    .service-items-table td { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border: none; }
    .service-items-table td::before {
        content: attr(data-label);
        font-weight: bold;
        color: var(--text-secondary);
        padding-right: 1rem;
    }
    .service-items-table td.item-actions-cell { justify-content: flex-end; }
    .service-items-table td.item-actions-cell::before { display: none; }
    .service-items-table input { width: 60%; text-align: right; }
    .item-total-display { padding: 0 !important; }
    .totals-section { max-width: none; }
}

/* --- Dashboard Upgrades: Stats, Filters, Exports --- */
.text-secondary {
    color: var(--text-secondary);
}

.stats-card {
    background: linear-gradient(145deg, var(--accent-blue), #2358ad);
    color: white;
    padding: 2rem;
    text-align: center;
}
.stats-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.2rem;
    font-weight: 500;
    opacity: 0.8;
}
.stats-amount {
    margin: 0;
    font-size: 2.5rem;
    font-weight: 700;
}

.filter-export-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.filter-export-header .card-header {
    border: none;
    padding: 0;
    margin: 0;
}
.export-buttons,
.filter-btns {
    display: flex;
    gap: 0.5rem;
}
.export-buttons .btn {
    white-space: nowrap;
}

.filter-form .filter-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-form .form-control {
    min-width: 150px;
}
.filter-form .custom-date-inputs {
    display: none; /* Hidden by default, JS will show it */
    gap: 1rem;
}
.filter-form .btn {
    padding-top: 10px;
    padding-bottom: 10px;
}

@media (max-width: 768px) {
    .filter-export-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    .filter-export-header .export-buttons,
    .filter-btns {
        justify-content: space-between;
    }
    .export-buttons .btn,
    .filter-btns .btn {
        flex-grow: 1;
    }
    .filter-form .filter-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-form .custom-date-inputs {
        flex-direction: column;
    }
}

/* Dashboard Earning & Filters Style */
.dashboard-stats-container {
  display: flex;
  gap: 40px;
  align-items: stretch;
}
.dashboard-stats-container > .card {
  flex: 1 1 50%;
}
@media (max-width: 768px) {
  .dashboard-stats-container {
    display: block;
  }
}