@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');

:root {
    --bg: #F6F9FF;
    --accent: #1E3A8A;
    /* deep indigo */
    --accent-2: #F97316;
    /* warm orange */
    --muted: #6B7280;
    --card-bg: #FFFFFF;
    --card-border: #E6EEFc;
    --accent-grad: linear-gradient(90deg, #4F46E5 0%, #06B6D4 100%);
}

body {
    font-family: 'Poppins', Inter, Arial, sans-serif;
    background: var(--bg);
    color: #0F172A;
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: #1E3A8A;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    box-shadow: 2px 0 8px rgba(30, 58, 138, 0.07);
    z-index: 100;
}

.sidebar .logo {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 2rem 1.5rem 1.5rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    border-bottom: 1px solid #233876;
}

.sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 1.5rem;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #fff;
    text-decoration: none;
    padding: 0.85rem 2rem;
    font-size: 1.08rem;
    border-radius: 8px 0 0 8px;
    margin-bottom: 0.3rem;
    transition: background 0.15s;
}

.sidebar nav a.active,
.sidebar nav a:hover {
    background: #233876;
    color: #F97316;
}

.sidebar .logout {
    margin: 1.5rem 2rem 2rem 2rem;
    padding: 0.7rem 0;
    border-top: 1px solid #233876;
}

.sidebar .logout a {
    color: #fff;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    font-size: 1.08rem;
    margin-top: 1rem;
    transition: color 0.15s;
}

.sidebar .logout a:hover {
    color: #F97316;
}

.main {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: #fff;
    padding: 1.2rem 2.5rem 1.2rem 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar .page-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #1E3A8A;
}

.topbar .topbar-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.topbar .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #F97316;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.08);
}

.dashboard-stats {
    display: flex;
    gap: 2rem;
    margin: 2.5rem 2.5rem 0 2.5rem;
    flex-wrap: wrap;
}

.stat-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.07);
    padding: 1.5rem 2rem;
    min-width: 220px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.stat-card .stat-label {
    color: #6b7280;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: #1E3A8A;
}

.stat-card .stat-icon {
    font-size: 2.2rem;
    margin-bottom: 0.7rem;
    color: #F97316;
}

@media (max-width: 900px) {
    .sidebar {
        width: 70px;
    }

    .sidebar .logo span {
        display: none;
    }

    .sidebar nav a span {
        display: none;
    }

    .main {
        margin-left: 70px;
    }

    .dashboard-stats {
        flex-direction: column;
        gap: 1rem;
    }
}

@media (max-width: 600px) {
    .main {
        margin-left: 0;
    }

    .sidebar {
        display: none;
    }

    .topbar {
        padding: 1rem;
    }

    .dashboard-stats {
        margin: 1rem;
    }
}

/* Modern invoice styles */
.invoice-box {
    padding: 2rem;
    max-width: 1120px;
    margin: 2rem auto;
    background: var(--card-bg);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 12px 35px rgba(18, 38, 80, 0.08);
}

.invoice-box::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: var(--accent-grad);
}

.invoice-inner {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
    z-index: 1
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 0;
    border-bottom: 1px solid rgba(14, 42, 128, 0.06);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.logo-icon {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    background: linear-gradient(180deg, #eef2ff, #ffffff);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 4px 20px rgba(16, 24, 64, 0.04);
}

.company h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #07123a;
}

.company .muted {
    font-size: 0.9rem;
    color: var(--muted);
    margin-top: 3px;
}

.invoice-meta {
    text-align: right;
}

.inv-label {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.95rem;
}

.inv-number {
    font-size: 1.05rem;
    color: #0f172a;
    font-weight: 800;
    margin-top: 0.2rem;
}

.inv-date {
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: 0.2rem;
}

.inv-status {
    display: inline-block;
    margin-top: 0.4rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.07);
}

.inv-status.paid {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.12), rgba(4, 120, 87, 0.04));
    color: #065f46;
    border: 1px solid rgba(6, 95, 70, 0.06);
}

.inv-status.due {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.08), rgba(249, 115, 22, 0.02));
    color: #92400e;
    border: 1px solid rgba(249, 115, 22, 0.06);
}

.barcode-wrap {
    display: flex;
    justify-content: center;
    margin: 0.7rem 0 0.3rem 0;
}

.barcode-canvas {
    width: 220px;
    height: 40px;
}

.invoice-parties {
    display: flex;
    gap: 2rem;
    margin-top: 0.8rem;
    flex-wrap: wrap;
}

.party {
    flex: 1;
    min-width: 220px;
    background: transparent;
    padding: 0.6rem 0;
}

.party-title {
    font-weight: 700;
    color: #1E3A8A;
    margin-bottom: 4px;
}

.party-name {
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 4px;
}

.party-address,
.party-location,
.party-contact {
    color: #475569;
    font-size: 0.95rem;
    margin-bottom: 3px;
}

.details-table,
.pricing-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.8rem;
    font-size: 0.95rem;
}

.details-table thead th,
.pricing-table thead th {
    text-align: left;
    padding: 0.9rem 0.85rem;
    background: #f8fafc;
    color: #1E3A8A;
    font-weight: 700;
    border-bottom: 1px solid #eef2ff;
    font-size: 0.98rem;
}

.details-table tbody td,
.pricing-table tbody td {
    padding: 0.9rem 0.85rem;
    border-bottom: 1px solid #f1f5f9;
    color: #0f172a;
}

.pricing-table .total {
    font-weight: 800;
    color: #0f172a;
}

.courier-description {
    margin-top: 0.8rem;
}

.desc-label {
    font-weight: 700;
    color: #1E3A8A;
    margin-bottom: 6px;
}

.desc-body {
    color: #374151;
}

.amount-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.in-words {
    color: #374151;
    font-weight: 600;
}

.actions {
    text-align: right;
}

.btn-primary {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    color: #fff;
    padding: 0.62rem 1.05rem;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    border: none;
    box-shadow: 0 8px 20px rgba(30, 58, 138, 0.12);
}

.download-btn {
    background: rgba(14, 42, 128, 0.06);
    color: var(--accent);
    padding: 0.5rem 0.95rem;
    border-radius: 8px;
    border: 1px solid rgba(14, 42, 128, 0.06);
    font-weight: 700;
    cursor: pointer;
}

.invoice-footer {
    text-align: right;
    color: var(--accent);
    font-weight: 700;
    padding-top: 0.8rem;
    border-top: 1px dashed rgba(14, 42, 128, 0.06);
    margin-top: 0.8rem;
}

/* Small footer lines for GST and staff */
.invoice-gst,
.invoice-staff {
    font-size: 0.95rem;
    color: #374151;
    font-weight: 600;
    margin-top: 6px;
}

.invoice-gst {
    color: #0f172a;
}

.invoice-staff {
    color: #6b7280;
    font-weight: 500;
}

@media (max-width: 900px) {
    .invoice-meta {
        text-align: left;
        margin-top: 0.6rem;
    }

    .invoice-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
    }

    .invoice-parties {
        flex-direction: column;
    }
}

/* Actions area for invoice (print / download) */
.invoice-actions {
    max-width: 1100px;
    margin: 0.6rem auto 1rem;
    text-align: right;
}

.invoice-actions .download-btn,
.invoice-actions .btn-primary {
    min-width: 120px;
}

@media (max-width: 700px) {
    .invoice-actions {
        text-align: center;
        padding: 0 1rem;
    }

    .invoice-actions .download-btn,
    .invoice-actions .btn-primary {
        width: 48%;
        min-width: 0;
        display: inline-block;
    }
}

/* Print tweaks */
@media print {
    body {
        background: #fff !important;
    }

    .sidebar,
    .topbar,
    .download-btn,
    .btn-primary {
        display: none !important;
    }

    .invoice-box {
        box-shadow: none;
        margin: 0;
        border-radius: 0;
    }

    .invoice-inner {
        gap: 0;
    }
}

/* Enhanced invoice visuals */
.company-address {
    color: #374151;
    font-size: 0.95rem;
    margin-top: 6px;
}

.invoice-layout {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
}

.invoice-main {
    flex: 1 1 60%;
}

.invoice-side {
    width: 320px;
    flex-shrink: 0;
}

.invoice-summary {
    background: linear-gradient(180deg, #ffffff 0%, rgba(239, 246, 255, 0.8) 100%);
    border: 1px solid var(--card-border);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(30, 58, 138, 0.04);
}

.summary-title {
    font-weight: 700;
    color: #1E3A8A;
    margin-bottom: 0.6rem;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    color: #374151;
}

.summary-row.total {
    font-size: 1.15rem;
    font-weight: 800;
    color: #0f172a;
    margin-top: 0.5rem;
    border-top: 1px dashed #e6eefc;
    padding-top: 0.6rem;
}

.status-pill {
    display: inline-block;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.84rem;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.status-pill.paid {
    background: linear-gradient(90deg, #ECFDF5, #DFF6EE);
    color: #065f46;
}

.status-pill.unpaid {
    background: linear-gradient(90deg, #FFF7ED, #FFF3E0);
    color: #92400e;
}

.totals-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.6rem;
}

.totals-table td {
    padding: 6px 0;
}

.signature {
    margin-top: 1.2rem;
    text-align: center;
    color: #6b7280;
}

.signature .line {
    width: 160px;
    border-top: 1px solid #e6eefc;
    margin: 0.8rem auto 0.3rem;
}

/* Print page size and margins for better PDF output */
@page {
    size: A4;
    margin: 18mm;
}

@media print {

    html,
    body {
        width: 210mm;
    }

    .invoice-box {
        max-width: 100%;
        margin: 0;
        padding: 10mm;
    }
}

/* Fit-to-page print rules: make the invoice compact so it fits on a single A4 page where possible */
@media print {
    @page {
        size: A4;
        margin: 10mm;
    }

    html,
    body {
        width: 210mm;
        height: 297mm;
        margin: 0;
    }

    /* Reduce base font-size for print to fit more content on one page */
    html,
    body {
        font-size: 11px;
    }

    .invoice-box {
        width: 190mm;
        max-width: 190mm;
        padding: 6mm;
        margin: 0 auto;
        box-shadow: none;
    }

    .invoice-inner {
        gap: 0;
    }

    .invoice-header {
        padding-bottom: 4px;
        border-bottom-width: 1px;
    }

    .brand .company h2 {
        font-size: 1rem;
    }

    .company-address,
    .party-address,
    .party-location,
    .party-contact,
    .desc-body,
    .details-table td,
    .pricing-table td {
        font-size: 0.82rem;
    }

    .details-table thead th,
    .pricing-table thead th {
        font-size: 0.85rem;
        padding: 0.2rem 0.3rem;
    }

    .details-table tbody td,
    .pricing-table tbody td {
        padding: 0.35rem 0.3rem;
    }

    .invoice-summary {
        padding: 0.6rem;
    }

    .summary-row,
    .totals-table td {
        font-size: 0.85rem;
    }

    .signature .line {
        width: 110px;
    }

    .barcode-canvas {
        width: 140px;
        height: 24px;
    }

    .invoice-actions {
        display: none !important;
    }

    /* Avoid page breaks inside the invoice box */
    .invoice-box,
    .invoice-inner,
    .invoice-layout {
        page-break-inside: avoid;
    }

    /* Make right column percentage-based on print so it fits A4 */
    .invoice-layout {
        display: flex;
        gap: 0.8rem;
    }

    .invoice-main {
        flex: 1 1 64%;
    }

    .invoice-side {
        flex: 0 0 34%;
        width: 34%;
        max-width: 34%;
    }
}

/* Settings / Edit Company styles */
.settings-card {
    max-width: 1100px;
    margin: 2.2rem auto;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(2, 6, 23, 0.06);
    padding: 1.25rem;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem
}

.settings-title {
    font-size: 1.25rem;
    color: #0f172a;
    font-weight: 700
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.25rem;
    align-items: start
}

.settings-panel {
    background: transparent;
    padding: 0
}

.field {
    margin-bottom: 0.8rem
}

.field label {
    display: block;
    font-weight: 700;
    color: #374151;
    margin-bottom: 0.4rem
}

.field input[type=text],
.field input[type=file],
.field textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 0.96rem
}

.logo-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    padding: 1rem;
    border: 1px dashed #e6eefc;
    border-radius: 8px;
    background: linear-gradient(180deg, #f8fafc, #ffffff);
}

.logo-preview img {
    max-height: 120px;
    max-width: 100%;
    object-fit: contain;
    background: #fff;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid #eef2ff
}

.settings-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    justify-content: flex-end;
    margin-top: 1rem
}

.btn-restore {
    background: #f97316;
    color: #fff;
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    border: none;
    font-weight: 700
}

.small-note {
    font-size: 0.9rem;
    color: #6b7280
}

@media (max-width: 880px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .logo-preview {
        order: -1;
    }
}

/* -- Extra polished visuals (overrides for a more attractive invoice) -- */
.invoice-header {
    padding: 1rem 0 1.1rem 0;
}

.company h2 {
    letter-spacing: -0.2px;
    font-weight: 700;
}

.company-address {
    opacity: 0.95;
}

/* Decorative banner behind the header */
.invoice-header .brand {
    padding-right: 0.6rem;
}

.invoice-meta {
    background: linear-gradient(180deg, rgba(79, 70, 229, 0.06), rgba(6, 182, 212, 0.02));
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    display: inline-block;
    min-width: 160px;
    text-align: right;
}

/* Subtle watermark (company logo) on the invoice */
.invoice-box::after {
    content: '';
    position: absolute;
    right: 28px;
    bottom: 18px;
    width: 220px;
    height: 220px;
    background-image: url('logo.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.06;
    transform: rotate(-12deg);
    pointer-events: none;
}

/* Table header as pill-style labels */
.details-table thead th,
.pricing-table thead th {
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.06), rgba(6, 182, 212, 0.02));
    border-radius: 8px;
    padding: 0.9rem 0.85rem;
}

.details-table tbody tr:nth-child(odd) {
    background: rgba(14, 42, 128, 0.01);
}

/* Emphasize the total in the summary panel */
.invoice-summary .summary-row.total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.invoice-summary .summary-row.total div:last-child {
    font-size: 1.6rem;
    font-weight: 900;
    color: #07123a;
}

.invoice-summary .summary-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Highlight total box with subtle gradient */
.invoice-summary .total-badge {
    margin-top: 0.6rem;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.08), rgba(6, 182, 212, 0.04));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.invoice-summary .total-badge .label {
    color: var(--muted);
    font-weight: 700;
}

.invoice-summary .total-badge .value {
    font-size: 1.25rem;
    font-weight: 900;
    color: #07123a;
}

/* Buttons: stronger hover & micro-interaction */
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 30px rgba(16, 24, 64, 0.12);
}

.download-btn:hover {
    transform: translateY(-1px);
}

/* Slightly larger barcode for better scanning */
.barcode-canvas {
    width: 260px;
    height: 44px;
}

/* Mobile compact adjustments for the new visuals */
@media (max-width:700px) {
    .invoice-summary {
        margin-top: 0.8rem;
    }

    .invoice-box::after {
        display: none;
    }

    .invoice-meta {
        min-width: 120px;
    }
}