:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe3ef;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --soft: #eef4ff;
    --danger: #ef4444;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.06);
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden}
body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(180deg, #f8fafc 0%, #eef3f9 100%);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }

.app-shell {
    max-width: 1320px;
    margin: 0 auto;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.eyebrow {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 6px;
}

.topbar h1 { margin: 0; font-size: 30px; line-height: 1.1; }
.top-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.panel, .invoice-paper {
    background: var(--panel);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel { padding: 22px; margin-bottom: 20px; }
.panel-header { margin-bottom: 18px; }
.panel-header h2 { margin: 0 0 6px; font-size: 20px; }
.panel-header p { margin: 0; color: var(--muted); }
.inline-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.form-grid.two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-weight: 600; font-size: 14px; }
.field input,
.field select,
.field textarea,
.search-form input {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 14px 15px;
    outline: none;
    transition: .2s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-form input:focus {
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.logo-upload-wrap {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
}

.upload-box {
    flex: 1;
    border: 1.5px dashed #bfd3ff;
    border-radius: 12px;
    padding: 20px;
    background: var(--soft);
    cursor: pointer;
}
.upload-box input { display: none; }
.upload-content { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.upload-content strong { color: var(--text); }
.logo-preview-box {
    width: 120px; height: 120px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px;
    display: flex; align-items: center; justify-content: center;
}

.items-table-wrap { overflow-x: auto; }
.items-table, .invoice-table {
    width: 100%;
    border-collapse: collapse;
}
.items-table th,
.items-table td,
.invoice-table th,
.invoice-table td {
    padding: 14px 12px;
    border-bottom: 1px solid #eaf0f7;
    text-align: left;
    vertical-align: middle;
}

.items-table th, .invoice-table th {
    background: #f8fbff;
    color: #385073;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.items-table td input,
.items-table td select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 12px;
    font-size: 15px;
}
.btn-icon {
    width: 42px; height: 42px; border-radius: 10px; border: 1px solid #fecaca; background: #fff5f5; color: var(--danger); cursor: pointer;
}
.line-total { font-weight: 700; color: var(--primary); }

.split-grid {
    display: grid;
    grid-template-columns: 1.35fr .8fr;
    gap: 20px;
}
.sticky-summary { position: sticky; top: 24px; height: fit-content; }
.summary-card { background: #f8fbff; border: 1px solid #e2ebff; border-radius: 12px; padding: 18px; margin: 16px 0 20px; }
.summary-card > div { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.summary-card > div:not(:last-child) { border-bottom: 1px solid #e8eef8; }
.summary-total strong { color: var(--primary); font-size: 24px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 10px;
    padding: 13px 18px;
    border: 1px solid transparent;
    font-weight: 700;
    cursor: pointer;
    transition: .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: #fff; border-color: var(--line); }
.btn-outline { background: #eff6ff; color: var(--primary); border-color: #cfe0ff; }
.btn-block { width: 100%; }
.btn-xs { padding: 9px 12px; font-size: 13px; }

.invoice-page-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-bottom: 18px;
}

.invoice-paper {
    padding: 34px;
    max-width: 1000px;
    margin: 0 auto 30px;
}
.invoice-top {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    align-items: flex-start;
    padding-bottom: 26px;
    border-bottom: 1px solid #e8eef8;
}
.invoice-logo { max-width: 94px; max-height: 94px; margin-bottom: 14px; }
.brand-block h2 { margin: 0 0 10px; color: var(--primary); font-size: 30px; }
.brand-block p { margin: 6px 0; color: #475569; }
.invoice-heading { text-align: right; }
.status-badge {
    display: inline-block;
    padding: 8px 12px;
    background: #eef4ff;
    color: var(--primary);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
}
.invoice-heading h1 { margin: 0 0 18px; font-size: 30px; color: var(--primary); letter-spacing: .03em; }
.invoice-meta { display: grid; gap: 12px; }
.invoice-meta div,
.total-line {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}
.invoice-meta span,
.mini-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.invoice-meta strong { font-size: 16px; }

.invoice-info-grid {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 18px;
    margin: 26px 0;
}
.info-card {
    background: #fbfdff;
    border: 1px solid #e8eef8;
    border-radius: 12px;
    padding: 22px;
}
.accent-card { border-top: 3px solid var(--primary); }
.info-card h3 { margin: 10px 0 10px; font-size: 28px; }
.info-card p { margin: 7px 0; color: #475569; }

.table-card { border: 1px solid #e8eef8; border-radius: 12px; overflow: hidden; }
.invoice-table tbody tr:nth-child(even) { background: #fcfdff; }
.invoice-table.compact td, .invoice-table.compact th { padding: 12px; }
.action-cell { display: flex; gap: 8px; flex-wrap: wrap; }

.totals-box {
    width: min(100%, 360px);
    margin-left: auto;
    margin-top: 22px;
    background: #fbfdff;
    border: 1px solid #e8eef8;
    border-radius: 12px;
    padding: 18px;
}
.total-line { padding: 10px 0; }
.total-line:not(:last-child) { border-bottom: 1px solid #edf2f8; }
.total-line.grand strong,
.total-line.grand span { color: var(--primary); font-size: 22px; font-weight: 800; }

.note-box {
    margin-top: 26px;
    border: 1px solid #f4d58d;
    background: #fff9e9;
    border-radius: 12px;
    padding: 18px 20px;
}
.note-box h4 { margin: 0 0 8px; color: #9a5b00; }
.note-box p { margin: 0; color: #7c4a03; line-height: 1.65; }

.search-form { display: flex; gap: 10px; align-items: center; }
.footer-note { text-align: center; padding: 10px 0 26px; color: var(--muted); }
.grid-form form { display: block; }

@media (max-width: 980px) {
    .form-grid.two,
    .split-grid,
    .invoice-info-grid,
    .invoice-top,
    .topbar,
    .inline-between { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; }
    .invoice-heading { text-align: left; }
    .sticky-summary { position: static; }
    .invoice-paper { padding: 20px; }
    
    .custom-split-grid {
        gap: 0;
    }
}

@media print {
    body { background: #fff; }
    .no-print, .topbar, .footer-note { display: none !important; }
    .app-shell { max-width: 100%; padding: 0; }
    .invoice-paper { box-shadow: none; border: 0; margin: 0; max-width: 100%; }
}

.login-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 180px);
}

.login-card {
    width: 100%;
    max-width: 460px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.alert-box {
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid rgba(49, 107, 255, 0.18);
    background: rgba(49, 107, 255, 0.06);
    color: #16336f;
    border-radius: 10px;
    font-size: 14px;
}

.alert-box.error {
    border-color: rgba(225, 29, 72, 0.18);
    background: rgba(225, 29, 72, 0.06);
    color: #881337;
}

/* === 2026 refinements for NISI Developer === */
body {
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    margin-bottom: 18px;
}

.topbar h1 {
    font-size: 30px;
    line-height: 1.15;
    margin: 8px 0 0;
}

.panel-header h2,
.invoice-paper h2,
.invoice-paper h3,
.note-box h4 {
    line-height: 1.2;
}

.panel-header h2 {
    font-size: 20px;
}

.invoice-heading h1 {
    font-size: 30px;
}

.invoice-paper h2 {
    font-size: 17px;
}

.invoice-paper h3 {
    font-size: 15px;
}

.footer-note {
    margin-top: auto;
    text-align: center;
    padding: 18px 0 26px;
    color: var(--muted);
}

.footer-note p {
    margin: 0;
}

.logo-upload-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    gap: 14px;
    align-items: stretch;
}

.logo-preview-dynamic {
    min-height: 86px;
    border: 1px dashed #cddaf1;
    border-radius: 12px;
    background: #f8fbff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--muted);
    text-align: center;
    padding: 12px;
}

.logo-preview-dynamic img {
    max-width: 100%;
    max-height: 82px;
    object-fit: contain;
}

.logo-preview-dynamic.has-image {
    border-style: solid;
    background: #fff;
}

.slim-items-table th:nth-child(2),
.slim-items-table td:nth-child(2),
.slim-items-table th:nth-child(3),
.slim-items-table td:nth-child(3) {
    width: 160px;
}

.single-card-grid {
    grid-template-columns: 1fr;
}

.rounded-logo {
    width: 84px;
    height: 84px;
    object-fit: cover;
    border-radius: 999px;
}

.invoice-info-text {
    margin-top: 22px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.75;
    border-top: 1px solid #e8eef8;
    padding-top: 18px;
}

@media (max-width: 900px) {
    .logo-upload-wrap {
        grid-template-columns: 1fr;
    }
}

@page {
    size: A4;
    margin: 8mm;
}

@media print {
    html,
    body {
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        font-size: 13px !important;
        line-height: 1.35 !important;
    }

    body {
        min-height: auto !important;
    }

    .topbar,
    .page-actions,
    .site-header,
    .site-footer,
    .no-print,
    .invoice-page-actions,
    .btn,
    button {
        display: none !important;
    }

    .app-shell,
    .invoice-page,
    .invoice-wrap,
    .invoice-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        min-height: auto !important;
    }

    .invoice-paper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 16px !important;
        box-sizing: border-box !important;
        background: #ffffff !important;
        box-shadow: none !important;
        overflow: hidden !important;
        border-radius: 12px !important;
    }

    /* HEADER: 2 KOLONA */
    .invoice-top {
        display: grid !important;
        grid-template-columns: 48% 48% !important;
        justify-content: space-between !important;
        align-items: start !important;
        gap: 4% !important;
        margin-bottom: 16px !important;
        padding-bottom: 0 !important;
        border-bottom: none !important;
        clear: both !important;
    }

    .invoice-top .brand-block {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        text-align: left !important;
        float: none !important;
    }

    .invoice-top .invoice-heading {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        text-align: right !important;
        float: none !important;
        justify-self: end !important;
    }

    .invoice-top .brand-block * {
        text-align: left !important;
    }

    .invoice-top .invoice-heading * {
        text-align: right !important;
    }

    .invoice-logo,
    .brand-block img {
        width: 78px !important;
        height: 78px !important;
        min-width: 78px !important;
        min-height: 78px !important;
        object-fit: cover !important;
        border-radius: 50% !important;
        display: block !important;
        margin-bottom: 10px !important;
    }

    .invoice-client-box {
        margin: 14px 0 !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* TABELA MAJTAS */
    .table-card {
        width: 63% !important;
        max-width: 63% !important;
        float: left !important;
        margin: 0 !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* QMIMORJA DJATHTAS - PAK ME E MADHE */
    .totals-box {
        width: 35% !important;
        max-width: 35% !important;
        float: right !important;
        margin: 0 !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
        table-layout: fixed !important;
    }

    th,
    td {
        padding: 8px 10px !important;
        vertical-align: middle !important;
    }

    tr,
    td,
    th {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* TOTALI PËR PAGESË MË I VOGËL */
    .totals-box .total-row,
    .totals-box .grand-total,
    .totals-box .pay-total,
    .totals-box .amount-total {
        font-size: 15px !important;
        line-height: 1.2 !important;
    }

    .totals-box .total-row strong,
    .totals-box .grand-total strong,
    .totals-box .pay-total strong,
    .totals-box .amount-total strong {
        font-size: 15px !important;
    }

    /* SHËNIME POSHTË */
    .note-box {
        clear: both !important;
        margin-top: 20px !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* TEKSTI INFORMUES TË SHFAQET */
    .invoice-info-text {
        display: block !important;
        clear: both !important;
        text-align: center !important;
        margin-top: 12px !important;
        font-size: 13px !important;
        line-height: 1.4 !important;
        color: #5f6f8a !important;
    }

    * {
        box-shadow: none !important;
    }
    
    .totals-box .total-row:last-child,
        .totals-box .grand-total:last-child,
        .totals-box .pay-total:last-child {
            font-size: 14px !important;
    }
    
    .table-card .invoice-table {
        margin-bottom: 20px;
    }
    
    .table-card {
        border-bottom: 0;
    }
    
    .totals-box * {
        font-size: 18px !important;
        flex: 1 1 50% !important;
    }
    
    .total-line {
        display: flex !important;
    }
}