/*
 * Bill Generator (bill generator): the tool's own components, styled in the site's design language (6 Oct 2026, on the
 * UltraCompress Pro template). Base: /libs/site-pages.css (tokens, Inter and Space Grotesk, buttons, theme toggle,
 * focus rings) and /libs/shared-nav.css (the site's header and footer). This file holds only what the tool itself
 * needs: the section tabs and toolbar, the dashboard, the invoice form and the live preview, the history table, the
 * client cards, the settings, the windows and the toasts. Light is the default; dark applies when <html> has no
 * data-theme. Every class and id the script touches keeps its name, and the variable names the script's markup and
 * the original rules use (--text-secondary, --bg-tertiary, --danger ...) are aliases of the site's tokens below.
 *
 * The invoice document itself (.invoice-preview and .invoice-template with its four templates) keeps the original's
 * fixed colours on purpose: it is the paper the PDF and PNG are made from and must look the same in both page themes.
 */

/* ----- Tokens the tool adds, and the aliases the original rules use ----- */
:root {
    --surface: #ffffff;                 /* cards are true white in the light theme */
    --surface-2: #f3f4f8;               /* a quiet inset inside a card */
    --ring: rgba(139, 92, 246, 0.18);
    --app-max: 1600px;
    --info: #0369a1;

    --bg-primary: var(--bg);
    --bg-secondary: var(--surface);
    --bg-tertiary: var(--surface-2);
    --text-muted: var(--text-3);
    --border-color: var(--surface-border);
    --border-focus: var(--brand);
    --accent-primary: var(--brand);
    --accent-secondary: var(--brand-2);
    --accent-gradient: var(--gradient-brand);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}
:root:not([data-theme="light"]) {
    --surface: #14141f;
    --surface-2: rgba(255, 255, 255, 0.05);
    --info: #38bdf8;
}

/* ----- Page: full width, the page provides the side space ----- */
.container.app-container {
    max-width: calc(var(--app-max) + 2 * var(--content-gutter));
    margin-top: 16px;
}
@media (min-width: 640px) { .container.app-container { margin-top: 24px; } }

/* ----- Tools back link above the header, as on every other tool: the bar scrolls away under the sticky header ----- */
body { padding-top: 0; }
.back-bar { height: 48px; display: flex; align-items: center; padding: 0 var(--zdu-gutter, 24px); }
body > header { position: sticky; top: 0; z-index: 50; }
header .site-nav { position: relative; top: auto; }
.theme-toggle { top: calc(90px + var(--bar-offset, 48px)); }
@media (max-width: 768px) { .theme-toggle { top: calc(75px + var(--bar-offset, 48px)); } }

/* ----- Hero: brand row, headline, tagline ----- */
.app-hero { margin: 0 0 2rem; text-align: center; }
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.25rem;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-strong);
}
.app-brand img { width: 44px; height: 44px; border-radius: 12px; display: block; }
.app-hero h1 { margin-bottom: 0.75rem; }
.app-tagline { color: var(--text-2); font-size: 1.125rem; line-height: 1.6; max-width: 46rem; margin: 0 auto; }

/* ----- Buttons: the site's pills, in the tool's sizes (.header-btn is the class the script writes) ----- */
.header-btn, .btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 9999px;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    padding: 12px 24px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4); color: #fff; text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text-strong); border: 1px solid var(--surface-border); padding: 11px 23px; }
.btn-secondary:hover { border-color: var(--brand); color: var(--link); transform: translateY(-2px); text-decoration: none; }
.btn-danger { background: var(--danger-strong); color: #fff; box-shadow: 0 4px 15px rgba(185, 28, 28, 0.25); }
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(185, 28, 28, 0.35); }
.btn-sm { font-size: 0.85rem; padding: 9px 16px; }
.btn-secondary.btn-sm { padding: 8px 15px; }
.header-btn svg { flex-shrink: 0; }
.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--text-strong);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.btn-icon:hover { border-color: var(--brand); color: var(--link); transform: translateY(-2px); }

/* ----- The app: section tabs and the toolbar ----- */
.app-shell { margin: 0 0 3rem; scroll-margin-top: 90px; }
.app-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 0 8px;
    margin: 0 0 12px;
    -webkit-overflow-scrolling: touch;
}
.app-tabs::-webkit-scrollbar { display: none; }
.nav-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: var(--chip);
    border: 1px solid var(--chip-border);
    color: var(--text-2);
    padding: 9px 16px;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { border-color: var(--brand); color: var(--link); }
.nav-item.active { background: var(--gradient-brand); color: #fff; border-color: transparent; }
.nav-badge {
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 9999px;
    background: var(--brand);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
}
.nav-item.active .nav-badge { background: #fff; color: #7c3aed; }
.app-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin: 0 0 1.25rem; }
.page-title { margin: 0; font-size: 1.5rem; }
.app-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.page-view { display: none; }
.page-view.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ----- Cards: one surface for every box the tool draws ----- */
.stat-card, .section-card, .form-panel, .preview-panel, .history-table-container, .client-card, .settings-section, .clients-grid > .empty-state {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--surface-shadow);
}

/* ----- Dashboard: four tiles that fill their row ----- */
.dashboard-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 20px; transition: transform 0.3s ease, box-shadow 0.3s ease; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--surface-hover-shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.stat-icon.blue { background: rgba(59, 130, 246, 0.12); color: #2563eb; }
.stat-icon.green { background: rgba(16, 185, 129, 0.12); color: #059669; }
.stat-icon.orange { background: rgba(245, 158, 11, 0.14); color: #d97706; }
.stat-icon.purple { background: rgba(139, 92, 246, 0.14); color: #7c3aed; }
.stat-value { font-family: 'Space Grotesk', 'Inter', sans-serif; font-size: 1.75rem; font-weight: 700; color: var(--text-strong); line-height: 1.15; margin-bottom: 4px; overflow-wrap: anywhere; }
.stat-label { font-size: 0.85rem; color: var(--text-3); }
.stat-sublabel { font-size: 0.75rem; color: var(--text-3); margin-top: 2px; }

.dashboard-sections { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.section-card { overflow: hidden; }
.section-header { padding: 16px 20px; border-bottom: 1px solid var(--surface-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { margin: 0; font-size: 1.05rem; font-weight: 700; }
.section-body { padding: 16px 20px; }
.section-body--flush { padding: 0; }
.muted { color: var(--text-3); margin: 0; }

/* Tables (the dashboard's recent invoices and the history) */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0; }
.invoice-table, .history-table { width: 100%; border-collapse: collapse; margin: 0; background: none; border-radius: 0; }
.invoice-table th, .history-table th {
    padding: 12px 20px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    background: var(--surface-2);
    border: 0;
    border-bottom: 1px solid var(--surface-border);
}
.invoice-table td, .history-table td { padding: 12px 20px; border: 0; border-bottom: 1px solid var(--surface-border); font-size: 0.925rem; color: var(--text); vertical-align: middle; }
.invoice-table tr:last-child td, .history-table tr:last-child td { border-bottom: none; }
.invoice-table tbody tr:hover td, .history-table tbody tr:hover td { background: var(--bg-hover, rgba(139, 92, 246, 0.06)); }
.invoice-number { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; color: var(--link); }
.empty-state--row { text-align: center; padding: 28px 20px !important; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.status-badge.draft { background: rgba(148, 163, 184, 0.2); color: #475569; }
.status-badge.sent { background: rgba(59, 130, 246, 0.15); color: #2563eb; }
.status-badge.paid { background: rgba(16, 185, 129, 0.15); color: #059669; }
.status-badge.overdue { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
:root:not([data-theme="light"]) .status-badge.draft { color: #cbd5e1; }
:root:not([data-theme="light"]) .status-badge.sent { color: #93c5fd; }
:root:not([data-theme="light"]) .status-badge.paid { color: #6ee7b7; }
:root:not([data-theme="light"]) .status-badge.overdue { color: #fca5a5; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Quick actions */
.quick-actions { display: flex; flex-direction: column; gap: 10px; }
.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--surface-border);
    color: var(--text-strong);
    cursor: pointer;
    font-size: 0.925rem;
    font-weight: 600;
    text-align: left;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
.quick-action-btn:hover { border-color: var(--brand); color: var(--link); transform: translateY(-2px); }
.quick-action-icon { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; background: var(--surface); border: 1px solid var(--surface-border); display: flex; align-items: center; justify-content: center; }

/* ----- New invoice: the form and the live preview ----- */
.create-invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.form-panel { overflow: hidden; }
.form-panel-header { padding: 16px 20px; border-bottom: 1px solid var(--surface-border); }
.form-panel-header h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.form-panel-body { padding: 20px; }
.form-section { margin-bottom: 1.75rem; }
.form-section:last-child { margin-bottom: 0; }
.form-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 1rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--surface-border);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}
.form-section-title svg { color: var(--link); }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-row--tight { margin: 8px 0; gap: 0 10px; }
.form-row--tight .form-group { margin-bottom: 0; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-strong); margin-bottom: 6px; }
.form-label--check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-label--check input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
.req { color: var(--danger); }
.form-input, .form-select, .form-textarea, .search-box input, .line-item input {
    width: 100%;
    padding: 10px 14px;
    background: var(--field);
    border: 1px solid var(--field-border);
    border-radius: 12px;
    font-size: 0.925rem;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-input::placeholder, .form-textarea::placeholder, .search-box input::placeholder, .line-item input::placeholder { color: var(--placeholder); }
.form-input:focus, .form-select:focus, .form-textarea:focus, .search-box input:focus, .line-item input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.form-textarea { resize: vertical; min-height: 76px; }
.form-select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b93a1' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}
.form-select option { color: #0a0a14; background: #fff; }
.form-input--compact, .form-select--compact { padding-top: 8px; padding-bottom: 8px; }
.form-input[type="date"] { color-scheme: light; }
:root:not([data-theme="light"]) .form-input[type="date"] { color-scheme: dark; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 1rem; border-top: 1px solid var(--surface-border); }
.form-actions .header-btn { flex: 1 1 auto; }

/* Line items */
.line-items-container { border: 1px solid var(--surface-border); border-radius: 12px; overflow: hidden; }
.line-items-header, .line-item { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 0.8fr) minmax(0, 1fr) minmax(0, 1fr) 36px; gap: 8px; padding: 10px 12px; align-items: center; }
.line-items-header { background: var(--surface-2); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.line-item { border-bottom: 1px solid var(--surface-border); }
.line-item:last-child { border-bottom: none; }
.line-item input { padding: 8px 10px; border-radius: 10px; font-size: 0.875rem; }
.line-item-amount { font-weight: 700; color: var(--text-strong); font-size: 0.9rem; overflow-wrap: anywhere; }
.remove-item-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(185, 28, 28, 0.3);
    background: rgba(185, 28, 28, 0.08);
    color: var(--danger);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}
.remove-item-btn:hover { background: var(--danger-strong); color: #fff; }
.add-item-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px;
    margin-top: 10px;
    border: 2px dashed rgba(139, 92, 246, 0.45);
    border-radius: 12px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.add-item-btn:hover { border-color: var(--brand); color: var(--link); background: var(--tint-brand); }

/* Totals */
.totals-section { background: var(--surface-2); border: 1px solid var(--surface-border); border-radius: 12px; padding: 12px 16px; margin-top: 14px; }
.totals-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 0.925rem; color: var(--text-2); }
.totals-row.total { font-family: 'Space Grotesk', 'Inter', sans-serif; font-size: 1.25rem; font-weight: 700; color: var(--text-strong); border-top: 2px solid var(--surface-border); padding-top: 10px; margin-top: 4px; }

/* Preview panel */
.preview-panel { overflow: hidden; display: flex; flex-direction: column; position: sticky; top: 100px; max-height: calc(100vh - 120px); }
.preview-header { padding: 12px 20px; border-bottom: 1px solid var(--surface-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.preview-header h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.preview-actions { display: flex; gap: 8px; }
.preview-container { flex: 1; overflow-y: auto; padding: 20px; background: var(--surface-2); display: flex; justify-content: center; align-items: flex-start; }

/* ===== The invoice document: fixed colours, the same in both page themes (this is the PDF) ===== */
.invoice-preview { width: 100%; max-width: 600px; background: #ffffff; border-radius: 10px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 10px 10px -5px rgba(0, 0, 0, 0.05); overflow: hidden; }
.invoice-template { --inv-accent: #3b82f6; padding: 2rem; color: #1e293b; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.5; }
.invoice-template h4 { font-family: inherit; }
.invoice-header { display: flex; justify-content: space-between; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 2px solid #e2e8f0; }
.invoice-brand { display: flex; align-items: center; gap: 1rem; }
.invoice-logo { width: 60px; height: 60px; border-radius: 12px; object-fit: contain; background: #f1f5f9; }
.invoice-logo-placeholder { width: 60px; height: 60px; border-radius: 12px; background: linear-gradient(135deg, var(--inv-accent) 0%, #8b5cf6 100%); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 1.5rem; }
.invoice-company-name { font-size: 1.5rem; font-weight: 700; color: #1e293b; }
.invoice-company-tagline { font-size: 0.875rem; color: #64748b; }
.invoice-title-section { text-align: right; }
.invoice-title { font-size: 2rem; font-weight: 700; color: var(--inv-accent); letter-spacing: 0.05em; }
.invoice-number-display { font-size: 1rem; color: #64748b; margin-top: 0.25rem; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 2rem; }
.party-section h4 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: #94a3b8; margin: 0 0 0.5rem; }
.party-name { font-size: 1.125rem; font-weight: 600; color: #1e293b; margin-bottom: 0.25rem; }
.party-details { font-size: 0.875rem; color: #64748b; line-height: 1.6; overflow-wrap: anywhere; }
.invoice-meta { display: flex; gap: 2rem; margin-bottom: 2rem; padding: 1rem 1.25rem; background: #f8fafc; border-radius: 8px; }
.meta-item { flex: 1; }
.meta-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #94a3b8; margin-bottom: 0.25rem; }
.meta-value { font-size: 0.9375rem; font-weight: 600; color: #1e293b; }
.invoice-items-table { width: 100%; border-collapse: collapse; margin: 0 0 1.5rem; background: none; border-radius: 0; }
.invoice-items-table th { padding: 0.75rem 1rem; text-align: left; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #fff; background: var(--inv-accent); border: 0; }
.invoice-items-table th:first-child { border-radius: 6px 0 0 6px; }
.invoice-items-table th:last-child { border-radius: 0 6px 6px 0; text-align: right; }
.invoice-items-table td { padding: 1rem; border: 0; border-bottom: 1px solid #e2e8f0; font-size: 0.9375rem; color: #1e293b; }
.invoice-items-table td:last-child { text-align: right; font-weight: 600; }
.invoice-items-table tr:last-child td { border-bottom: none; }
.invoice-totals { margin-left: auto; width: 280px; max-width: 100%; }
.invoice-totals-row { display: flex; justify-content: space-between; gap: 12px; padding: 0.5rem 0; font-size: 0.9375rem; color: #64748b; }
.invoice-totals-row.grand-total { font-size: 1.25rem; font-weight: 700; color: #1e293b; border-top: 2px solid #e2e8f0; padding-top: 0.75rem; margin-top: 0.5rem; }
.invoice-notes { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #e2e8f0; }
.invoice-notes h4 { font-size: 0.875rem; font-weight: 600; color: #1e293b; margin: 0 0 0.5rem; }
.invoice-notes p { font-size: 0.875rem; color: #64748b; line-height: 1.6; margin: 0 0 0.5rem; overflow-wrap: anywhere; }
.invoice-footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #e2e8f0; text-align: center; }
.invoice-footer p { font-size: 0.8125rem; color: #94a3b8; margin: 0; }
/* Corporate */
.invoice-template.corporate { background: #fafafa; }
.invoice-template.corporate .invoice-header { border-bottom-color: #1e293b; }
.invoice-template.corporate .invoice-title { color: #1e293b; }
.invoice-template.corporate .invoice-items-table th { background: #1e293b; }
/* Creative */
.invoice-template.creative { background: linear-gradient(135deg, #fef9ff 0%, #f0f9ff 100%); }
.invoice-template.creative .invoice-title { background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.invoice-template.creative .invoice-items-table th { background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%); }
.invoice-template.creative .invoice-meta { background: rgba(139, 92, 246, 0.1); }
/* Dark */
.invoice-template.dark { background: #1e293b; color: #f8fafc; }
.invoice-template.dark .invoice-header { border-bottom-color: #334155; }
.invoice-template.dark .invoice-company-name, .invoice-template.dark .party-name, .invoice-template.dark .meta-value, .invoice-template.dark .invoice-notes h4, .invoice-template.dark .invoice-items-table td { color: #f8fafc; }
.invoice-template.dark .invoice-company-tagline, .invoice-template.dark .party-details, .invoice-template.dark .invoice-number-display, .invoice-template.dark .invoice-notes p, .invoice-template.dark .invoice-footer p { color: #94a3b8; }
.invoice-template.dark .invoice-meta { background: #334155; }
.invoice-template.dark .invoice-items-table td { border-bottom-color: #334155; }
.invoice-template.dark .invoice-totals-row.grand-total { border-top-color: #334155; color: #f8fafc; }
.invoice-template.dark .invoice-notes, .invoice-template.dark .invoice-footer { border-top-color: #334155; }

/* ----- Invoice history ----- */
.history-filters { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 12px; margin-bottom: 16px; align-items: center; }
.search-box { position: relative; min-width: 0; }
.search-box input { padding-left: 40px; }
.search-box input::-webkit-search-cancel-button { cursor: pointer; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-label { font-size: 0.85rem; color: var(--text-2); white-space: nowrap; }
.filter-group .form-select, .filter-group .form-input { width: auto; }
.history-table-container { overflow: hidden; }
.history-table td strong { color: var(--text-strong); }
.invoice-actions { display: flex; gap: 6px; }
.action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.action-btn:hover { border-color: var(--brand); color: var(--link); }
.action-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

/* Empty states */
.empty-state { text-align: center; padding: 48px 20px; }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 16px; background: var(--surface-2); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.empty-title { margin: 0 0 6px; font-size: 1.2rem; }
.empty-description { color: var(--text-3); margin-bottom: 18px; }

/* ----- Clients ----- */
.clients-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.clients-header .search-box { flex: 1; max-width: 420px; }
.clients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.clients-grid > .empty-state { grid-column: 1 / -1; box-shadow: none; }
.client-card { padding: 20px; transition: transform 0.3s ease, box-shadow 0.3s ease; }
.client-card:hover { transform: translateY(-4px); box-shadow: var(--surface-hover-shadow); }
.client-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.client-avatar { width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; background: var(--gradient-brand); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 1.2rem; }
.client-info { min-width: 0; }
.client-info h3 { margin: 0 0 2px; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-info p { margin: 0; font-size: 0.85rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-details { font-size: 0.875rem; color: var(--text-2); line-height: 1.6; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--surface-border); overflow-wrap: anywhere; }
.client-stats { display: flex; gap: 24px; }
.client-stat { display: flex; flex-direction: column; min-width: 0; }
.client-stat-value { font-weight: 700; color: var(--text-strong); overflow-wrap: anywhere; }
.client-stat-label { color: var(--text-3); font-size: 0.75rem; }
.client-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--surface-border); }
.client-action-btn {
    flex: 1;
    padding: 7px 10px;
    border-radius: 9999px;
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--text-2);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: border-color 0.2s ease, color 0.2s ease;
}
.client-action-btn:hover { border-color: var(--brand); color: var(--link); }
.client-action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ----- Settings ----- */
.settings-container { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.settings-section { overflow: hidden; }
.settings-section-header { padding: 16px 20px; border-bottom: 1px solid var(--surface-border); }
.settings-section-title { margin: 0; font-size: 1.05rem; font-weight: 700; }
.settings-section-body { padding: 16px 20px; }
.settings-section-body > .form-group:last-child { margin-bottom: 0; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--surface-border); }
.settings-row:first-child { padding-top: 0; }
.settings-row:last-child { border-bottom: none; padding-bottom: 0; }
.settings-label { flex: 1; min-width: 0; }
.settings-label h4 { margin: 0 0 2px; font-size: 0.95rem; font-weight: 600; }
.settings-label p { margin: 0; font-size: 0.8rem; color: var(--text-3); line-height: 1.5; }
.settings-control { flex-shrink: 0; }
.settings-input { width: 220px; max-width: 100%; }
.settings-input--short { width: 140px; }
.logo-upload { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.logo-preview { width: 60px; height: 60px; border-radius: 12px; background: var(--surface-2); border: 2px dashed var(--surface-border); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--text-3); }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.upload-btn {
    padding: 8px 15px;
    border-radius: 9999px;
    border: 1px solid var(--surface-border);
    background: var(--surface);
    color: var(--text-strong);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: border-color 0.2s ease, color 0.2s ease;
}
.upload-btn:hover { border-color: var(--brand); color: var(--link); }
.color-picker-container { display: flex; align-items: center; gap: 10px; }
.color-picker { width: 42px; height: 42px; border: 1px solid var(--surface-border); border-radius: 10px; cursor: pointer; padding: 2px; background: var(--surface); }
.color-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; color: var(--text-2); }
.template-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.template-option {
    border: 2px solid var(--surface-border);
    border-radius: 12px;
    padding: 12px 8px;
    cursor: pointer;
    background: var(--surface);
    color: var(--text-2);
    text-align: center;
    transition: border-color 0.2s ease, background 0.2s ease;
}
.template-option:hover { border-color: var(--brand); }
.template-option.active { border-color: var(--brand); background: var(--tint-brand); color: var(--text-strong); }
.template-preview { width: 52px; height: 70px; margin: 0 auto 8px; border-radius: 4px; background: #f8fafc; border: 1px solid rgba(0, 0, 0, 0.1); }
.template-preview.minimal { background: linear-gradient(#3b82f6 14%, #f8fafc 14%); }
.template-preview.corporate { background: linear-gradient(#1e293b 30%, #f8fafc 30%); }
.template-preview.creative { background: linear-gradient(135deg, #fef9ff, #f0f9ff); }
.template-preview.dark { background: #1e293b; }
.template-name { font-size: 0.8rem; font-weight: 600; }
kbd {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    color: var(--text-2);
}

/* ----- Windows ----- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 20, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(12px);
    transition: transform 0.25s ease;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal--small { max-width: 420px; }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--surface-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-title { margin: 0; font-size: 1.15rem; }
.modal-close {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--chip-border);
    background: var(--chip);
    color: var(--text-strong);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, color 0.2s ease;
}
.modal-close:hover { border-color: var(--brand); color: var(--link); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-body p { margin: 0; color: var(--text-2); }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--surface-border); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

/* ----- Toasts ----- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px); }
.toast {
    background: #0a0a14;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 4px solid;
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    min-width: 260px;
    max-width: 400px;
    animation: slideIn 0.3s ease;
}
.toast.success { border-left-color: #4ade80; }
.toast.error { border-left-color: #f87171; }
.toast.warning { border-left-color: #fbbf24; }
.toast.info { border-left-color: #38bdf8; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-icon { width: 24px; height: 24px; flex-shrink: 0; }
.toast.success .toast-icon { color: #4ade80; }
.toast.error .toast-icon { color: #f87171; }
.toast.warning .toast-icon { color: #fbbf24; }
.toast.info .toast-icon { color: #38bdf8; }
.toast-content { flex: 1; min-width: 0; }
.toast-message { font-size: 0.875rem; font-weight: 500; overflow-wrap: anywhere; }

/* ----- Information sections below the tool ----- */
.info-section { margin: 0 0 2.5rem; }
.info-section h2 { font-size: 1.75rem; margin: 0 0 1.25rem; }
.info-section > p { max-width: 70ch; }
/* Three columns on desktops, two on tablets, one on phones: six cards fill two rows without a gap. */
.info-section .info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.info-three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 1rem 0 1.5rem; }
.info-stack { display: grid; gap: 12px; }
.info-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    box-shadow: var(--surface-shadow);
    padding: 20px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.info-card:hover { transform: translateY(-4px); box-shadow: var(--surface-hover-shadow); }
.info-card--small { padding: 16px; box-shadow: none; }
.info-card h3 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.info-card p { color: var(--text-2); margin-bottom: 0.75rem; }
.info-card p:last-child { margin-bottom: 0; }
.info-section article:not(.info-card) p { color: var(--text-2); max-width: 70ch; }
.step-card { position: relative; padding-top: 24px; }
.step-num {
    position: absolute;
    top: -16px;
    left: 20px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 0.75rem; }
.step-head h3 { margin: 0; }
.step-emoji { font-size: 1.6rem; line-height: 1; }
.info-section details.info-card { padding: 0; }
.info-section details.info-card summary {
    cursor: pointer;
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-strong);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.info-section details.info-card summary::-webkit-details-marker { display: none; }
.info-section details.info-card summary::after { content: '+'; color: var(--link); font-weight: 700; font-size: 1.2rem; line-height: 1; flex-shrink: 0; }
.info-section details.info-card[open] summary::after { content: '\2212'; }
.info-section details.info-card p { padding: 0 20px 16px; margin: 0; color: var(--text-2); }

/* ----- Tablets ----- */
@media (max-width: 1023px) {
    .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
    .dashboard-sections { grid-template-columns: 1fr; }
    .create-invoice-layout { grid-template-columns: 1fr; }
    .preview-panel { position: static; max-height: none; order: -1; }
    .preview-container { max-height: 520px; }
    .settings-container { grid-template-columns: 1fr; }
    .history-filters { grid-template-columns: 1fr 1fr; }
    .history-filters .search-box { grid-column: span 2; }
    .history-filters .filter-group:last-child { grid-column: span 2; }
    .filter-group .form-select, .filter-group .form-input { flex: 1; width: auto; }
    .info-section .info-grid, .info-three { grid-template-columns: repeat(2, 1fr); }
}

/* ----- Phones ----- */
@media (max-width: 639px) {
    .app-hero { margin-bottom: 1.5rem; }
    .app-tagline { font-size: 1rem; }
    .app-toolbar { gap: 10px; }
    .page-title { font-size: 1.25rem; }
    .app-actions { width: 100%; }
    .app-actions .header-btn { flex: 1 1 auto; padding-left: 12px; padding-right: 12px; }
    .dashboard-stats { gap: 12px; }
    .stat-card { padding: 14px; }
    .stat-icon { width: 38px; height: 38px; margin-bottom: 10px; }
    .stat-value { font-size: 1.35rem; }
    .section-header, .section-body, .form-panel-header, .form-panel-body, .preview-header, .settings-section-header, .settings-section-body, .client-card { padding-left: 16px; padding-right: 16px; }
    .invoice-table th, .invoice-table td, .history-table th, .history-table td { padding-left: 16px; padding-right: 16px; }
    .preview-container { padding: 12px; }
    .form-row { grid-template-columns: 1fr; }
    .form-row--tight { grid-template-columns: 1fr 1fr; }
    .line-items-header { display: none; }
    .line-item { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) 32px; grid-template-areas: "desc desc desc desc" "qty rate amount remove"; gap: 8px; }
    .line-item input:nth-child(1) { grid-area: desc; }
    .line-item input:nth-child(2) { grid-area: qty; }
    .line-item input:nth-child(3) { grid-area: rate; }
    .line-item .line-item-amount { grid-area: amount; text-align: right; }
    .line-item .remove-item-btn { grid-area: remove; }
    .form-actions .header-btn { flex: 1 1 100%; }
    .invoice-template { padding: 1.25rem; }
    .invoice-header { flex-direction: column; gap: 1rem; }
    .invoice-title-section { text-align: left; }
    .invoice-title { font-size: 1.5rem; }
    .invoice-parties { grid-template-columns: 1fr; gap: 1.25rem; }
    .invoice-meta { flex-wrap: wrap; gap: 1rem; }
    .meta-item { flex: 1 1 40%; }
    .invoice-items-table th, .invoice-items-table td { padding: 0.6rem 0.5rem; font-size: 0.85rem; }
    .invoice-totals { width: 100%; }
    .history-filters { grid-template-columns: 1fr; }
    .history-filters .search-box, .history-filters .filter-group:last-child { grid-column: auto; }
    .clients-header { flex-direction: column; align-items: stretch; }
    .clients-header .search-box { max-width: none; }
    .clients-grid { grid-template-columns: 1fr; }
    .settings-row { flex-wrap: wrap; }
    .settings-control { width: 100%; }
    .settings-input, .settings-input--short { width: 100%; }
    .template-selector { grid-template-columns: repeat(2, 1fr); }
    .modal-overlay { padding: 8px; }
    .modal-body, .modal-header, .modal-footer { padding-left: 16px; padding-right: 16px; }
    .toast-container { bottom: 16px; right: 16px; left: 16px; align-items: flex-end; }
    .toast { min-width: 0; }
    .info-section h2 { font-size: 1.4rem; }
    .info-section .info-grid, .info-three { grid-template-columns: 1fr; }
    .info-card { padding: 16px; }
    .step-num { left: 16px; }
}

/* ----- Print: only the invoice ----- */
@media print {
    .back-bar, body > header, body > footer, .theme-toggle, .app-hero, .app-tabs, .app-toolbar, .info-section, .form-panel, .preview-header, .toast-container, .modal-overlay, #zdu-cookie-banner, noscript { display: none !important; }
    body { padding: 0; background: #fff; }
    body::before { display: none; }
    .container.app-container { max-width: none; margin: 0; padding: 0; }
    .page-view { display: none !important; }
    #createView { display: block !important; }
    .create-invoice-layout { display: block; }
    .preview-panel { position: static; max-height: none; border: 0; box-shadow: none; }
    .preview-container { padding: 0; background: #fff; max-height: none; overflow: visible; }
    .invoice-preview { box-shadow: none; max-width: 100%; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .header-btn, .btn-primary, .btn-secondary, .btn-danger, .stat-card, .client-card, .info-card, .modal, .toast, .page-view.active { transition: none; animation: none; }
}

/* Phones: 16 px text, 44 px tap targets (AdSense audit H-04, 8 Oct 2026) */
@media (max-width: 639.98px) {
    main button, main select, main summary, main [role="button"],
    main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]) { min-height: 44px; }
    td.empty-state > p { font-size: 1rem; }
}
