:root {
    /* Brand Colors */
    --primary-color: #0B2447;
    /* Deep Navy */
    --primary-light: #19376D;
    /* Lighter Navy */
    --primary-dark: #071a36;
    --secondary-color: #00AEEF;
    /* Cyan/Teal - Highlight */
    --accent-color: #FFC107;
    /* Yellow/Gold - Attention */

    /* Functional Colors */
    --success-color: #28a745;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;

    /* Dark Theme Surface Colors */
    --bg-body: #101014;
    /* Very dark, almost black */
    --bg-card: #1E1E24;
    /* Dark Grey-Blue tint */
    --bg-input: #2B2B36;
    /* Slightly lighter for inputs */
    --border-color: #3A3A45;
    --bg-hover: #2C2C35;

    /* Typography */
    --text-main: #E0E0E0;
    --text-muted: #A0A0A0;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-xxl: 48px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 15px rgba(0, 174, 239, 0.2);

    /* Back to Top Button */
    --btt-bg: rgba(255, 255, 255, 0.1);
    --btt-glow: var(--secondary-color);
}

.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: var(--btt-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 1500;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.back-to-top.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(0, 174, 239, 0.4);
    transform: scale(1.1);
}

/* Global Reset*/
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    /* Kept original variable as --bg-color was not defined */
    color: var(--text-main);
    /* Kept original variable as --text-color was not defined */
    line-height: 1.6;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: #fff;
    margin-top: 0;
}

h1 {
    font-weight: 700;
    letter-spacing: -0.5px;
}

p.lead {
    font-size: 1.1rem;
    color: var(--text-muted);
}

small {
    color: var(--text-muted);
}

a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: #fff;
}

/* Layout Container */
.container {
    max-width: 1200px;
    width: 95%;
    margin: 0 auto;
    padding: var(--spacing-lg) 0;
}

/* Header */
.app-header {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    /* -webkit-backdrop-filter: blur(10px); was removed */
    padding: var(--spacing-md) 0;
    /* box-shadow: var(--shadow-md); was removed */
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    /* padding: 0 var(--spacing-md); was removed */
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    /* Kept original variable as --text-color was not defined */
    font-size: 1.5rem;
    cursor: pointer;
    padding: var(--spacing-xs);
    z-index: 1100;
    transition: all 0.3s ease;
}

.menu-toggle.active {
    color: white !important;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.brand-section {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.brand-logo {
    height: 40px;
    width: auto;
}

.app-title {
    font-size: 1.4rem;
    margin: 0;
    color: #fff;
    font-weight: 600;
}

/* Navigation */
.main-nav {
    display: flex;
    gap: var(--spacing-lg);
}

.nav-link {
    color: var(--text-muted);
    font-weight: 500;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: var(--secondary-color);
    background-color: rgba(0, 174, 239, 0.1);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

.dashboard-grid.two-cols {
    grid-template-columns: 1fr 2fr;
}

/* Cards / Sections */
.section-box,
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: 3px solid var(--primary-light);
    /* Accent top border */
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-action {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 220px;
}

.card-action:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-top-color: var(--secondary-color);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    color: var(--secondary-color);
}

.card-title {
    border-bottom: 2px solid var(--border-color);
    padding-bottom: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    font-size: 1.25rem;
    color: var(--secondary-color);
}

.card-action .card-title {
    border: none;
    margin-bottom: var(--spacing-xs);
    color: #fff;
    font-size: 1.5rem;
}

.card-text {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: var(--spacing-lg);
}

/* Buttons */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    text-decoration: none;
}

/* Primary Button */
button[type="submit"],
.btn-primary {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
}

button[type="submit"]:hover,
.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 174, 239, 0.4);
}

.btn-block {
    display: flex;
    width: 100%;
}

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

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

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

.btn-outline-light:hover {
    border-color: var(--text-main);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* Success/Danger Buttons */
.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

.btn-danger,
.remove-btn {
    background-color: var(--danger-color);
    color: white;
    padding: 6px 12px;
}

.remove-btn {
    width: auto;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Forms & Inputs */
label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.15);
    background-color: #353545;
}

/* Responsive Items (Invoices) */
.item-row {
    display: flex;
    gap: var(--spacing-md);
    align-items: flex-start;
    margin-bottom: var(--spacing-md);
}

/* Grid Layout for Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

/* Table Wrapper for Mobile */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--spacing-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0;
    background-color: var(--bg-card);
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #121215;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

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

tr:hover td {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Badges */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.bg-secondary {
    background-color: #4a4a55;
    color: #fff;
}

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

.bg-warning {
    background-color: var(--warning-color);
    color: #000;
}

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

/* Utils */
.mb-2 {
    margin-bottom: var(--spacing-sm);
}

.mb-3 {
    margin-bottom: var(--spacing-md);
}

.mb-4 {
    margin-bottom: var(--spacing-lg);
}

.mt-3 {
    margin-top: var(--spacing-md);
}

.mt-4 {
    margin-top: var(--spacing-lg);
}

.w-100 {
    width: 100% !important;
}

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

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

.d-flex {
    display: flex;
}

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

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

.gap-2 {
    gap: var(--spacing-sm);
}

.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: var(--spacing-lg) 0;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* --- PREMIUM MODAL SYSTEM --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay:not(.d-none) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg), 0 0 40px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay:not(.d-none) .modal-content {
    transform: translateY(0);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #fff;
}

.modal-body {
    padding: var(--spacing-lg);
}

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

/* Confirmation Modal Specifics */
.confirm-modal .modal-content {
    max-width: 400px;
}

.confirm-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    display: block;
    text-align: center;
}

.confirm-title {
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.confirm-message {
    color: var(--text-muted);
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: var(--spacing-lg);
    white-space: pre-line;
}

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: var(--spacing-sm) 0;
        margin-bottom: var(--spacing-md);
        position: relative;
        /* Disable sticky on mobile as per user request */
        top: auto;
    }

    .container {
        width: 100%;
        padding: var(--spacing-md);
    }

    .header-content {
        flex-direction: row;
        /* Keep logo and hamburger horizontal */
        justify-content: space-between;
        align-items: center;
    }

    .menu-toggle {
        display: block;
        position: relative;
        z-index: 1100;
    }

    .menu-toggle.active {
        position: fixed !important;
        top: 20px !important;
        right: 20px !important;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 50%;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        backdrop-filter: blur(5px);
    }

    .main-nav {
        display: none;
        /* Hide by default on mobile */
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 280px;
        background: rgba(15, 23, 42, 0.98);
        backdrop-filter: blur(20px);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: var(--spacing-xl);
        z-index: 1000;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
        transition: transform 0.3s ease-in-out;
        transform: translateX(100%);
    }

    .main-nav.active {
        display: flex;
        transform: translateX(0);
    }

    .main-nav a {
        font-size: 1.2rem;
        padding: var(--spacing-md) var(--spacing-xl);
        width: 100%;
        text-align: center;
    }

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

    .item-desc {
        flex: 1 1 100%;
    }

    .item-qty,
    .item-price {
        flex: 1;
    }

    .app-title {
        font-size: 1.4rem;
    }

    .dashboard-grid,
    .dashboard-grid.two-cols {
        grid-template-columns: 1fr;
    }

    /* Table adjustments for mobile */
    table {
        min-width: auto;
        /* Removed fixed 600px */
    }

    .table-responsive {
        border-radius: 0;
        margin-left: calc(var(--spacing-md) * -1);
        margin-right: calc(var(--spacing-md) * -1);
        border: none;
        overflow-x: hidden;
        /* Prevent inner scroll since we use cards */
    }

    /* PREMIUM TABLE-TO-CARD CONVERSION */
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody {
        display: block;
        width: 100%;
    }

    .table-mobile-cards tr {
        display: block;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        margin-bottom: var(--spacing-lg);
        padding: var(--spacing-md);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        width: 100%;
    }

    .table-mobile-cards td {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: 12px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        text-align: left;
        width: 100%;
        gap: 4px;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
        padding-top: 15px;
        flex-direction: row;
        /* Keep actions side-by-side if they fit */
        flex-wrap: wrap;
        gap: 10px;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.65rem;
        letter-spacing: 0.8px;
        color: var(--secondary-color);
        opacity: 0.6;
        display: block;
        margin-bottom: 2px;
    }

    .table-mobile-cards td>* {
        width: 100%;
        word-break: break-word;
        overflow-wrap: break-word;
        font-size: 0.95rem;
    }

    .table-mobile-cards td:last-child::before {
        width: 100%;
        margin-bottom: 8px;
    }

    /* Glassmorphism for mobile cards */
    .card {
        backdrop-filter: blur(10px);
        background: rgba(30, 41, 59, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .item-row {
        flex-direction: column;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-color);
        padding: var(--spacing-lg);
        border-radius: var(--radius-lg);
        position: relative;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        backdrop-filter: blur(5px);
    }

    .item-row::before {
        content: "Line Item";
        display: block;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--secondary-color);
        margin-bottom: var(--spacing-sm);
        font-weight: 600;
    }

    .item-row input {
        width: 100% !important;
        background: rgba(255, 255, 255, 0.05) !important;
    }

    .item-row .remove-btn {
        position: absolute;
        top: 15px;
        right: 15px;
        background: rgba(239, 68, 68, 0.1);
        color: #ef4444;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .w-mobile-100 {
        width: 100% !important;
    }

    /* Nav Tabs Mobile Optimization */
    .nav-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 2px solid var(--border-color);
        margin-bottom: var(--spacing-lg);
        padding-bottom: 5px;
        gap: 5px;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
        /* Hide scrollbar but keep functionality */
    }

    .nav-item {
        flex: 0 0 auto;
    }

    .nav-link {
        white-space: nowrap;
        padding: 10px 15px;
        font-size: 0.9rem;
    }

    /* Monthly Summary Actions Mobile */
    .summary-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100%;
        gap: 15px !important;
    }

    .summary-actions input,
    .summary-actions select,
    .summary-actions button {
        width: 100% !important;
        flex: none !important;
    }
}