:root {
    --bg-dark: #0a0a0a;
    --bg-panel: #141414;
    --bg-input: #1f1f1f;
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --accent-red: #e60000;
    --accent-red-hover: #ff1a1a;
    --border-color: #333333;
    --inv-blue: #23228a;
    --inv-green: #0b8c19;
    --radius: 8px;
    --transition: all 0.2s ease-in-out;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
}

/* ── Auth Gate ── */
#auth-gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at top, #1a0000 0%, #0a0a0a 70%);
}

.auth-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 3rem;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(230, 0, 0, 0.15);
}

.auth-logo-img {
    max-width: 250px;
    margin-bottom: 1.5rem;
    display: inline-block;
}

.auth-card h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }
.auth-card p { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.95rem; }

.auth-error {
    color: #ff6b6b;
    margin-top: 1rem;
    font-size: 0.9rem;
    background: rgba(255,0,0,0.1);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

.g_id_signin { display: flex; justify-content: center; margin-bottom: 1rem; }

/* ── Header ── */
.app-header {
    background: var(--bg-panel);
    padding: 0.9rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 1.5rem; }
.header-logo-img { height: 26px; width: auto; display: block; }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-muted); }
.bc-item { cursor: pointer; transition: var(--transition); }
.bc-item:hover { color: var(--text-main); }
.bc-item.bc-home { }
.bc-sep { color: var(--border-color); }
.bc-current { color: var(--text-main); font-weight: 500; cursor: default; }

.header-right { display: flex; align-items: center; gap: 0.75rem; }

.user-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 99px;
}

.btn-outline { background: transparent; border: 1px solid var(--border-color); color: white; padding: 0.45rem 1rem; font-size: 0.85rem; border-radius: var(--radius); cursor: pointer; }
.btn-outline:hover { border-color: var(--text-muted); }
.btn-outline-sm { background: transparent; border: 1px solid #555; color: #aaa; padding: 0.3rem 0.7rem; font-size: 0.78rem; border-radius: var(--radius); cursor: pointer; }
.btn-outline-sm:hover { color: var(--accent-red); border-color: var(--accent-red); }

/* ── Layout ── */
.container {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.form-section {
    flex: 1;
    min-width: 480px;
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.preview-section {
    flex: 1.3;
    min-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.icon-btn-header {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    font-family: inherit;
}
.icon-btn-header:hover { border-color: var(--accent-blue); color: var(--accent-blue); background: rgba(0, 163, 255, 0.05); }

.status-badge-wrap { display: flex; align-items: center; gap: 0.5rem; }
.status-badge-wrap label { font-size: 0.8rem; color: var(--text-muted); }

.status-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
}

form h3 { margin: 1.5rem 0 1rem; font-size: 1.05rem; color: var(--text-muted); }

hr { border: 0; border-top: 1px dashed var(--border-color); margin: 2rem 0; }

.form-row { display: flex; gap: 1rem; margin-bottom: 1rem; }
.cols-3 > div { flex: 1; min-width: 0; }
.form-group { flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }

label { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; }

input, select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

input:focus, select:focus { outline: none; border-color: var(--accent-red); }

.addon-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-input);
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.6rem;
    border: 1px solid var(--border-color);
}

.addon-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent-red); cursor: pointer; flex-shrink: 0; }
.addon-item input[type="number"], .addon-item input[type="text"] { padding: 0.4rem 0.6rem; font-size: 0.9rem; background: var(--bg-panel); }
.addon-info { flex: 1; }
.addon-price { width: 100px; display: flex; align-items: center; gap: 3px; }

button { cursor: pointer; font-family: inherit; font-weight: 600; border: none; border-radius: var(--radius); }
.btn-primary { background: var(--accent-red); color: #fff; width: 100%; font-size: 1rem; padding: 1rem; box-shadow: 0 4px 15px rgba(230,0,0,0.4); transition: var(--transition); }
.btn-primary:hover { background: var(--accent-red-hover); transform: translateY(-1px); }
.btn-secondary { background: transparent; color: var(--text-main); border: 1px dashed var(--border-color); width: 100%; padding: 0.6rem; margin-top: 0.5rem; }
.btn-secondary:hover { border-color: var(--text-muted); }
.action-bar { display: flex; }

/* ── Invoice Canvas ── */
.invoice-wrapper {
    background: #e5e5e5;
    padding: 2rem;
    border-radius: var(--radius);
    overflow-x: auto;
    display: flex;
    justify-content: center;
}

.invoice-canvas {
    background: #fff;
    color: #333;
    width: 216mm;
    min-height: 279mm;
    padding: 18mm 20mm;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    font-family: 'Roboto', Arial, sans-serif;
    font-size: 14px;
}

.inv-top-bar { width: 100%; height: 12px; background: #000; margin-bottom: 24px; }

.inv-header { display: flex; justify-content: space-between; margin-bottom: 28px; }
.inv-logo-img { max-width: 220px; margin-bottom: 12px; display: block; }
.inv-contact { color: #666; line-height: 1.5; font-size: 13px; }
.inv-contact a { color: #0056b3; }
.inv-header-right { text-align: right; }
.inv-title { font-size: 30px; font-weight: 700; margin-bottom: 4px; }
.inv-submitted { font-size: 15px; font-weight: 700; color: var(--inv-green); }

.inv-details-grid { display: flex; gap: 24px; margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid #ccc; }
.inv-col { flex: 1; }
.inv-col h4 { font-size: 15px; font-weight: 700; margin-bottom: 6px; color: #222; }
.inv-col div { color: #555; margin-bottom: 2px; font-size: 13px; }

.inv-dates-grid { display: grid; grid-template-columns: 1fr 1fr; row-gap: 5px; margin-bottom: 12px; font-size: 13px; }
.inv-dates-grid strong { color: #333; }
.inv-payment-terms { color: #777; font-size: 11.5px; line-height: 1.4; }

.invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.invoice-table th { color: var(--inv-blue); border-bottom: 2px solid #ccc; padding: 10px 8px 10px 0; text-align: left; font-size: 14px; font-weight: 700; }
.invoice-table td { padding: 9px 8px 9px 0; border-bottom: 1px solid #eee; color: #333; font-size: 13px; vertical-align: top; }
.invoice-table tbody tr:nth-child(even) td { background: #fafafa; }

.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* ── Bottom Section ── */
.inv-bottom-section { display: flex; justify-content: space-between; margin-top: 8px; gap: 20px; }
.inv-notes-signature { width: 55%; }
.inv-notes-block { margin-bottom: 32px; font-size: 13px; }
.inv-signature-block h3 { font-size: 15px; margin-bottom: 36px; color: #333; }
.inv-signature-line { font-size: 20px; color: #333; display: flex; align-items: flex-end; }
.line-fill { border-bottom: 1px solid #888; flex: 1; margin-left: 5px; margin-bottom: 4px; }
.inv-signature-caption { font-size: 11px; color: #888; margin-top: 4px; line-height: 1.4; }

/* ── Totals ── */
.inv-totals-block { width: 42%; padding-left: 16px; }
.inv-total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; color: var(--inv-blue); }
.inv-total-row .value { font-weight: 700; color: #333; }
.highlight-total { padding: 8px 0; }
.highlight-total .value { font-size: 22px; color: var(--inv-green); }

/* KEY FIX: "Final Payment" label never wraps */
.nowrap { white-space: nowrap; }

.inv-final-note { text-align: right; font-size: 11px; color: #888; margin-top: 8px; line-height: 1.4; }

/* ── Modal ── */
.modal { display: none; position: fixed; z-index: 1000; inset: 0; background: rgba(0,0,0,0.8); }
.modal-content { background: var(--bg-panel); margin: 6% auto; padding: 2rem; border: 1px solid var(--border-color); width: 85%; max-width: 900px; border-radius: var(--radius); color: var(--text-main); max-height: 80vh; overflow-y: auto; }
.close-btn { color: var(--text-muted); float: right; font-size: 28px; cursor: pointer; line-height: 1; }
.close-btn:hover { color: var(--accent-red); }

.db-invoice-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.db-invoice-table th { background: var(--bg-input); padding: 0.7rem 1rem; text-align: left; font-size: 0.82rem; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px solid var(--border-color); }
.db-invoice-table td { padding: 0.8rem 1rem; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; vertical-align: middle; }
.db-invoice-table tr:hover td { background: rgba(255,255,255,0.03); }

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: calc(var(--radius) * 1.5);
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.modal-card h3 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}
.modal-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.status-pill { padding: 3px 10px; border-radius: 99px; font-size: 0.78rem; font-weight: 600; }
.status-Pending { background: rgba(255,180,0,0.15); color: #ffa500; }
.status-Confirmed { background: rgba(0,200,100,0.15); color: #0b8c19; }
.status-Cancelled { background: rgba(255,0,0,0.15); color: #e60000; }

.db-action-btn { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); padding: 0.3rem 0.7rem; font-size: 0.8rem; border-radius: var(--radius); cursor: pointer; margin-right: 4px; }
.db-action-btn:hover { border-color: var(--accent-red); color: var(--accent-red); }

/* ─────────────────────────────────────
   LANDING PAGE
───────────────────────────────────── */
.view { min-height: calc(100vh - 60px); }

#view-landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    background: radial-gradient(ellipse at 30% 0%, #1a0000 0%, #0a0a0a 60%);
}

.landing-hero { text-align: center; margin-bottom: 3.5rem; }
.landing-logo-img { max-width: 350px; margin-bottom: 1rem; display: inline-block; }
.landing-sub { color: var(--text-muted); font-size: 1.1rem; margin-top: 0.75rem; letter-spacing: 2px; text-transform: uppercase; }

.cta-grid {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.cta-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 3rem 3.5rem;
    width: 300px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.cta-card:hover {
    transform: translateY(-6px);
    border-color: var(--accent-red);
    box-shadow: 0 16px 40px rgba(230,0,0,0.25);
}

.cta-card.cta-secondary:hover {
    border-color: #fff;
    box-shadow: 0 16px 40px rgba(255,255,255,0.08);
}

.cta-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.cta-label { font-size: 1.4rem; font-weight: 800; letter-spacing: 2px; color: var(--text-main); }
.cta-desc { font-size: 0.9rem; color: var(--text-muted); line-height: 1.4; }

.cta-card:not(.cta-secondary) .cta-icon { color: var(--accent-red); }
.cta-card:not(.cta-secondary) .cta-label { color: var(--accent-red); }

/* ─────────────────────────────────────
   SEARCH PAGE
───────────────────────────────────── */
.search-page {
    max-width: 1300px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

.search-title { font-size: 1.8rem; font-weight: 700; margin-bottom: 0.4rem; }
.search-subtitle { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.95rem; }

.search-form-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 2rem;
}

.search-form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.search-actions { display: flex; gap: 1rem; align-items: center; }
.search-btn-size { width: auto; padding: 0.75rem 2.5rem; font-size: 1rem; }
.btn-secondary-sm { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 0.7rem 1.5rem; border-radius: var(--radius); cursor: pointer; font-family: inherit; font-size: 0.9rem; }
.btn-secondary-sm:hover { border-color: var(--text-main); color: var(--text-main); }

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.results-count { color: var(--text-muted); font-size: 0.9rem; }
.results-filter-input {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    width: 260px;
}
.results-filter-input:focus { outline: none; border-color: var(--accent-red); }

.results-table-wrap { overflow-x: auto; }

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.7rem;
}

.results-table th {
    background: var(--bg-input);
    padding: 0.75rem 1rem;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.results-table th.sortable { cursor: pointer; user-select: none; }
.results-table th.sortable:hover { color: var(--text-main); }
.results-table th.sort-asc .sort-icon::after  { content: ' ▲'; }
.results-table th.sort-desc .sort-icon::after { content: ' ▼'; }
.sort-icon { color: var(--border-color); font-size: 0.75rem; }

.results-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

.results-table tbody tr:hover td { background: rgba(255,255,255,0.03); cursor: pointer; }

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.4rem;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.open-quote-btn { color: var(--text-main); }
.open-quote-btn:hover { border-color: var(--accent-red); color: var(--accent-red); }

.delete-quote-btn { color: var(--accent-red); }
.delete-quote-btn:hover { border-color: var(--accent-red); background: rgba(230,0,0,0.1); }

.no-results { text-align: center; color: var(--text-muted); padding: 3rem; font-size: 1rem; }

.col-email {
    max-width: 15vw; /* Adjust max width dynamically */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.col-actions {
    text-align: center;
    white-space: nowrap;
}

/* ── Mobile Responsive ── */
@media (max-width: 1024px) {
    .container { flex-direction: column; }
    .form-section, .preview-section { min-width: 100%; width: 100%; }
    .form-row { flex-direction: column; gap: 0.5rem; }
    .cols-3 { flex-direction: column; }
    .search-form-grid { grid-template-columns: 1fr; }
    .inv-details-grid { flex-direction: column; gap: 15px; }
    .inv-header { flex-direction: column; align-items: center; text-align: center; }
    .inv-header-right { text-align: center; margin-top: 15px; }
    .results-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    
    .inv-bottom-section { flex-direction: column; gap: 30px; }
    .inv-notes-signature, .inv-totals-block { width: 100%; padding-left: 0; }
    
    .db-invoice-table th, .db-invoice-table td { font-size: 0.8rem; padding: 0.5rem; }
    .db-action-btn { font-size: 0.7rem; padding: 0.2rem 0.5rem; }
}
