/* ====== DESIGN TOKENS ====== */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #f7f9fc;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --sidebar-bg: #0f172a;
    --sidebar-text: #e2e8f0;
    --sidebar-hover: #1e293b;
    --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);
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --font-sans: 'Inter', sans-serif;
    --transition: all 0.2s ease-in-out;
}

/* Dark Mode Tokens */
body.dark-mode {
    --primary-color: #3b82f6;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --border-color: #334155;
    --sidebar-bg: #0b1120;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

/* ====== RESET & BASE ====== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    font-size: 0.95rem;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: var(--primary-color);
}

input,
select,
textarea,
button {
    font-family: inherit;
    font-size: inherit;
}

.hidden {
    display: none !important;
}

/* ====== UTILITIES ====== */
.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.pb-0 {
    padding-bottom: 0 !important;
}

.w-100 {
    width: 100%;
}

.w-50 {
    width: 50%;
}

.w-60 {
    width: 60%;
}

.w-40 {
    width: 40%;
}

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

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

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-end {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
}

.row-align {
    display: flex;
    align-items: center;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.gap-sm {
    gap: 0.5rem;
}

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

.text-primary {
    color: var(--primary-color);
}

.bold {
    font-weight: 700;
}

.bg-light {
    background-color: var(--secondary-color);
}

.bg-dark {
    background-color: #e2e8f0;
    color: #0f172a;
}

body.dark-mode .bg-light,
body.dark-mode .bg-dark {
    background-color: var(--border-color);
    color: var(--text-color);
}

.custom-brand-text {
    color: #243589 !important;
}

.gstin-text {
    color: #fa9e33 !important;
}

@media print {
    .custom-brand-text {
        color: #243589 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .gstin-text {
        color: #fa9e33 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ====== BADGES ====== */
.badge {
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: var(--success-color);
    color: white;
}

.badge-danger {
    background: var(--danger-color);
    color: white;
}

body.dark-mode .badge-success {
    background: var(--success-color);
    color: white;
}

body.dark-mode .badge-danger {
    background: var(--danger-color);
    color: white;
}

/* ====== BUTTONS ====== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

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

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

.btn-outline:hover {
    background-color: var(--secondary-color);
    border-color: var(--text-muted);
}

body.dark-mode .btn-outline:hover {
    background-color: var(--border-color);
}

.btn-transparent {
    background: none;
    color: inherit;
    border: none;
}

.btn-icon-danger {
    color: var(--danger-color);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

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

body.dark-mode .btn-icon-danger:hover {
    background-color: rgba(239, 68, 68, 0.2);
}

.btn-block {
    width: 100%;
    padding: 0.75rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

/* ====== LOGIN PAGE ====== */
#login-view {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    background: var(--card-bg);
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    padding: 3rem 2.5rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.login-header h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.input-with-icon i {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    pointer-events: none;
}

.input-with-icon i:first-child {
    left: 0.75rem;
}

.input-with-icon #toggle-password {
    right: 0.75rem;
    left: auto;
    cursor: pointer;
    pointer-events: auto;
    transition: var(--transition);
}

.input-with-icon #toggle-password:hover {
    color: var(--primary-color);
}

.input-with-icon input {
    padding-left: 2.75rem;
    padding-right: 2.75rem;
    width: 100%;
}

.input-with-icon.no-left-icon input {
    padding-left: 0.75rem;
}

.error-msg {
    color: var(--danger-color);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
    background: #fee2e2;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

/* ====== APP LAYOUT ====== */
#app-layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.sidebar-brand {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: var(--transition);
    width: 100%;
}

.nav-item:hover {
    background-color: var(--sidebar-hover);
    color: white;
}

.nav-item.active {
    background-color: var(--primary-color);
    color: white;
    border-left: 4px solid white;
}

.sidebar-bottom {
    padding: 1rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: 60px;
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 10;
}

.topbar h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* ====== CARDS ====== */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 1.1rem;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.02);
}

body.dark-mode .card-footer {
    background-color: rgba(255, 255, 255, 0.02);
}

/* ====== DASHBOARD CARDS ====== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.summary-card {
    display: flex;
    align-items: center;
    padding: 1.5rem;
    gap: 1rem;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.card-icon.blue {
    background: #dbeafe;
    color: #2563eb;
}

.card-icon.green {
    background: #d1fae5;
    color: #10b981;
}

.card-icon.orange {
    background: #fef3c7;
    color: #f59e0b;
}

.card-icon.purple {
    background: #f3e8ff;
    color: #9333ea;
}

body.dark-mode .card-icon {
    background: var(--border-color);
}

.card-info h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.card-info p {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

/* ====== FORMS ====== */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-color);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--card-bg);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input.small-input {
    width: 60px;
    padding: 0.25rem;
    text-align: center;
    display: inline-block;
}

/* Checkboxes */
.checkbox-container {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
    margin-bottom: 0;
}

.checkbox-container input {
    margin-right: 0.5rem;
    width: auto;
}

/* Form Sections */
.box-section {
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    background-color: var(--secondary-color);
}

body.dark-mode .box-section {
    background-color: var(--card-bg);
}

.box-section h3 {
    font-size: 0.95rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-color);
}

.box-section h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

/* Totals Box */
.totals-box {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.totals-box .form-group {
    margin-bottom: 0.5rem;
}

.grand-total-row {
    border-top: 2px solid var(--border-color);
    padding-top: 1rem;
}

/* ====== TABLES ====== */
.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--secondary-color);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
}

body.dark-mode .data-table th {
    background-color: rgba(255, 255, 255, 0.05);
}

.data-table tbody tr:hover {
    background-color: var(--bg-color);
}

.search-box {
    position: relative;
    width: 250px;
}

.search-box i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    padding-left: 2rem;
    border-radius: 999px;
}

/* Products Table specific */
.products-table input {
    padding: 0.4rem;
    border: 1px solid transparent;
}

.products-table input:hover,
.products-table input:focus {
    border-color: var(--border-color);
}

/* ====== TOAST ====== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--text-color);
    color: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

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

/* ====== PRINT / INVOICE PREVIEW ====== */
.invoice-print-container {
    position: relative;
    background: #fff;
    color: #000;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 20px auto;
    padding: 10mm;
    /* Consistent margins */
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    box-sizing: border-box;
}

.copy-label-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #f7f9fc;
    border: 1px solid #e2e8f0;
    padding: 5px 12px;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #1e293b;
    border-radius: 4px;
}

/* These styles mostly map to your original invoice format but cleaned up */
.print-header {
    border-bottom: 3px solid var(--primary-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    text-align: center;
}

.company-info-area {
    display: flex;
    align-items: center;
    justify-content: center;
}

.company-details {
    text-align: left;
}

.company-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.print-title {
    background: var(--secondary-color);
    text-align: center;
    font-weight: 700;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

.print-two-col {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.print-box {
    border: 1px solid var(--border-color);
}

.print-box-title {
    background: var(--secondary-color);
    padding: 0.4rem 0.5rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.print-block {
    padding: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.6;
}

.print-grid-2-rows {
    padding: 0.5rem;
}

.print-table-wrap {
    min-height: 200px;
    margin-bottom: 0.5rem;
}

.print-items {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border-color);
}

.print-items th,
.print-items td {
    border: 1px solid var(--border-color);
    padding: 0.4rem;
    font-size: 0.85rem;
}

.print-items th {
    background: var(--secondary-color);
    font-weight: 600;
    text-align: left;
}

.print-bottom {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.print-totals {
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.print-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.print-totals-row:last-child {
    border-bottom: none;
}

.print-totals-row.grand {
    font-weight: 700;
    background: var(--secondary-color);
    font-size: 1rem;
}

.print-signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.sig-box {
    text-align: center;
    font-size: 0.85rem;
    border-top: 1px solid #000;
    padding-top: 0.5rem;
    width: 200px;
}

.sig-box.right {
    text-align: right;
    border-top: none;
}

/* Print Media Query */
@media print {
    @page {
        margin: 0;
        size: A4 portrait;
    }

    body {
        background-color: #fff !important;
        margin: 0;
        padding: 0;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide all non-printable application frames */
    .sidebar,
    .topbar,
    .toast,
    .view:not(#app-layout),
    .sub-view:not(#invoice-preview-view),
    .no-print {
        display: none !important;
    }

    /* Ensure flex wrappers don't crush the height or width */
    #app-layout,
    .main-content,
    .content-area,
    #invoice-preview-view {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        position: static !important;
    }

    #print-area {
        display: block !important;
        width: 210mm !important;
        margin: 0 auto !important;
        padding: 0 !important;
        position: static !important;
    }

    .invoice-print-container {
        width: 210mm !important;
        height: auto !important;
        min-height: auto !important;
        padding: 10mm !important;
        /* Match preview padding exactly */
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        page-break-after: always;
        page-break-inside: avoid;
        box-sizing: border-box !important;
        position: relative !important;
    }

    .invoice-print-container:last-child {
        page-break-after: auto;
    }

    .copy-label-badge {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Ensure colors print */
    .print-title,
    .print-box-title,
    .print-items th,
    .print-totals-row.grand {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        background: #f7f9fc !important;
        background-color: #f7f9fc !important;
    }
}

/* Responsive */
@media screen and (max-width: 768px) {
    #app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 0.5rem;
    }

    .sidebar-brand {
        border: none;
        padding: 0.5rem;
    }

    .sidebar-nav {
        display: flex;
        overflow-x: auto;
        padding: 0;
        flex: none;
        width: 100%;
    }

    .nav-item {
        width: auto;
        padding: 0.5rem;
        font-size: 0.8rem;
        flex-direction: column;
        gap: 0.25rem;
    }

    .sidebar-bottom {
        display: none;
    }

    .topbar {
        padding: 0 1rem;
    }

    .content-area {
        padding: 1rem;
    }

    .grid-2,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .print-two-col,
    .print-bottom {
        flex-direction: column;
    }

    .w-50,
    .w-60,
    .w-40 {
        width: 100%;
    }
}