@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #f8fafc;
    --secondary-hover: #f1f5f9;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;

    --sidebar-w: 260px;
    --border-radius: 12px;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --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);

    /* Invoice Specific CSS vars */
    --orange: #2563eb; /* Rebranding orange to blue */
    --orange-deep: #1d4ed8;
    --orange-soft: #eff6ff;
    --ink: #0f172a;
    --ink-soft: #334155;
    --paper: #ffffff;
    --line: #e2e8f0;
    --line-soft: #f1f5f9;
    --muted: #64748b;
    --strip-w: 6px;
    --pad-x: 14mm;
    --pad-top: 6mm;
    --pad-bot: 4mm;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg-color); color: var(--text-main); line-height: 1.5; }

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

/* Sidebar */
.sidebar { width: var(--sidebar-w); background-color: var(--card-bg); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; z-index: 10; box-shadow: var(--shadow-sm); height: 100vh; }
.sidebar-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.logo { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 700; color: var(--primary); }
.logo i { font-size: 24px; }
/* The nav list scrolls on its own so a long menu never pushes the footer
   (theme toggle / account) off-screen. min-height:0 lets the flex child shrink. */
.sidebar-nav { padding: 16px 14px; flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.sidebar-nav { scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 8px; color: var(--text-muted); text-decoration: none; font-weight: 500; transition: all 0.2s ease; flex-shrink: 0; }
.nav-item i { font-size: 20px; }
.nav-item:hover { background-color: var(--secondary); color: var(--text-main); }
.nav-item.active { background-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; background: var(--bg-color); }
.top-header { display: flex; justify-content: space-between; align-items: center; padding: 24px 40px; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(10px); }
.top-header h1 { font-size: 24px; font-weight: 600; }
.header-actions { display: flex; gap: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 6px; font-weight: 500; font-family: inherit; cursor: pointer; transition: all 0.2s; border: none; font-size: 14px; }
.btn-primary { background-color: var(--primary); color: white; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2); }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--card-bg); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--secondary); }
.btn-success { background-color: var(--success); color: white; }
.btn-success:hover { background-color: #047857; }

.content-area { padding: 0 40px 40px; flex: 1; }
.page-section { display: none; animation: fadeIn 0.3s ease; }
.page-section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; margin-bottom: 32px; }
.stat-card { background: var(--card-bg); border-radius: var(--border-radius); padding: 24px; display: flex; align-items: center; gap: 20px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 28px; }
.stat-details h3 { font-size: 14px; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.stat-details p { font-size: 28px; font-weight: 700; color: var(--text-main); }

.dashboard-widgets { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.widget { background: var(--card-bg); border-radius: var(--border-radius); border: 1px solid var(--border-color); overflow: hidden; box-shadow: var(--shadow-sm); }
.widget-header { padding: 20px 24px; border-bottom: 1px solid var(--border-color); }
.widget-header h2 { font-size: 16px; font-weight: 600; }

.card { background: var(--card-bg); border-radius: var(--border-radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); overflow: hidden; margin-bottom: 24px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 14px 24px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 14px; }
.table th { font-weight: 600; color: var(--text-muted); background: var(--secondary); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
.table tbody tr:hover { background-color: var(--secondary); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; color: var(--text-muted); margin-bottom: 8px; font-size: 14px; }
.form-control { width: 100%; padding: 10px 14px; border: 1px solid var(--border-color); border-radius: 6px; font-family: inherit; font-size: 14px; transition: all 0.2s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
.col { flex: 1; }
.row { display: flex; gap: 16px; }

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    box-sizing: border-box;
    overflow-y: auto;
}
.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}
.modal-content {
    background: var(--card-bg);
    width: 100%;
    max-height: min(90vh, calc(100vh - 48px));
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
    position: relative;
    border: 1px solid var(--border-color);
}
.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: var(--card-bg);
    z-index: 2;
}
.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}
.close-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: background-color 0.15s, color 0.15s, transform 0.1s;
    flex-shrink: 0;
    line-height: 1;
}
.close-btn:hover {
    background-color: var(--secondary);
    color: var(--text-main);
    transform: scale(1.05);
}
.close-btn:active {
    transform: scale(0.95);
}
.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    overscroll-behavior: contain;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
    flex-shrink: 0;
}
.modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
    background: var(--card-bg);
    z-index: 2;
}
body.modal-open {
    overflow: hidden !important;
}

/* Modal table scroll & sticky headers */
.modal-body .table-responsive {
    max-height: 100%;
    overflow: auto;
}
#glDetailModal .table th {
    position: sticky;
    top: 0;
    background: var(--secondary);
    z-index: 5;
    box-shadow: 0 1px 0 var(--border-color);
}



/* ==================================================================== */
/* INVOICE A4 LAYOUT (Extracted & Adapted) */
/* ==================================================================== */

.invoice-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

.page-container {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding-bottom: 20px;
}

.page {
    background: var(--paper);
    width: 210mm;
    min-height: 297mm;
    box-shadow: 0 8px 40px rgba(0,0,0,.12);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.page::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0;
    width: var(--strip-w); background: var(--orange); z-index: 2;
}

.page-content-area { flex: 1 1 auto; position: relative; z-index: 3; }
.page-content-inner { width: 100%; transform-origin: top left; }

.page-header {
    flex: 0 0 auto;
    padding: var(--pad-top) var(--pad-x) 12px calc(var(--pad-x) + 2mm);
    display: grid; grid-template-columns: 1fr auto;
    align-items: flex-start; gap: 20px;
    border-bottom: 1px solid var(--line);
    background: radial-gradient(circle at 100% 0%, var(--orange-soft) 0%, transparent 40%), var(--paper);
}
/* Dark accent strip below the logo (restored from the old bill). */
.page-header .workshop-tag {
    display: inline-block; margin-top: 6px;
    background: var(--ink); color: #fff;
    font-family: 'DM Mono', monospace; font-weight: 700;
    font-size: 11px; letter-spacing: 3px; text-transform: uppercase;
    padding: 4px 12px;
}
.page-header .workshop-tag::before { content: "· "; color: var(--orange); }

/* Bill-type badge on the printed page (right, under the REF). Prints. */
.page-header .doc-badge .copy-badge {
    margin-top: 8px; display: inline-block;
    font-family: 'DM Mono', monospace; font-size: 9px; font-weight: 700;
    letter-spacing: 1.5px; text-transform: uppercase;
    padding: 3px 9px; border-radius: 3px;
    background: var(--ink); color: #fff;
}
.page-header .doc-badge .copy-badge.outside { background: var(--orange); }
.page-header .doc-badge .copy-badge.detailed { background: #6366f1; }

.page-header .doc-badge { text-align: right; }
.page-header .doc-badge .label { font-family: 'Bricolage Grotesque', sans-serif; font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1; color: var(--ink); text-transform: uppercase; }
.page-header .doc-badge .label::first-letter { color: var(--orange); }
.page-header .doc-badge .ref { margin-top: 6px; font-family: 'DM Mono', monospace; font-size: 11px; color: var(--muted); letter-spacing: .5px; }

.page-footer {
    flex: 0 0 auto; background: var(--ink); color: #fff;
    padding: 12px 18px 12px calc(var(--pad-x) + 2mm);
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; position: relative;
}
.page-footer::before { content: ""; position: absolute; top: 0; left: 6px; right: 0; height: 3px; background: var(--orange); }
.page-footer .brand-mini { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 600; font-size: 14px; letter-spacing: .3px; }
.page-footer .brand-mini span { color: var(--orange); }
.page-footer .contacts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; font-size: 10px; }
.page-footer .contacts .item { display: flex; gap: 7px; align-items: flex-start; line-height: 1.4; }
.page-footer .contacts .ic { width: 16px; height: 16px; border-radius: 50%; background: var(--orange); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: #fff; margin-top: 1px; }
.page-footer .vat { font-family: 'DM Mono', monospace; font-size: 9px; letter-spacing: 1.5px; text-align: right; opacity: .85; }
.page-footer .vat .k { color: var(--orange); display: block; margin-bottom: 2px; }

.page-body { padding: 14px var(--pad-x) 14px calc(var(--pad-x) + 2mm); font-size: 12px;}

[contenteditable="true"] { outline: none; border-radius: 2px; transition: background .15s, box-shadow .15s; min-width: 12px; }
[contenteditable="true"]:hover { background: var(--orange-soft); }
[contenteditable="true"]:focus { background: var(--orange-soft); box-shadow: 0 0 0 2px var(--orange); }
input.cell, textarea.cell { width: 100%; border: none; padding: 4px 6px; font: inherit; color: inherit; background: transparent; text-align: right; border-radius: 2px; resize:none;}
input.cell:focus, textarea.cell:focus { background: var(--orange-soft); outline: 1px solid var(--orange); }
input.cell:disabled, textarea.cell:disabled { color: var(--ink); background: transparent !important; outline: none !important; cursor: default; }
input.cell:disabled::placeholder, textarea.cell:disabled::placeholder { color: transparent; }
input.cell.left, textarea.cell.left { text-align: left; }
input.cell.center { text-align: center; }
input.tax-rate { width: 44px; padding: 2px 4px; text-align: right; border: 1px solid var(--line); border-radius: 3px; font: inherit; background: #fff; }
input.tax-rate:focus { outline: 1px solid var(--orange); border-color: var(--orange); }

.section { margin-bottom: 16px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.section-num { font-family: 'DM Mono', monospace; font-size: 10px; font-weight: 500; color: var(--orange); background: var(--orange-soft); padding: 2px 7px; border-radius: 3px; letter-spacing: .5px; }
.section-title { font-family: 'Bricolage Grotesque', sans-serif; font-size: 11px; font-weight: 600; color: var(--ink); text-transform: uppercase; letter-spacing: 2.5px; }
.section-line { flex: 1; height: 1px; background: var(--line); }

.party-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); background: #fff; }
.party { padding: 12px 14px; border-right: 1px solid var(--line); }
.party:last-child { border-right: none; }
.party .key { font-family: 'DM Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 6px; }
.party .body { font-size: 12px; line-height: 1.55; }

.meta-strip { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink); color: #fff; margin-bottom: 14px; }
.meta-strip .cell { padding: 9px 12px; border-right: 1px solid #2a2520; }
.meta-strip .cell:last-child { border-right: none; }
.meta-strip .key { font-family: 'DM Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 2px; color: var(--orange); margin-bottom: 3px; }
.meta-strip .val { font-family: 'DM Mono', monospace; font-size: 11.5px; font-weight: 500; }

table.items { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
table.items th { background: var(--ink); color: #fff; font-family: 'DM Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 1.8px; font-weight: 500; padding: 9px 10px; text-align: left; border-right: 1px solid #2a2520; }
table.items th:last-child { border-right: none; }
table.items th.num { text-align: right; }
table.items td { padding: 4px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; font-size: 12px; }
table.items tr:hover td { background: #fdfaf4; }
table.items td.idx { text-align: center; width: 32px; font-family: 'DM Mono', monospace; font-size: 11px; color: var(--muted); }
table.items td.num { text-align: right; white-space: nowrap; font-family: 'DM Mono', monospace; }

.row-actions { width: 30px; text-align: center; }
.row-actions button { background: transparent; border: none; cursor: pointer; color: #c0392b; font-size: 16px; line-height: 1; width: 22px; height: 22px; border-radius: 3px; transition: background .15s; }
.row-actions button:hover { background: #fde2e0; }

.add-buttons { margin: 10px 0 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.add-buttons button { background: transparent; border: 1px dashed var(--line); color: var(--muted); padding: 6px 12px; border-radius: 4px; cursor: pointer; font: 500 11px 'DM Sans'; text-transform: uppercase; letter-spacing: 1px; transition: all .15s; }
.add-buttons button:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-soft); }

.totals-wrap { display: grid; grid-template-columns: 1fr 360px; gap: 18px; margin-bottom: 18px; }
.notes { padding: 12px 14px; border: 1px solid var(--line); background: #fff; font-size: 11.5px; color: var(--ink-soft); }
.notes .key { font-family: 'DM Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 6px; }
table.totals { border-collapse: collapse; width: 100%; }
table.totals td { padding: 6px 12px; border-bottom: 1px solid var(--line-soft); }
table.totals td:first-child { color: var(--ink-soft); font-size: 11.5px; }
table.totals td:last-child { text-align: right; font-family: 'DM Mono', monospace; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 500; }
table.totals tr.grand td { background: var(--orange); color: #fff; border: none; padding: 11px 14px; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; font-size: 13.5px; letter-spacing: .3px; text-transform: uppercase; }
table.totals tr.grand td:last-child { font-family: 'DM Mono', monospace; font-size: 15px; }

.signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin: 28px 0 8px; page-break-inside: avoid; }
.sig-block { text-align: center; padding-top: 32px; border-top: 1px solid var(--ink); font-family: 'DM Mono', monospace; font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: var(--ink-soft); }

/* Right-aligned e-signature: image above the dashed line, label below. Prints. */
.signatures.sig-right { display: flex; justify-content: flex-end; margin: 24px 0 8px; page-break-inside: avoid; }
.sig-sign { text-align: center; }
.sig-sign img { max-height: 60px; margin: 0 auto 4px; display: block; }
.sig-line { border-top: 1px dashed #94a3b8; width: 200px; margin: 0 auto 6px; }
.sig-label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }

/* Outside (customer) bill: hide the Unit + Length columns. */
.items.outside-bill th.col-unit, .items.outside-bill td.col-unit,
.items.outside-bill th.col-length, .items.outside-bill td.col-length { display: none; }

/* Bill-type toggle in the toolbar (never prints). */
.billtype-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.billtype-toggle .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.billtype-toggle .seg button { border: none; background: transparent; padding: 6px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.billtype-toggle .seg button.active { background: var(--orange); color: #fff; }

.payment-block { display: grid; grid-template-columns: 1fr; border: 1px solid var(--line); margin-bottom: 14px; background: #fff; page-break-inside: avoid; }
.payment-block > div { padding: 11px 14px; }
.payment-block .key { font-family: 'DM Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 4px; }
.payment-block .val { font-size: 11.5px; line-height: 1.5; }

/* Status Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-draft { background: #fef3c7; color: #d97706; }
.badge-finalized { background: #dcfce7; color: #15803d; }
.badge-low { background: #fee2e2; color: #b91c1c; }
.badge-ok { background: #f1f5f9; color: #475569; }
.badge-paid { background: #dcfce7; color: #15803d; }
.badge-partial { background: #fef3c7; color: #b45309; }
.badge-unpaid { background: #fee2e2; color: #b91c1c; }
.badge-cancelled { background: #e2e8f0; color: #475569; text-decoration: line-through; }
.badge-revised { background: #ede9fe; color: #6d28d9; text-decoration: line-through; }

/* Margin hint shown under a rate cell while billing */
.margin-hint { font-size: 10px; margin-top: 2px; font-family: 'DM Mono', monospace; }
.margin-hint.ok { color: #15803d; }
.margin-hint.warn { color: #b91c1c; font-weight: 600; }
.margin-hint.muted { color: #94a3b8; }

/* Three-way pricing comparison badges under an invoice rate cell. */
.pbadges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.pbadge { font-size: 9.5px; font-weight: 600; padding: 1px 5px; border-radius: 4px; white-space: nowrap; line-height: 1.5; }
.pbadge-cost { background: rgba(245, 158, 11, .14); color: #b45309; }
.pbadge-market { background: rgba(37, 99, 235, .12); color: #1d4ed8; }
.pbadge-suggested { background: rgba(16, 185, 129, .15); color: #047857; }

/* Account controls in the sidebar */
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.sidebar-footer .account-line { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.sidebar-footer .account-actions { display: flex; gap: 8px; }
.sidebar-footer .account-actions button { flex: 1; font-size: 12px; padding: 8px 10px; }
.default-pw-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 20px; display: none; }
.default-pw-warning.show { display: block; }

/* Login overlay */
.login-overlay { position: fixed; inset: 0; background: linear-gradient(135deg, #1e3a8a, #0f172a); display: none; align-items: center; justify-content: center; z-index: 2000; }
.login-overlay.active { display: flex; }
.login-card { background: var(--card-bg); width: 100%; max-width: 380px; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 36px 32px; }
.login-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; color: var(--text-main); }
.login-card p.sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card .form-group { margin-bottom: 16px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-hint { color: var(--text-muted); font-size: 11px; margin-top: 16px; text-align: center; }

/* Discount input inside the totals table */
input.disc-input { width: 90px; padding: 2px 6px; text-align: right; border: 1px solid var(--line); border-radius: 3px; font: inherit; background: #fff; }
input.disc-input:focus { outline: 1px solid var(--orange); border-color: var(--orange); }
.roundoff-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }

/* ==================================================================== */
/* FRESH LOOK + DARK MODE + UX COMPONENTS                                */
/* ==================================================================== */

/* Dark theme — overrides the app-chrome variables only. The invoice page
   keeps its own light "paper" palette (--paper/--ink/--line/...) so previews
   and printouts stay light in either theme. JS sets data-theme on <html>. */
:root[data-theme="dark"] {
    --bg-color: #0b1220;
    --card-bg: #131c2e;
    --text-main: #e6edf7;
    --text-muted: #93a4bd;
    --border-color: #24314a;
    --secondary: #1a2438;
    --secondary-hover: #212d45;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.45);
    --shadow-md: 0 6px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.6);
}
:root[data-theme="dark"] body { background: radial-gradient(1200px 600px at 100% -10%, rgba(37,99,235,.10), transparent 60%), var(--bg-color); }

/* Smooth theme transition */
body, .sidebar, .card, .stat-card, .widget, .modal-content, .form-control, .btn, .table th, .table td { transition: background-color .25s ease, color .25s ease, border-color .25s ease; }

/* Fresh-look polish (applies to both themes) */
.sidebar { background: var(--card-bg); }
:root[data-theme="dark"] .sidebar { background: #0f1728; }
.nav-item { border-radius: 10px; }
.nav-item.active { background: linear-gradient(135deg, var(--primary), #4f46e5); box-shadow: 0 8px 20px rgba(37,99,235,.35); }
.top-header { border-bottom: 1px solid transparent; }
:root[data-theme="dark"] .top-header { background: rgba(11,18,32,.7); }

.stat-card { border-radius: 16px; position: relative; }
.stat-card::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; border-radius: 16px 16px 0 0; background: linear-gradient(90deg, var(--primary), #4f46e5); opacity: 0; transition: opacity .2s; }
.stat-card:hover::after { opacity: .9; }

.btn { border-radius: 8px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #3b56e0); }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-hover), #3145c9); }
.btn-text { background: transparent !important; box-shadow: none !important; padding: 6px 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

.card { border-radius: 16px; }
.table th { background: var(--secondary); }
:root[data-theme="dark"] .table th { background: #1a2438; }
.table tbody tr { transition: background-color .12s; }

/* Form controls adapt to theme */
.form-control { background: var(--card-bg); color: var(--text-main); }
.form-control::placeholder { color: var(--text-muted); opacity: .8; }
select.form-control option { color: initial; }

/* Theme toggle button in the sidebar footer */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: 100%; cursor: pointer; }

/* Top progress bar (indeterminate) shown while any fetch is in flight */
.top-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 3000; background: transparent; overflow: hidden; opacity: 0; transition: opacity .2s; pointer-events: none; }
.top-progress.active { opacity: 1; }
.top-progress::before { content: ""; position: absolute; height: 100%; width: 40%; left: -40%; background: linear-gradient(90deg, transparent, var(--primary), #6366f1, transparent); animation: progress-slide 1.1s ease-in-out infinite; }
@keyframes progress-slide { 0% { left: -40%; } 100% { left: 100%; } }

/* Toasts */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 4000; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, 90vw); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 13px 16px; border-radius: 12px; background: var(--card-bg); color: var(--text-main); box-shadow: var(--shadow-lg); border: 1px solid var(--border-color); border-left: 4px solid var(--primary); font-size: 14px; animation: toast-in .22s ease; }
.toast.hide { animation: toast-out .2s ease forwards; }
.toast.success { border-left-color: #10b981; }
.toast.error { border-left-color: #ef4444; }
.toast.info { border-left-color: var(--primary); }
.toast .toast-ic { font-weight: 700; line-height: 1.3; }
.toast.success .toast-ic { color: #10b981; }
.toast.error .toast-ic { color: #ef4444; }
.toast.info .toast-ic { color: var(--primary); }
.toast .toast-msg { flex: 1; line-height: 1.4; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }

/* Skeleton loading rows */
.skeleton-row td { padding: 16px 24px; }
.skeleton { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--secondary) 25%, var(--secondary-hover) 50%, var(--secondary) 75%); background-size: 200% 100%; animation: skeleton-shimmer 1.2s infinite; }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Inline spinner */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-color); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
.section-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty states */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-emoji { font-size: 40px; margin-bottom: 12px; opacity: .8; }
.empty-state h3 { font-size: 16px; color: var(--text-main); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* Confirm/prompt dialog reuses .modal; slightly narrower */
#confirmDialog .modal-content { max-width: 440px; }
#confirmDialog .confirm-message { font-size: 14px; color: var(--text-muted); line-height: 1.55; margin-bottom: 8px; }
#confirmDialog input.form-control { margin-top: 12px; }

/* ==================================================================== */
/* RESPONSIVE LAYOUT                                                     */
/* ==================================================================== */

/* Reusable two-column split (collapses on narrow screens) */
.split-2 { display: grid; gap: 24px; align-items: start; }
.split-2.wide-left { grid-template-columns: 380px 1fr; }
.split-2.wide-right { grid-template-columns: 320px 1fr; }

/* Header title + hamburger (hamburger hidden on desktop) */
.header-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; background: transparent; border: 1px solid var(--border-color); color: var(--text-main); width: 40px; height: 40px; border-radius: 10px; font-size: 22px; cursor: pointer; align-items: center; justify-content: center; flex-shrink: 0; }
.menu-toggle:hover { background: var(--secondary); }

/* Mobile off-canvas sidebar backdrop */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); z-index: 1400; }
.sidebar-backdrop.show { display: block; }

/* Large laptops / small desktops */
@media (max-width: 1200px) {
    .content-area { padding: 0 28px 32px; }
    .top-header { padding: 20px 28px; }
}

/* Tablets: stack the dashboard widgets */
@media (max-width: 1024px) {
    .dashboard-widgets { grid-template-columns: 1fr; }
}

/* Narrow: collapse the two-column splits */
@media (max-width: 900px) {
    .split-2, .split-2.wide-left, .split-2.wide-right { grid-template-columns: 1fr; }
}

/* Phones & small tablets: off-canvas sidebar + compact chrome */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; width: 264px; max-width: 84vw;
        transform: translateX(-100%); transition: transform 0.25s ease; z-index: 1500;
        box-shadow: none;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main-content { width: 100%; }
    .menu-toggle { display: inline-flex; }

    .top-header { padding: 12px 14px; position: sticky; }
    .top-header h1 { font-size: 19px; }
    .content-area { padding: 0 14px 24px; }

    .stats-grid { grid-template-columns: 1fr; gap: 14px; margin-bottom: 20px; }
    .section-header { flex-wrap: wrap; align-items: flex-start; gap: 12px; }
    .header-actions { flex-wrap: wrap; gap: 10px; }
    .header-actions .btn, .section-header .btn { flex: 1 1 auto; }
    .invoice-toolbar { flex-wrap: wrap; gap: 12px; }

    /* Forms & modals stack and fit the viewport */
    .row { flex-direction: column; gap: 0; }
    .modal { padding: 12px 8px; }
    .modal-content { max-width: 98vw !important; margin: auto; max-height: calc(100vh - 24px); }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 12px 16px; }


    /* Denser tables so more fits before horizontal scroll */
    .table th, .table td { padding: 10px 12px; font-size: 13px; }
    .stat-card { padding: 18px; }
    .stat-details p { font-size: 24px; }

    /* Invoice-save actions stack full width */
    .invoice-save-actions { flex-wrap: wrap; }
    .invoice-save-actions .btn { flex: 1 1 auto; }
}

/* Very small phones */
@media (max-width: 420px) {
    .content-area { padding: 0 10px 20px; }
    .stat-card { gap: 14px; }
    .btn { padding: 9px 14px; font-size: 13px; }
}

/* Print rules */
@media print {
    .no-print { display: none !important; }
    .print-only { display: inline !important; }
    .app-container { height: auto; overflow: visible; }
    .main-content { overflow: visible; }
    .content-area { padding: 0 !important; }
    
    .page-section { display: none; }
    .page-section.print-only-section { display: block; }

    @page { size: A4; margin: 0; }
    html, body { background: #fff !important; margin: 0; padding: 0; width: 210mm; }
    
    .page { box-shadow: none; margin: 0; width: 210mm; page-break-after: avoid; page-break-inside: avoid; }

    [contenteditable="true"] { background: none !important; box-shadow: none !important; }
    input.cell, textarea.cell, input.tax-rate, input.disc-input { background: none !important; outline: none !important; border: none !important; resize: none; }

    .page-header, .page-footer, .meta-strip, table.items th, table.totals tr.grand td, .section-num, .page-footer::before, .page-footer .contacts .ic, .page::before,
    .page-header .workshop-tag, .page-header .doc-badge .copy-badge {
      -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
}

/* ----------------------------------------------------
   Role-based visibility (Admin / Cashier / Viewer).
   A `role-*` class on <html> hides controls the current role may not use.
   Server-side checks are authoritative; this is only to declutter the UI.
   ---------------------------------------------------- */
html:not(.role-admin) .admin-only { display: none !important; }
html:not(.role-admin):not(.role-manager) .manager-or-admin { display: none !important; }
html:not(.role-admin):not(.role-manager) .manager-only { display: none !important; }
html.role-viewer .hide-from-viewer, html.role-viewer .write-only { display: none !important; }
.account-role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #a0aec0;
  border: 1px solid rgba(160,174,192,0.4);
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 6px;
}

/* Bill Comparison — warning chips */
.bc-warn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.bc-warn { display: inline-flex; align-items: center; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 8px; }

/* Job Profit Analysis — summary footer + nav badge */
.jp-footer { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 2px solid var(--ink); background: var(--bg-color, #f8fafc); }
.jp-foot-cell { flex: 1; min-width: 130px; display: flex; flex-direction: column; }
.jp-foot-cell .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.jp-foot-cell .v { font-size: 16px; font-weight: 700; margin-top: 2px; }
.jp-foot-cell.jp-unpaid { min-width: 220px; }
.jp-foot-cell.jp-unpaid .k { color: #dc2626; font-weight: 700; }
.jp-foot-cell.jp-unpaid .v { font-size: 22px; font-weight: 800; color: #dc2626; }
.nav-badge { background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; margin-left: 6px; }

/* Job Profit Analysis — the three numbered comparisons.
   (1) our cost vs outside cost, (2) our price vs outside price,
   (3) our cost vs our price. Each card is headed by a step chip. */
.analysis-step { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--border-color); }
.analysis-step .step-no { flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--primary), #4f46e5); align-self: center; }
.analysis-step .step-title { font-size: 15px; font-weight: 600; color: var(--text-main); }
.analysis-step .step-hint { font-size: 12.5px; font-weight: 400; color: var(--text-muted); }
.analysis-sub { font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--text-muted); margin: 20px 0 8px; }
.analysis-note { font-size: 12px; color: var(--text-muted); margin-top: 10px; line-height: 1.6; }
/* The bottom line of each comparison. */
.table tr.analysis-total td { font-weight: 700; background: var(--secondary); border-top: 2px solid var(--border-color); }
/* Signed money: green when it went our way, red when it did not. The KPI
   selectors are listed explicitly because `.stat-details p` sets a colour and
   would otherwise out-specify a bare `.pos` / `.neg`. */
.pos, .stat-details p.pos { color: var(--success); }
.neg, .stat-details p.neg { color: var(--danger); }
.flat, .stat-details p.flat { color: var(--text-muted); }
:root[data-theme="dark"] .pos, :root[data-theme="dark"] .stat-details p.pos { color: #34d399; }
:root[data-theme="dark"] .neg, :root[data-theme="dark"] .stat-details p.neg { color: #f87171; }
/* "est" provenance tag on an outside cost derived from market retail. */
.basis-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 10px; font-size: 10px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; background: var(--secondary); color: var(--text-muted); border: 1px solid var(--border-color); }
