:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --bg-dark: #f8fafc;
    --bg-card: #ffffff;
    --text-light: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --error: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    line-height: 1.6;
}

/* Views Management */
.view {
    display: none;
}
.view.active {
    display: block;
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.login-box {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-box h2 {
    margin-bottom: 0.5rem;
    color: var(--primary);
}
.login-box p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Forms */
.input-group {
    margin-bottom: 1rem;
    text-align: left;
}
.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.input-group input, .input-group textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-light);
    font-size: 1rem;
    transition: border-color 0.2s;
}
.input-group input:focus, .input-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.full-width {
    grid-column: 1 / -1;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}
.btn-primary:hover {
    background: var(--primary-dark);
}
.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    background: var(--primary);
    color: white;
}
.mt-1 { margin-top: 1rem; }
.error-msg {
    color: var(--error);
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Dashboard Layout & Navigation Header */
.app-header {
    background: var(--bg-card);
    padding: 0.75rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.02em;
    user-select: none;
}
.nav-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.55rem 0.95rem;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    transition: all 0.2s ease;
    user-select: none;
}
.nav-btn:hover {
    color: var(--text-light);
    background: rgba(15, 23, 42, 0.05);
}
.nav-btn.active {
    color: var(--primary);
    background: rgba(16, 185, 129, 0.1);
    font-weight: 600;
}
.nav-btn.logout:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.08);
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    color: var(--text-light);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.mobile-menu-toggle:hover {
    background: #f1f5f9;
}
.mobile-nav-actions {
    display: none;
}

/* Navigation Dropdown */
.nav-dropdown {
    position: relative;
    display: inline-block;
}
.nav-dropdown-btn .dropdown-chevron {
    transition: transform 0.2s ease;
    margin-left: 0.15rem;
}
.nav-dropdown:hover .nav-dropdown-btn .dropdown-chevron,
.nav-dropdown.open .nav-dropdown-btn .dropdown-chevron {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 250px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    padding: 0.4rem;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: none;
}
.nav-dropdown:hover .dropdown-menu,
.nav-dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
    font-family: inherit;
    text-decoration: none;
}
.dropdown-item:hover {
    background: #f1f5f9;
}
.dropdown-item.active-sub {
    background: rgba(16, 185, 129, 0.1);
}
.dropdown-item.active-sub .dropdown-title {
    color: var(--primary);
    font-weight: 600;
}
.dropdown-icon {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #f8fafc;
    border-radius: 6px;
    flex-shrink: 0;
}
.dropdown-item:hover .dropdown-icon {
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.dropdown-text {
    display: flex;
    flex-direction: column;
}
.dropdown-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #1e293b;
    line-height: 1.25;
}
.dropdown-sub {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.15rem;
}
.dropdown-divider {
    height: 1px;
    background: #f1f5f9;
    margin: 0.3rem 0.4rem;
}

.dashboard-content {
    max-width: 98%;
    width: 98%;
    margin: 1.25rem auto;
    padding: 0 0.5rem;
}

/* Dashboard Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}
.metric-card h3 {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.metric-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-light);
}

/* Status Badges */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    display: inline-block;
}
.badge.paid {
    background: #dcfce7;
    color: #166534;
}
.badge.pending {
    background: #fef08a;
    color: #854d0e;
}

.header-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}
.header-action .btn-primary {
    width: auto;
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 0.75rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 0.88rem;
}
th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    background: #f8fafc;
}
tbody tr {
    transition: background-color 0.15s ease;
}
tbody tr:hover {
    background-color: #f1f5f9;
}
.items-table input {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-light);
}
.items-table .btn-remove {
    background: var(--error);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.5rem;
    cursor: pointer;
}

/* Invoice Summary */
.invoice-summary {
    display: flex;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}
.totals {
    width: 300px;
}
.totals p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.grand-total {
    font-size: 1.25rem;
    color: var(--primary);
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    margin-top: 0.5rem;
}
.words {
    width: 100%;
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.form-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}
.form-actions button {
    width: auto;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 100;
}
.modal.active { display: flex; justify-content: center; align-items: center; }
.modal-content {
    background: #fff;
    color: #000;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 8px;
    position: relative;
    padding: 2rem;
}
.close-btn {
    position: absolute;
    top: 1rem; right: 1.5rem;
    font-size: 2rem;
    cursor: pointer;
    color: #333;
}
.modal-actions {
    margin-top: 2rem;
    text-align: right;
}
.modal-actions .btn-primary { width: auto; }

/* Print Template Styles for Preview */
.print-wrap {
    font-family: Arial, sans-serif;
    color: #000;
}
.print-wrap .header {
    text-align: center;
    border-bottom: 2px solid #000;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.print-wrap .header h1 { color: #10b981; margin-bottom: 5px; }
.print-wrap .details {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
}
.print-wrap table.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}
.print-wrap table.invoice-table th, .print-wrap table.invoice-table td {
    border: 1px solid #000;
    padding: 8px;
    text-align: center;
}
.print-wrap table.invoice-table th { background: #f0f0f0; }
.print-wrap .footer {
    display: flex;
    justify-content: space-between;
    border-top: 2px solid #000;
    padding-top: 1rem;
}

/* Table Action Cell & Small Buttons */
.action-cell {
    display: flex;
    gap: 0.4rem;
    flex-wrap: nowrap;
    white-space: nowrap;
    align-items: center;
}
.btn-sm {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.78rem !important;
    font-weight: 500 !important;
    width: auto !important;
    white-space: nowrap !important;
    margin: 0 !important;
}

/* Invoice Upload Dropzone */
.invoice-upload-box {
    border: 2px dashed #cbd5e1;
    background: #f8fafc;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    text-align: center;
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    position: relative;
}
.invoice-upload-box:hover, .invoice-upload-box.drag-over {
    border-color: #10b981;
    background: #f0fdf4;
}
.invoice-upload-box .upload-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #e6fcf5;
    color: #059669;
    margin-bottom: 0.5rem;
}
.invoice-upload-box .upload-title {
    font-weight: 600;
    color: #1e293b;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}
.invoice-upload-box .upload-sub {
    font-size: 0.82rem;
    color: #64748b;
}
.invoice-upload-box .upload-status {
    display: none;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
}
.invoice-upload-box .upload-status.processing {
    display: block;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}
.invoice-upload-box .upload-status.success {
    display: block;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}
.invoice-upload-box .upload-status.error {
    display: block;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}
.field-highlight {
    animation: highlightPulse 2s ease-out;
}
@keyframes highlightPulse {
    0% { background-color: #bbf7d0 !important; border-color: #16a34a !important; }
    50% { background-color: #dcfce7 !important; }
    100% { background-color: var(--bg-dark) !important; border-color: var(--border) !important; }
}

/* Inactivity Lock Screen & Biometric Passkey Styling */
.lock-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}
.lock-overlay.active {
    display: flex;
}
.lock-box {
    background: #ffffff;
    border-radius: 16px;
    padding: 2.25rem 2.5rem;
    max-width: 440px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    border: 1px solid #e2e8f0;
    animation: lockPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes lockPopIn {
    0% { transform: scale(0.92); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.lock-avatar-icon {
    width: 60px;
    height: 60px;
    background: #ecfdf5;
    color: #10b981;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem auto;
    border: 2px solid #a7f3d0;
}
.btn-biometric {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}
.btn-biometric:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}
.divider-text {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.25rem 0;
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.divider-text::before, .divider-text::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #e2e8f0;
}
.divider-text::before { margin-right: .5em; }
.divider-text::after { margin-left: .5em; }

/* ==========================================================================
   Responsive & Mobile-Friendly Media Queries
   ========================================================================== */

/* Tablets and Mobile Devices (<= 860px) */
@media (max-width: 860px) {
    .app-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        position: relative;
    }
    .header-left {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
    }
    .mobile-menu-toggle {
        display: inline-flex;
    }
    .header-right {
        display: none; /* Relocated inside mobile drawer */
    }

    /* Mobile Nav Drawer */
    .nav-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border);
        background: #ffffff;
    }
    .nav-menu.mobile-open {
        display: flex;
        animation: mobileMenuSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }
    @keyframes mobileMenuSlide {
        0% { opacity: 0; transform: translateY(-8px); }
        100% { opacity: 1; transform: translateY(0); }
    }

    .nav-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }
    .nav-dropdown {
        width: 100%;
    }
    .nav-dropdown-btn {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .dropdown-menu {
        position: static;
        width: 100%;
        box-shadow: none;
        border: 1px solid var(--border);
        background: #f8fafc;
        margin-top: 0.35rem;
        opacity: 1;
        visibility: visible;
        transform: none;
        pointer-events: auto;
        display: none;
        padding: 0.35rem;
    }
    .nav-dropdown.open .dropdown-menu {
        display: block;
    }
    .dropdown-item {
        padding: 0.65rem 0.75rem;
    }

    .mobile-nav-actions {
        display: flex;
        flex-direction: column;
        gap: 0.4rem;
        margin-top: 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px dashed var(--border);
    }

    .dashboard-content {
        max-width: 100%;
        width: 100%;
        padding: 0 0.75rem;
        margin: 0.75rem auto;
    }

    /* Header Actions & Toolbars */
    .header-action {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }
    .header-action > div {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .header-action button {
        flex: 1 1 auto;
        justify-content: center;
        text-align: center;
    }

    /* Filter Toolbars */
    .filter-toolbar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem !important;
        padding: 0.85rem !important;
    }
    .filter-toolbar > div {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* Dashboard Metrics Cards (2 columns on mobile) */
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
    .metric-card {
        padding: 0.85rem 0.95rem;
    }
    .metric-card h3 {
        font-size: 0.75rem;
        line-height: 1.3;
    }
    .metric-card .value {
        font-size: 1.25rem !important;
        margin-top: 0.25rem;
        word-break: break-all;
    }

    /* Form Layouts */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    .form-card {
        padding: 1.25rem 1rem !important;
    }
    .form-actions {
        flex-direction: column-reverse !important;
        gap: 0.75rem !important;
    }
    .form-actions button {
        width: 100% !important;
    }

    /* Line Items Table in Invoice Form */
    .items-table th, .items-table td {
        padding: 0.5rem !important;
        font-size: 0.85rem !important;
    }

    /* Modals */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 1.25rem 1rem !important;
        max-height: 90vh !important;
    }
    .lock-box {
        padding: 1.75rem 1.25rem !important;
        width: 92% !important;
    }
}

/* Small Smart Phones (<= 480px) */
@media (max-width: 480px) {
    .logo {
        font-size: 1.1rem;
    }
    .metrics-grid {
        grid-template-columns: 1fr !important;
        gap: 0.65rem !important;
    }
    .metric-card {
        padding: 0.75rem 0.85rem;
    }
    .metric-card .value {
        font-size: 1.35rem !important;
    }
    .login-container {
        padding: 1rem 0.5rem;
    }
    .login-box {
        padding: 1.75rem 1.25rem !important;
        width: 100% !important;
        box-shadow: none;
        border: 1px solid var(--border);
    }
    .input-group input, .input-group select, .input-group textarea {
        font-size: 16px !important; /* Prevents auto-zoom on iOS */
    }
    .table-container {
        border-radius: 6px;
    }
    .data-table th, .data-table td {
        padding: 0.6rem 0.5rem !important;
        font-size: 0.82rem !important;
    }
    .action-cell {
        gap: 0.25rem;
    }
    .btn-sm {
        padding: 0.35rem 0.5rem !important;
        font-size: 0.74rem !important;
    }
}

