:root {
    /* Colors - Premium Palette */
    --primary: #2563EB;
    /* Royal Blue */
    --primary-dark: #1E40AF;
    --primary-light: #60A5FA;
    --accent: #10B981;
    /* Emerald */

    --bg-body: #F3F4F6;
    /* Cool Gray 100 */
    --bg-surface: #FFFFFF;
    --bg-sidebar: #0F172A;
    /* Slate 900 */

    --text-main: #1F2937;
    /* Gray 800 */
    --text-muted: #6B7280;
    /* Gray 500 */
    --text-on-dark: #F9FAFB;

    --border-light: #E5E7EB;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: --bg-body;
    /* Fallback */
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
}

a {
    text-decoration: none;
    color: inherit;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: var(--text-on-dark);
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    flex-shrink: 0;
}

.brand {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: var(--primary-light);
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    color: #9CA3AF;
    transition: all 0.2s;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
}

.nav-item:hover,
.nav-item.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-on-dark);
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.top-bar {
    height: 70px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-xl);
}

#page-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.username {
    font-size: 0.875rem;
    font-weight: 500;
}

.content-view {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
}

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

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

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

/* Utility Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 0.5rem;
    font-size: 0.875rem;
}

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

.btn-primary:hover {
    background-color: var(--primary-dark);
}

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

.btn-secondary:hover {
    background-color: var(--bg-body);
}

.btn-danger {
    background-color: #EF4444;
    color: white;
}

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

.w-full {
    width: 100%;
}

.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-light);
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.table th {
    text-align: left;
    padding: var(--spacing-md);
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
    background-color: #F9FAFB;
}

.table td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

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

.badge {
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background-color: #D1FAE5;
    color: #065F46;
}

.badge-warning {
    background-color: #FEF3C7;
    color: #92400E;
}

.badge-gray {
    background-color: #F3F4F6;
    color: #4B5563;
}

/* Professional Minimalist Design */
.invoice-modern {
    background: white;
    padding: 0;
    max-width: 800px;
    margin: 0 auto;
    color: #111827;
    /* Darker black for print legibility */
}

/* Header */
.invoice-header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #E5E7EB;
}

.invoice-brand-section {
    max-width: 50%;
}

.invoice-meta-section {
    text-align: right;
}

.invoice-title-large {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.invoice-number-large {
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--text-main);
}

/* Info Grid (Clean, no boxes) */
.invoice-info-grid {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4rem;
}

.invoice-info-col {
    width: 45%;
}

.invoice-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.invoice-value-primary {
    font-size: 1.125rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 0.25rem;
}

.invoice-value-secondary {
    font-size: 0.95rem;
    color: #4B5563;
    line-height: 1.5;
}

/* Table (Clean lines) */
.invoice-table-modern {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 3rem;
}

.invoice-table-modern th {
    text-align: left;
    padding: 1rem 0;
    border-bottom: 2px solid #111827;
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    color: #111827;
}

.invoice-table-modern td {
    padding: 1rem 0;
    border-bottom: 1px solid #E5E7EB;
    font-size: 0.95rem;
}

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

/* Summary (Right aligned, clean) */
.invoice-summary-section {
    display: flex;
    justify-content: flex-end;
}

.invoice-summary-box {
    width: 300px;
    background: transparent;
    /* No background */
    color: inherit;
    padding: 0;
}

.invoice-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    color: #4B5563;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px solid #111827;
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
}

/* Footer (Bank info) */
.invoice-footer-grid {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid #E5E7EB;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Responsive Mobile Menu */
.mobile-only {
    display: none;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    /* Sidebar Mobile Transition */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        width: 280px;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

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

    .top-bar {
        padding: 0 var(--spacing-md);
    }

    /* Adjust padding for mobile content */
    .content-view {
        padding: var(--spacing-md);
    }

    .invoice-header-content {
        flex-direction: column;
        gap: 2rem;
    }

    .invoice-brand-section,
    .invoice-meta-section {
        max-width: 100%;
        text-align: left;
    }

    .invoice-info-grid {
        flex-direction: column;
        gap: 2rem;
    }

    .invoice-info-col {
        width: 100%;
    }

    .invoice-footer-grid {
        grid-template-columns: 1fr;
    }

    /* Invoice Preview Mobile Adjustment */
    #preview-content {
        overflow-x: hidden;
        /* Prevent horizontal scroll on body */
        display: flex;
        justify-content: center;
        background: #525659;
    }

    #preview-content #invoice-content {
        transform: scale(0.55);
        /* Slightly smaller to ensure fit */
        transform-origin: top center;
        width: 180% !important;
        /* Compensate 100/0.55 approx */
        margin-bottom: -70%;
        /* Aggressive margin comp */
        margin-left: 0;
        box-shadow: none;
        /* Reduce visual noise */
    }

    /* Improve input visibility on mobile cards */
    #items-table input {
        width: 100%;
        min-height: 40px;
        /* Larger touch target */
        font-size: 16px;
        /* Prevent IOS zoom */
    }

    /* Mobile Table / List View - Card Style */
    .table thead {
        display: none;
    }

    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        background: #fff;
        margin-bottom: 1rem;
        border: 1px solid var(--border-light);
        border-radius: var(--radius-md);
        padding: 1rem;
        box-shadow: var(--shadow-sm);
    }

    .table td {
        padding: 0.5rem 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.85rem;
        color: var(--text-muted);
        text-align: left;
    }

    /* Specific tweaks for invoice items table in form */
    #items-table tr {
        position: relative;
        padding-bottom: 3rem;
        /* Space for delete button */
    }

    #items-table td {
        display: block;
        text-align: left;
        padding: 0.25rem 0;
    }

    #items-table td::before {
        display: block;
        margin-bottom: 0.25rem;
    }

    #items-table input {
        width: 100%;
    }

    /* Delete button positioning in items table */
    #items-table td:last-child {
        position: absolute;
        bottom: 1rem;
        right: 1rem;
        width: auto;
    }
}

/* Print Styles */
@media print {
    @page {
        margin: 0;
        size: auto;
    }

    body {
        background-color: white;
        color: black;
        margin: 0;
    }

    .sidebar,
    .top-bar,
    .no-print,
    .btn-icon,
    .sidebar-overlay {
        display: none !important;
    }

    .app-container {
        height: auto;
        display: block;
    }

    .main-content {
        margin: 0;
        padding: 0;
        overflow: visible;
    }

    .content-view {
        padding: 0;
        overflow: visible;
    }

    .card {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    /* Resume invoice styling for print */
    .invoice-paper {
        /* Ensure it takes full width on print but keep padding */
        width: 100% !important;
        max-width: none !important;
        padding: 20mm !important;
        /* Add padding since we removed page margin */
        margin: 0 !important;
    }
}

/* =========================================
   TOAST NOTIFICATIONS
   ========================================= */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 450px;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease forwards;
    border-left: 4px solid var(--primary);
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.success {
    border-left-color: var(--accent);
}

.toast.info {
    border-left-color: var(--primary);
}

.toast-icon {
    font-size: 1.25rem;
}

.toast.error .toast-icon {
    color: #ef4444;
}

.toast.success .toast-icon {
    color: var(--accent);
}

.toast.info .toast-icon {
    color: var(--primary);
}

.toast-body {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
}

.toast.fadeOut {
    animation: toastSlideOut 0.3s ease forwards;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}