/* ==========================================================================
   Proforma Invoice Generator — Stylesheet
   ========================================================================== */

:root {
    --brand: #0056b3;
    --brand-dark: #003d82;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --border: #e1e5eb;
    --text: #2b2f36;
    --text-muted: #6c757d;
    --danger: #dc3545;
    --success: #1d9a5b;
    --radius: 8px;
    --sidebar-width: 230px;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* ---------------------------------------------------------------------- */
/* APP LAYOUT                                                              */
/* ---------------------------------------------------------------------- */
#app {
    display: none; /* toggled to flex by app.js once authenticated */
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--brand-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 20px 14px 40px;
}

.brand {
    text-align: center;
    padding-bottom: 18px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}

.brand-icon {
    font-size: 1.8rem;
    margin-bottom: 6px;
    color: #fff;
}

.brand-logo {
    height: 36px;       /* Adjust height to fit your sidebar navbar */
    width: auto;        /* Keeps the image aspect ratio natural */
    object-fit: contain;
    vertical-align: middle;
    border-radius: 4px; /* Optional rounded corners */
}

.brand h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.version-tag {
    display: block;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: rgba(255,255,255,0.8);
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.nav-btn i {
    width: 18px;
    text-align: center;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.nav-btn.active {
    background: var(--brand);
    color: #fff;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.15);
}

.sidebar-footer > button,
.sidebar-footer > label {
    width: 100%;
    box-sizing: border-box;
}

.main-content {
    flex: 1;
    padding: 28px 32px 42px;
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
}

/* ---------------------------------------------------------------------- */
/* VIEWS                                                                    */
/* ---------------------------------------------------------------------- */
.app-view {
    display: none;
}

.app-view.active-view {
    display: block;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.view-header h1 {
    font-size: 1.5rem;
    color: var(--brand-dark);
}

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

/* ---------------------------------------------------------------------- */
/* CARDS & FORM GRID                                                        */
/* ---------------------------------------------------------------------- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin-bottom: 20px;
}

.card h3 {
    font-size: 1rem;
    color: var(--brand-dark);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid #eef1f5;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #eef1f5;
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.section-header-flex h3 {
    border: none;
    margin: 0;
    padding: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    align-items: start;
}

.form-section {
    grid-column: span 2;
}

.form-section.half-width {
    grid-column: span 1;
}

.form-section.full-width {
    grid-column: span 2;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 5px;
    color: #495057;
}

.field-hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 4px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-size: 0.88rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(0,86,179,0.12);
}

input[readonly] {
    background: #f1f3f5;
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

.inline-input {
    width: 130px;
    text-align: right;
    padding: 4px 8px;
}

/* Logo upload */
.logo-upload-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

#logo-preview {
    max-height: 44px;
    max-width: 100px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px;
    background: #fff;
}

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

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

th, td {
    border: 1px solid var(--border);
    padding: 9px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    background-color: #f8f9fb;
    font-weight: 600;
    color: #495057;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.items-table td input {
    padding: 6px 8px;
    font-size: 0.85rem;
}

.item-amount {
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

.items-table td:last-child,
.data-table td:last-child {
    text-align: center;
}

.empty-row {
    text-align: center;
    color: var(--text-muted);
    padding: 24px 10px !important;
}

/* ---------------------------------------------------------------------- */
/* BUTTONS                                                                    */
/* ---------------------------------------------------------------------- */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.87rem;
    line-height: 1.2;
    transition: background 0.15s, transform 0.05s;
    white-space: nowrap;
    vertical-align: middle;
}

.btn-primary i, .btn-secondary i, .btn-danger i, .btn-icon i, .nav-btn i {
    line-height: 1;
}

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

.btn-secondary {
    background-color: #6c757d;
    color: #fff;
}
.btn-secondary:hover { background-color: #5a6268; }

.btn-danger {
    background-color: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.custom-file-upload {
    text-align: center;
    justify-content: center;
    cursor: pointer;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
    background: #f1f3f5;
    color: var(--brand);
}

.btn-delete-cust:hover, .btn-delete-prod:hover, .btn-delete-pi:hover, .btn-remove-row:hover {
    color: var(--danger);
    background: #fdecea;
}

.btn-remove-row {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 6px 8px;
}

/* ---------------------------------------------------------------------- */
/* SEARCH BOX                                                                */
/* ---------------------------------------------------------------------- */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    min-width: 260px;
}

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

.search-box input {
    border: none;
    padding: 0;
    font-size: 0.87rem;
}

.search-box input:focus {
    box-shadow: none;
}

/* ---------------------------------------------------------------------- */
/* INVOICE SUMMARY CARD                                                     */
/* ---------------------------------------------------------------------- */
.calculation-summary-card .summary-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    font-size: 0.9rem;
}

.summary-line strong {
    color: var(--text);
}

.grand-total {
    font-size: 1.1rem;
    padding-top: 10px;
}

.grand-total strong {
    color: var(--brand);
    font-size: 1.25rem;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 8px 0;
}

/* ---------------------------------------------------------------------- */
/* MODALS                                                                    */
/* ---------------------------------------------------------------------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 25, 35, 0.55);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.modal-content.modal-lg {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--brand-dark);
}

.modal-header .close-modal-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------------- */
/* RESPONSIVE                                                                */
/* ---------------------------------------------------------------------- */
@media (max-width: 991px) {
    .sidebar {
        width: 76px;
        padding: 16px 8px;
    }
    .brand h2, .version-tag, .nav-btn span, .sidebar-footer span {
        display: none;
    }
    .nav-btn {
        justify-content: center;
    }
    .main-content {
        max-width: calc(100vw - 76px);
    }
    .form-grid, .form-section.half-width, .form-section.full-width {
        grid-template-columns: 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }
    .brand { display: none; }
    .nav-menu { flex-direction: row; }
    .sidebar-footer { flex-direction: row; }
    .main-content {
        max-width: 100vw;
        padding: 18px;
    }
}

/* ---------------------------------------------------------------------- */
/* PRINT (used when the html2pdf.js library is unavailable and the app     */
/* falls back to the browser's native print dialog for the invoice)        */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* LOGIN SCREEN                                                             */
/* ---------------------------------------------------------------------- */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 32px 30px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.login-brand {
    text-align: center;
    margin-bottom: 22px;
}

.login-brand .brand-icon {
    color: var(--brand);
    font-size: 2rem;
}

.login-brand h2 {
    color: var(--brand-dark);
    margin: 8px 0 2px;
}

.login-brand p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.login-error {
    color: var(--danger);
    font-size: 0.82rem;
    min-height: 1.1em;
    margin-bottom: 8px;
}

/* ---------------------------------------------------------------------- */
/* SESSION INFO / ROLE BADGE                                                */
/* ---------------------------------------------------------------------- */
.session-info {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px 10px;
}

.role-badge {
    background: rgba(255,255,255,0.18);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------------- */
/* ROLE-BASED VISIBILITY                                                    */
/* Staff/user accounts cannot reach Settings, Backup/Restore, or delete     */
/* records. This is UI-level only — see the Access Control note in the     */
/* Settings screen about the limits of client-side auth.                   */
/* ---------------------------------------------------------------------- */
body.role-user .admin-only,
body.role-user .btn-delete-cust,
body.role-user .btn-delete-prod,
body.role-user .btn-delete-pi {
    display: none !important;
}

/* ---------------------------------------------------------------------- */
/* PRINT                                                                     */
/* This is now the PRIMARY print path (the "Print" button calls             */
/* window.print() directly) as well as the fallback if html2pdf.js fails    */
/* to load for "Save PDF". Because the invoice preview lives inside a       */
/* fixed-position modal with a scrollable, height-limited body, printing    */
/* naively would clip anything taller than the on-screen modal — overflow   */
/* clipping from .modal-body applies to descendants regardless of their     */
/* own position value. So for print, the entire modal chain is flattened    */
/* to normal static flow with no height/overflow limits, letting the full   */
/* invoice paginate naturally.                                              */
/*                                                                            */
/* Two things that previously pushed the invoice onto a blank page 2:       */
/* (1) #app/#login-screen/#app-footer were only visibility:hidden, which    */
/*     still reserves their full-page layout space ahead of the modal in    */
/*     document order — display:none removes them from layout entirely.    */
/* (2) The flattening rules applied to EVERY .modal element (even closed    */
/*     ones), un-hiding them and adding more blank space — scoped to        */
/*     .modal.open only now, so closed modals keep their default            */
/*     display:none from the base .modal rule.                              */
/* ---------------------------------------------------------------------- */
@media print {
    body * {
        visibility: hidden !important;
    }

    #print-area, #print-area * {
        visibility: visible !important;
    }

    #app, #login-screen, #app-footer {
        display: none !important;
    }

    .modal.open, .modal.open .modal-content, .modal.open .modal-body {
        position: static !important;
        display: block !important;
        overflow: visible !important;
        max-height: none !important;
        max-width: none !important;
        height: auto !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
        box-shadow: none !important;
        border: none !important;
        inset: auto !important;
    }

    .modal.open .modal-header, .modal.open .modal-footer {
        display: none !important;
    }

    #print-area {
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }

    @page {
        size: A4;
        margin: 12mm;
    }
}
/* ---------------------------------------------------------------------- */
/* EDIT MODE BANNER                                                         */
/* ---------------------------------------------------------------------- */
.edit-mode-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fff6e0;
    border: 1px solid #f0c869;
    color: #8a6415;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* ---------------------------------------------------------------------- */
/* FOOTER                                                                    */
/* ---------------------------------------------------------------------- */
#app-footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    text-align: center;
    background: rgba(0, 61, 130, 0.94);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.72rem;
    padding: 6px 10px;
    z-index: 900;
    letter-spacing: 0.02em;
}
