﻿* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: #f8f7f5;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
}

/* =============================================
   NAV
   ============================================= */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background: black;
    padding: 0 38px;
    height: 63px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.navbar h1 {
    font-size: 30px;
    font-family: 'Times New Roman', Times, serif;
    font-weight: 600;
    color: white;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.nav-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    font-size: medium;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.8s ease;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-print {
    background: transparent;
    border: 1.5px solid white;
    color: white;
}

.btn-save {
    background: #27ae60;
    color: white;
}

.btn-save:hover { background: #219a52; }

.btn-print:hover {
    background: white;
    color: black;
}

.btn-download {
    background: white;
    color: black;
}

.btn-download:hover {
    background: rgb(205, 201, 201);
    transform: translateY(-1px);
}

.btn-download:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* =============================================
   LAYOUT
   ============================================= */
.layout {
    max-width: 1280px;
    margin: 0 auto;
    padding: 30px 24px 60px;
    margin-left: 320px;
    margin-top: 63px;
}

@media (min-width: 1440px) {
    .layout { max-width: 1400px; margin-left: 360px; padding: 40px 32px 80px; }
    .sidebar { left: 32px; }
    .invoice-paper { padding: 56px 64px; }
    .invoice-word { font-size: 3rem; }
    .logo-upload { width: 200px; height: 120px;  }
}

@media (min-width: 1920px) {
    .layout { max-width: 1600px; margin-left: 400px; padding: 50px 40px 100px; }
    .sidebar { width: 320px; left: 40px; }
    .invoice-paper { padding: 64px 80px; }
    .invoice-word { font-size: 3.3rem; }
    .logo-upload { width: 220px; height: 140px; }
    .top-grid { gap: 48px; }
    .footer-grid { gap: 60px; }
    textarea { height: 100px; }
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: 280px;
    position: fixed;
    top: 82px;
    left: 24px;
    background-color: white;
    border: 1px solid rgb(224, 206, 206);
    border-radius: 9px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.settings-body {
    padding: 6px 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar h2 {
    font-size: 20px;
    font-weight: 800;
    color: #333;
    padding: 18px;
}

.setting-items {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.setting-label {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.container select {
    width: 100%;
    background: transparent;
    border: 1.5px solid #6f6f6f;
    border-radius: 6px;
    padding: 10px 36px 10px 13px;
    font-size: 12px;
    color: #333;
    cursor: pointer;
    transition: all 0.5s ease;
    outline: none;
}

.container select:focus { border: 2px solid #333; }

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.btn-sidebar-clear {
    width: 100%;
    padding: 8px;
    border: 1.5px solid #e74c3c;
    border-radius: 6px;
    background: transparent;
    color: #e74c3c;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.5s ease;
}

.btn-sidebar-clear:hover {
    background: #e74c3c;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.btn-saveDefault {
    border: none;
    background: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    padding: 4px 0;
    text-align: center;
    transition: color 0.2s ease;
    color: #333;
}

.btn-saveDefault:hover {
    color: black;
    text-decoration: underline;
}

/* =============================================
   INVOICE PAPER
   ============================================= */
.invoice-paper {
    background: white;
    padding: 44px 48px;
    border: 1px solid rgb(224, 206, 206);
    border-radius: 9px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 36px;
}

.logo-upload {
    width: 250px;
    height: 150px;
    border-radius: 20px;
    overflow: hidden;   /* clips image corners */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

#logoPreview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit; /* take parent radius */
    display: block;
}

#logoPreview:not([src]) { display: none !important; }

.logo-upload #logoText {
    font-size: 0.8rem;
    color: #333;
    font-weight: 500;
    text-align: center;
}

.invoice-title-block { text-align: right; }

.invoice-word {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: #111;
    line-height: 1;
    margin-bottom: 10px;
}

.invoice-number {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.invoice-number label {
    font-size: 1rem;
    font-weight: 600;
    color: #555;
}

.invoice-number input {
    width: 100px;
    text-align: right;
    font-size: 1rem;
    border: none;
    border-bottom: 1.5px solid #333;
    color: #333;
    padding: 4px 6px;
    font-family: sans-serif;
    outline: none;
    background: transparent;
}

/* =============================================
   TOP GRID
   ============================================= */
.top-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 36px;
}

.left-fields {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.address {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

textarea {
    font-size: 15px;
    color: black;
    background: transparent;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 10px 12px;
    height: 80px;
    line-height: 1.4;
    outline: none;
    width: 100%;
    resize: vertical;
    font-family: 'DM Sans', sans-serif;
}

textarea:focus { border: 2px solid #333; }

.right-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Regular Date row ── */
.field-row {
    display: grid;
    grid-template-columns: minmax(100px, 140px) 1fr;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.field-row label {
    font-size: 15px;
    color: black;
}

.field-row input {
    border-radius: 6px;
    font-size: 15px;
    color: black;
    background: transparent;
    border: 1px solid #333;
    outline: none;
    padding: 8px 18px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.field-row input:focus { border: 2px solid #333; }

input[type="date"] {
    width: 100%;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

/* ── Optional field rows ── */
.optional-field-row {
    display: grid;
    grid-template-columns: minmax(100px, 140px) 1fr;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.opt-label-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: #333;
    font-weight: 450;
    white-space: nowrap;
}

.opt-label-group span {
    font-size: 15px;
    color: #333;
}

.opt-label-group .remove-btn {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.opt-label-group .remove-btn:hover {
    color: #e74c3c;
    background: #fdecea;
}

.opt-input-box {
    display: flex;
    width: 100%;
    min-width: 0;
}

.opt-input-box input {
    width: 100%;
    min-width: 0;
    flex: 1;
    box-sizing: border-box;
    padding: 8px 18px;
    border: 1px solid #333;
    border-radius: 6px;
    background: transparent;
    font-size: 15px;
    text-align: left;
    outline: none;
    color: #333;
    font-weight: 400;
}

.opt-input-box input:focus { border: 2px solid black; }

.add-links {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}
.add-link {
    color: #2ecc71;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.add-link:hover {
    color: #27ae60;
    text-decoration: underline;
}

/* =============================================
   ITEMS TABLE
   ============================================= */
.items-table-wrapper {
    margin-top: 10px;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

.items-table thead tr {
    background: #111;
    color: #fff;
}

.items-table thead th {
    padding: 12px 10px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
}

.items-table tbody tr { border-bottom: 1px solid #ddd; }
.items-table tbody tr:hover { background: #f9f9f9; }

.items-table tbody td {
    padding: 10px;
    font-size: 14px;
    text-align: left;
    vertical-align: middle;
}

.items-table input {
    width: 100%;
    padding: 6px;
    border: none;
    outline: none;
    text-align: left;
    background: transparent;
    font-size: 14px;
    color: #333;
}
.amount-cell {
    font-weight: 600;
    text-align: center;
}

.del-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    color: #aaa;
    font-size: 18px;
    transition: 0.2s ease;
}

.del-btn:hover {
    color: #e74c3c;
    transform: scale(1.2);
}

.add-btn {
    margin: 25px 0;
    width: 100%;
    padding: 10px;
    background: none;
    border: 1.5px dashed #ccc;
    border-radius: 6px;
    font-size: 14px;
    color: #888;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
}

.add-btn:hover {
    border: 1.5px dashed #27ae60;
    color: #27ae60;
    transition: all 0.5s ease;
    font-weight: 600;
    font-size: 15px;
}

/* =============================================
   FOOTER
   ============================================= */
.footer-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 40px;
    align-items: start;
}

.field-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.remove-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.remove-btn:hover {
    color: #e74c3c;
    background: #fdecea;
}

.left-notes {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ── Totals ── */
.right-total {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.total-row {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.total-label-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.total-label-group span { color: #555; font-weight: 500; }

.percent-box {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 6px;
    overflow: hidden;
}

.percent-box input {
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: #222;
    border: none;
    outline: none;
    background: transparent;
    width: 70px;
    text-align: right;
    padding: 5px 8px;
}

.percent-box span {
    padding: 5px 8px;
    font-size: 13px;
    color: #888;
    background: #f5f5f5;
    border-left: 1px solid #ccc;
}

.total-row span { color: #555; font-weight: 500; }
.total-row strong { color: #222; font-weight: 600; }

.total-big span { font-size: 15px; font-weight: 600; color: #222; }
.total-big strong { font-size: 16px; font-weight: 700; color: #222; }

.balance-row span { font-size: 15px; font-weight: 600; color: #222; }
.balance-row strong { font-size: 16px; font-weight: 700; color: #2ecc71; }

.total-divider {
    border: none;
    border-top: 1px solid #ddd;
    margin: 2px 0;
}

.paid-box {
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.paid-box span {
    padding: 5px 8px;
    font-size: 13px;
    color: #252121;
    font-weight: 600;
    border-right: 1px solid #ccc;
}

.paid-box input {
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: #222;
    border: none;
    outline: none;
    background: transparent;
    width: 100px;
    text-align: right;
    padding: 5px 8px;
}

/* =============================================
   MODAL
   ============================================= */
.hidden { display: none !important; }

.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.confirm-dialog {
    position: relative;
    width: min(92vw, 420px);
    background: white;
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

.confirm-dialog h3 { font-size: 22px; color: #111; margin-bottom: 8px; }
.confirm-dialog p  { font-size: 14px; color: #444; margin-bottom: 18px; }

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.confirm-btn {
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}

.confirm-btn-secondary { background: white; color: #333; border-color: #d0d0d0; }
.confirm-btn-secondary:hover { background: #f5f5f5; }
.confirm-btn-primary { background: #111; color: white; }
.confirm-btn-primary:hover { background: #000; }

/* =============================================
   PRINT
   ============================================= */
@media print {
    @page { margin: 15mm; size: A4; }

    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    html, body { width: 100%; height: auto; overflow: visible !important; background: #fff !important; }

    .navbar, .sidebar, .add-btn, .del-btn, .btn, .remove-btn,
    .add-links, .add-note-links, .col-del, .optional-field-links {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    .layout { padding: 0 !important; max-width: 100% !important; margin: 0 !important; }

    .invoice-paper {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        border-radius: 0 !important;
    }

    header {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-start !important;
        justify-content: space-between !important;
        gap: 0 !important;
        margin-bottom: 28px !important;
        padding-bottom: 20px !important;
        border-bottom: 2px solid #111 !important;
    }

    .logo-upload { width: 140px !important; height: 80px !important; border: none !important; }
    .invoice-word { font-size: 2.2rem !important; letter-spacing: 6px !important; color: #111 !important; }
    .invoice-title-block { text-align: right !important; }
    .invoice-number input { border: none !important; border-bottom: 1.5px solid #333 !important; }

    .top-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 20px !important;
        align-items: start !important;
        margin-bottom: 28px !important;
    }

    .left-fields { display: flex !important; flex-direction: column !important; gap: 14px !important; }
    .address { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 14px !important; }

    .field-label {
        font-size: 11px !important;
        font-weight: 700 !important;
        color: black !important;
        text-transform: uppercase !important;
        letter-spacing: 0.8px !important;
        margin-bottom: 3px !important;
        display: block !important;
    }

    textarea {
        border: none !important;
        padding: 0 !important;
        height: auto !important;
        font-size: 13px !important;
        line-height: 1.2 !important;
        resize: none !important;
        background: transparent !important;
        color: #111 !important;
    }

    .right-fields { display: flex !important; flex-direction: column !important; gap: 6px !important; }

    .field-row {
        display: grid !important;
        grid-template-columns: 110px 1fr !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 3px 0 !important;
        border-bottom: 1px solid #f0f0f0 !important;
    }

    .field-row label { font-size: 14px !important; color: black !important; font-weight: 500 !important; }
    .field-row input { border: none !important; font-size: 13px !important; font-weight: 600 !important; color: #111 !important; text-align: right !important; padding: 0 !important; background: transparent !important; }

    .optional-field-row {
        display: grid !important;
        grid-template-columns: 110px 1fr !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 3px 0 !important;
        border-bottom: 1px solid #f0f0f0 !important;
    }

    .opt-label-group { display: flex !important; align-items: center !important; gap: 4px !important; }
    .opt-label-group span { font-size: 14px !important; color: black !important; font-weight: 500 !important; }

    .opt-input-box input {
        border: none !important;
        font-size: 13px !important;
        font-weight: 600 !important;
        color: #111 !important;
        text-align: right !important;
        padding: 0 !important;
        background: transparent !important;
        width: 100% !important;
    }

    input[type="date"]::-webkit-calendar-picker-indicator { display: none !important; opacity: 0 !important; }
    input[type="date"] { appearance: none !important; -webkit-appearance: none !important; }

    .field-row:has(input:placeholder-shown):not(:has(input[type="date"])) { display: none !important; }
    .field-row:has(input[type="date"][value=""]) { display: none !important; }
    .optional-field-row:has(input:placeholder-shown):not(:has(input[type="date"])) { display: none !important; }
    .optional-field-row:has(input[type="date"][value=""]) { display: none !important; }

    .items-table-wrapper { overflow: visible !important; margin-bottom: 0 !important; }

    .items-table {
        min-width: unset !important;
        width: 100% !important;
        border-collapse: collapse !important;
        margin-bottom: 0 !important;
        page-break-inside: avoid;
    }

    .items-table thead tr { background: #111 !important; color: #fff !important; }
    .items-table thead th { padding: 10px 12px !important; font-size: 11px !important; font-weight: 700 !important; text-transform: uppercase !important; }
    .items-table tbody tr { border-bottom: 1px solid #eee !important; }
    .items-table tbody td { padding: 10px 12px !important; font-size: 13px !important; color: #111 !important; }
    .items-table input { border: none !important; background: transparent !important; font-size: 13px !important; color: #111 !important; padding: 0 !important; }

    .footer-grid { display: grid !important; width: 100% !important; margin-top: 24px !important; gap: 32px !important; align-items: start !important; }
    .left-notes { order: 1 !important; }
    .right-total { order: 2 !important; min-width: 240px !important; }

    .total-row { display: flex !important; justify-content: space-between !important; padding: 5px 0 !important; font-size: 13px !important; border-bottom: 1px solid #f5f5f5 !important; }
    .total-big { border-bottom: 2px solid #111 !important; padding: 8px 0 !important; }
    .total-big span { font-size: 14px !important; font-weight: 700 !important; }
    .total-big strong { font-size: 15px !important; font-weight: 700 !important; }
    .balance-row { padding: 8px 0 !important; border-bottom: none !important; }
    .balance-row span { font-size: 14px !important; font-weight: 700 !important; color: #111 !important; }
    .balance-row strong { font-size: 15px !important; font-weight: 700 !important; color: #111 !important; }
    .total-divider { display: none !important; }

    .percent-box, .paid-box { border: none !important; background: transparent !important; }
    .percent-box span, .paid-box span { border: none !important; background: transparent !important; color: #111 !important; font-weight: 600 !important; }
    .percent-box input, .paid-box input { border: none !important; font-size: 13px !important; font-weight: 600 !important; color: #111 !important; }

    #notesGroup, #termsGroup { margin-top: 4px !important; }
    #notesGroup:not(:has(textarea:not(:placeholder-shown))),
    #termsGroup:not(:has(textarea:not(:placeholder-shown))) { display: none !important; }
    .field-items:has(textarea:placeholder-shown) { display: none !important; }

    #discountRow[style*="display: none"],
    #taxRow[style*="display: none"],
    #shippingRow[style*="display: none"] { display: none !important; }
}

/* =============================================
   RESPONSIVE — TABLET LARGE (≤1200px)
   ============================================= */
@media (max-width: 1200px) {
    .layout {
        margin-left: 300px;
        padding: 24px 20px 60px;
    }
    .sidebar {
        width: 260px;
        left: 16px;
    }
}

/* =============================================
   RESPONSIVE — TABLET (≤1024px)
   Sidebar goes to top, stacked layout
   ============================================= */
@media (max-width: 1024px) {
    .layout {
        margin-left: 0;
        padding: 20px 16px 60px;
        margin-top: 63px;
    }

    .sidebar {
        position: static;
        width: 100%;
        max-width: 100%;
        margin: 0 0 20px 0;
        border-radius: 9px;
        top: auto;
        left: auto;
    }

    .settings-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 0;
    }

    .sidebar h2 {
        font-size: 18px;
        padding: 14px 18px;
        white-space: nowrap;
    }

    .settings-body {
        flex: 1;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 12px 24px;
        padding: 12px 18px;
    }

    .setting-items {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .setting-label {
        font-size: 13px;
        white-space: nowrap;
    }

    .container select {
        width: auto;
        min-width: 140px;
    }

    .sidebar-actions {
        flex-direction: row;
        align-items: center;
        margin-top: 0;
        gap: 12px;
    }

    .btn-sidebar-clear {
        width: auto;
        padding: 8px 14px;
        white-space: nowrap;
    }

    .btn-saveDefault {
        margin-top: 0;
        white-space: nowrap;
    }

    .invoice-paper { padding: 32px 28px; }

    header {
        flex-direction: row;
        align-items: flex-start;
        gap: 16px;
    }

    .top-grid {
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }

    .footer-grid {
        grid-template-columns: 1fr 280px;
        gap: 24px;
    }
}

/* =============================================
   RESPONSIVE — TABLET SMALL (≤768px)
   ============================================= */
@media (max-width: 768px) {
    /* — Navbar — */
    .navbar {
        padding: 10px 14px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
    }

    .navbar h1 {
        font-size: 22px;
    }

    .nav-actions {
        gap: 8px;
    }

    .btn {
        padding: 7px 12px;
        font-size: 13px;
        border-radius: 8px;
    }

    /* — Layout — */
    .layout {
        padding: 16px 12px 60px;
        margin-top: 0;
        padding-top: calc(63px + 12px);
    }

    /* Detect when navbar wraps */
    .navbar:has(.nav-actions) {
        padding-bottom: 10px;
    }
 header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 14px;
        text-align: center;
    }

    .invoice-title-block {
        order: 1;
    }

    .logo-upload,
    #logoPreview {
        order: 2;
    }

    .logo-upload {
        margin-top: 8px;
    }
    /* — Sidebar horizontal on tablet — */
    .sidebar {
        position: static;
        width: 100%;
        margin-bottom: 16px;
        border-radius: 9px;
    }

    .settings-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .sidebar h2 {
        font-size: 16px;
        padding: 12px 14px;
    }

    .settings-body {
        flex: 1;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px 16px;
        padding: 10px 14px;
    }

    .setting-items {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .setting-label { font-size: 12px; }

    .container select {
        width: auto;
        min-width: 120px;
        font-size: 12px;
        padding: 7px 28px 7px 10px;
    }

    .sidebar-actions {
        flex-direction: row;
        align-items: center;
        margin-top: 0;
        gap: 10px;
    }

    .btn-sidebar-clear {
        width: auto;
        padding: 7px 12px;
        font-size: 11px;
    }

    .btn-saveDefault {
        margin-top: 0;
        font-size: 11px;
    }

    /* — Invoice paper — */
    .invoice-paper { padding: 20px 16px; }

    /* — Header — */
    header {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 24px;
    }

    .logo-upload {
        width: 110px;
        height: 70px;
        border-radius: 10px;
    }

    .invoice-word {
        font-size: 1.8rem;
        letter-spacing: 3px;
    }

    .invoice-number input {
        width: 80px;
        font-size: 0.9rem;
    }

    /* — Top grid stacks — */
    .top-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        margin-bottom: 24px;
    }

    .address {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    textarea {
        height: 75px;
        font-size: 14px;
    }

    /* — Right fields — */
    .right-fields {
        gap: 8px;
    }

    .field-row {
        grid-template-columns: 120px 1fr;
        gap: 8px;
        padding: 3px 0;
    }

    .field-row label { font-size: 14px; }

    .field-row input {
        font-size: 14px;
        padding: 7px 12px;
    }

    .optional-field-row {
        grid-template-columns: 120px 1fr;
        gap: 8px;
    }

    .opt-label-group span { font-size: 14px; }
    .opt-input-box input { font-size: 14px; padding: 7px 12px; }

    /* — Items table — */
    .items-table-wrapper {
        border-radius: 6px;
        margin: 8px -4px 0;
    }

    .items-table { min-width: 460px; }

    .items-table thead th { padding: 10px 8px; font-size: 11px; }
    .items-table tbody td { padding: 8px; }
    .items-table input { font-size: 13px; }

    .add-btn { margin: 16px 0; padding: 9px; font-size: 13px; }

    /* — Footer: totals below notes — */
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .left-notes { order: 2; }
    .right-total { order: 1; }

    .total-row { font-size: 13px; }

    .percent-box input { width: 60px; }
    .paid-box input { width: 80px; }

    .add-links { gap: 12px; }
    .add-link { font-size: 12px; }
}

/* =============================================
   RESPONSIVE — MOBILE (≤600px)
   ============================================= */
@media (max-width: 600px) {
    /* Navbar: stack vertically on very small screens */
    .navbar {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 14px 10px;
        gap: 8px;
        height: auto;
    }

    .navbar h1 {
        font-size: 20px;
        width: 100%;
    }

    .nav-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .btn {
        width: 100%;
        padding: 9px 10px;
        font-size: 13px;
        border-radius: 10px;
        text-align: center;
        justify-content: center;
        display: flex;
        align-items: center;
    }

    /* Dynamic top padding based on navbar height */
    .layout {
        padding: 0 10px 60px;
        padding-top: 110px; /* approx navbar height on mobile */
        margin-top: 0;
    }

    /* — Sidebar collapses to compact card — */
    .sidebar {
        margin-bottom: 12px;
    }

    .settings-container {
        flex-direction: column;
        align-items: stretch;
    }

    .sidebar h2 {
        font-size: 15px;
        padding: 12px 14px 8px;
        border-bottom: 1px solid #f0eded;
    }

    .settings-body {
        flex-direction: column;
        gap: 12px;
        padding: 12px 14px 14px;
    }

    .setting-items {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .container select {
        width: auto;
        flex: 1;
        min-width: 0;
        font-size: 13px;
    }

    .sidebar-actions {
        flex-direction: row;
        gap: 10px;
        margin-top: 4px;
    }

    .btn-sidebar-clear {
        flex: 1;
        padding: 8px;
        font-size: 12px;
    }

    .btn-saveDefault {
        flex: 1;
        font-size: 12px;
        padding: 8px;
        border: 1px solid #ddd;
        border-radius: 6px;
    }

    /* — Invoice paper — */
    .invoice-paper { padding: 16px 12px; }

    /* — Header — */
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        margin-bottom: 20px;
    }

    .logo-upload {
        width: 100px;
        height: 60px;
        border-radius: 8px;
    }

    .invoice-title-block {
        text-align: left;
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
    }

    .invoice-word {
        font-size: 1.6rem;
        letter-spacing: 2px;
        margin-bottom: 0;
    }

    .invoice-number {
        justify-content: flex-end;
    }

    .invoice-number input { width: 70px; font-size: 0.85rem; }

    /* — Top grid fully stacked — */
    .top-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* — Address: keep 2 col if possible, stack if too tight — */
    .address {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    textarea {
        font-size: 13px;
        padding: 8px 10px;
        height: 68px;
    }

    /* — Right fields — */
    .right-fields { gap: 6px; }

    .field-row {
        grid-template-columns: 100px 1fr;
        gap: 6px;
    }

    .field-row label { font-size: 13px; }
    .field-row input { font-size: 13px; padding: 7px 10px; }

    .optional-field-row { grid-template-columns: 100px 1fr; gap: 6px; }
    .opt-label-group span { font-size: 13px; }
    .opt-input-box input { font-size: 13px; padding: 7px 10px; }

    /* — Table — */
    .items-table-wrapper { margin: 6px -2px 0; }
    .items-table { min-width: 420px; }
    .items-table thead th { padding: 9px 6px; font-size: 10px; }
    .items-table tbody td { padding: 7px 6px; }
    .items-table input { font-size: 12px; }

    /* — Footer totals — */
    .total-row { font-size: 13px; gap: 8px; }
    .total-big span, .total-big strong { font-size: 14px; }
    .balance-row span, .balance-row strong { font-size: 14px; }

    .percent-box input { width: 55px; padding: 5px 6px; font-size: 13px; }
    .percent-box span  { padding: 5px 6px; font-size: 12px; }
    .paid-box input    { width: 75px; padding: 5px 6px; font-size: 13px; }
    .paid-box span     { padding: 5px 7px; font-size: 12px; }

    .add-links { gap: 8px; }
    .add-link { font-size: 12px; }
}

/* =============================================
   RESPONSIVE — MOBILE SMALL (≤480px)
   ============================================= */
@media (max-width: 480px) {
    .layout { padding-top: 120px; padding-left: 8px; padding-right: 8px; }

    .navbar { padding: 8px 12px 10px; }
    .navbar h1 { font-size: 18px; }

    .btn { font-size: 12px; padding: 8px 8px; border-radius: 8px; }

    .invoice-paper { padding: 14px 10px; border-radius: 8px; }

    /* Header stays horizontal with title on same row as number */
    header { gap: 10px; }
    .logo-upload { width: 80px; height: 52px; }
    .invoice-word { font-size: 1.4rem; letter-spacing: 1.5px; }
    .invoice-number input { width: 60px; font-size: 0.8rem; }

    /* Address: single column */
    .address { grid-template-columns: 1fr; gap: 10px; }

    textarea { height: 60px; font-size: 13px; }

    .field-row {
        grid-template-columns: 90px 1fr;
        gap: 5px;
    }
    .optional-field-row { grid-template-columns: 90px 1fr; gap: 5px; }
    .field-row label { font-size: 12px; }
    .field-row input  { font-size: 12px; padding: 6px 8px; }
    .opt-label-group span { font-size: 12px; }
    .opt-input-box input { font-size: 12px; padding: 6px 8px; }

    .items-table { min-width: 380px; }
    .items-table thead th { padding: 8px 5px; font-size: 10px; }
    .items-table tbody td { padding: 6px 5px; }
    .items-table input { font-size: 12px; }

    .add-btn { padding: 8px; font-size: 12px; }

    .total-row { font-size: 12px; }
    .total-big span, .total-big strong { font-size: 13px; }
    .balance-row span, .balance-row strong { font-size: 13px; }

    .percent-box input { width: 48px; padding: 4px 5px; font-size: 12px; }
    .percent-box span  { padding: 4px 5px; font-size: 11px; }
    .paid-box input    { width: 65px; padding: 4px 5px; font-size: 12px; }
    .paid-box span     { padding: 4px 6px; font-size: 11px; }

    .add-link { font-size: 11px; }

    .confirm-dialog { padding: 18px; }
    .confirm-dialog h3 { font-size: 18px; }
}

/* =============================================
   RESPONSIVE — MOBILE TINY (≤360px)
   ============================================= */
@media (max-width: 360px) {
    .layout { padding-top: 125px; padding-left: 6px; padding-right: 6px; }

    .navbar { padding: 8px 10px; gap: 6px; }
    .navbar h1 { font-size: 16px; }
    .nav-actions { gap: 6px; }
    .btn { font-size: 11px; padding: 7px 6px; }

    .invoice-paper { padding: 12px 8px; }
    .invoice-word { font-size: 1.2rem; }
    .logo-upload { width: 70px; height: 46px; }
    .invoice-number input { width: 55px; font-size: 0.75rem; }

    .field-row { grid-template-columns: 80px 1fr; gap: 4px; }
    .optional-field-row { grid-template-columns: 80px 1fr; gap: 4px; }
    .field-row label { font-size: 11px; }
    .field-row input { font-size: 11px; padding: 5px 7px; }
    .opt-label-group span { font-size: 11px; }
    .opt-input-box input { font-size: 11px; padding: 5px 7px; }

    textarea { height: 56px; font-size: 12px; padding: 7px 8px; }

    .items-table { min-width: 340px; }
    .items-table thead th { font-size: 9px; padding: 7px 4px; }
    .items-table tbody td { padding: 5px 4px; }
    .items-table input { font-size: 11px; }

    .total-row { font-size: 11px; }
    .percent-box input { width: 42px; font-size: 11px; }
    .paid-box input    { width: 58px; font-size: 11px; }
}

/* =============================================
   OVERFLOW GUARD
   ============================================= */
html, body { overflow-x: hidden; }

.layout, .invoice-paper, .top-grid, .footer-grid,
.address, .field-row, .optional-field-row, .right-fields, .left-fields,
.items-table, .items-table tbody, .items-table tr, .items-table td {
    max-width: 100%;
}

.top-grid > *, .footer-grid > *, .address > *, .field-row > *, .optional-field-row > * {
    min-width: 0;
}

/* =============================================
   NAVBAR HEIGHT OFFSET HELPER
   Dynamically adjust layout top offset using
   a JS-set --navbar-h custom property if needed.
   Falls back to fixed values above.
   ============================================= */
@supports (padding-top: env(safe-area-inset-top)) {
    .navbar {
        padding-top: calc(0px + env(safe-area-inset-top));
    }
}
