:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(2, 6, 23, 0.08), 0 1px 2px rgba(2, 6, 23, 0.04);
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; }
.title { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.lead { margin: 0; color: var(--muted); font-size: 15px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: none;
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-logo {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    flex: none;
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }

.nav-context { border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.nav-context-label { padding: 0 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; }
.nav-group-label { padding: 12px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #64748b; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.page-title { margin: 0; font-size: 18px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-meta { text-align: end; }
.user-name { display: block; font-weight: 600; font-size: 14px; }
.user-email { display: block; font-size: 12px; color: var(--muted); }

.sidebar-toggle {
    display: none;
    position: fixed;
    inset-inline-start: 12px;
    top: 12px;
    z-index: 40;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text);
}

.sidebar-backdrop { display: none; }

.container { padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; flex: 1; }

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        height: 100vh;
        z-index: 30;
        transform: translateX(100%);
        transition: transform 0.2s ease;
        width: min(300px, 85vw);
        box-shadow: 0 0 40px rgba(2, 6, 23, 0.4);
    }
    [dir="ltr"] .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0) !important; }
    .sidebar-backdrop.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 23, 0.5);
        z-index: 25;
    }
    .sidebar-toggle { display: flex; }
    .topbar { padding-inline-start: 64px; }
    .user-email { display: none; }
    .container { padding: 16px; }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { border-color: #cbd5e1; color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* Alerts */
.alert {
    border-radius: 10px;
    padding: 12px 16px;
    margin: 0 0 16px;
    font-size: 14px;
    border: 1px solid;
}
.alert-list { margin: 6px 0 0; padding-inline-start: 18px; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: #15803d; }
.alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-muted { background: #e2e8f0; color: #475569; }
.badge-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

/* Page header + search */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form { display: inline-flex; }

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.search-bar input[type="search"] {
    flex: 1;
    min-width: 0;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}
.card-title { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
.form-card { max-width: 860px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* Company grid */
.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}
.company-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    color: var(--text);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.company-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(2, 6, 23, 0.12); border-color: var(--primary); text-decoration: none; }

.company-card-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.company-card-name { margin: 0; font-size: 16px; font-weight: 700; }

.company-logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 22px;
    overflow: hidden;
    flex: none;
}
.company-logo img { width: 100%; height: 100%; object-fit: contain; }
.company-logo-lg { width: 84px; height: 84px; font-size: 32px; }

.company-card-body { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.company-card-line { display: flex; justify-content: space-between; gap: 12px; }
.company-card-line-label { color: var(--muted); }

.company-card-stats {
    display: flex;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
}
.stat { display: inline-flex; gap: 4px; align-items: baseline; }
.stat strong { color: var(--text); font-size: 15px; }

/* Company hero + stats */
.company-hero {
    display: flex;
    gap: 20px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.company-hero-info { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-card strong { font-size: 26px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card-money strong { font-size: 20px; font-variant-numeric: tabular-nums; }

/* Bar chart */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 200px;
    padding-top: 12px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 8px; height: 100%; min-width: 0; }
.bar-track {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: #f1f5f9;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.bar {
    width: 100%;
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    border-radius: 6px 6px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}
.bar-label {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.empty-note { margin: 0; color: var(--muted); }

/* Status list */
.status-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.status-row strong { font-variant-numeric: tabular-nums; }

.badge-status { background: #e2e8f0; color: #475569; }
.badge-status.status-draft { background: #f8fafc; color: #64748b; border: 1px solid var(--border); }
.badge-status.status-issued { background: var(--primary-soft); color: var(--primary); }
.badge-status.status-paid { background: var(--success-bg); color: #15803d; border-color: var(--success-border); }
.badge-status.status-overdue { background: #fef2f2; color: var(--danger); border-color: var(--danger-border); }
.badge-status.status-cancelled { background: #f1f5f9; color: #94a3b8; }
.badge-status.status-below-min { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }

/* Inline add (categories) */
.inline-add { display: flex; gap: 10px; }
.inline-add input[type="text"] { flex: 1; min-width: 0; }

.muted { color: var(--muted); }

/* Details list */
.details { margin: 0; }
.details-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.details-row:last-child { border-bottom: 0; }
.details-row dt { color: var(--muted); font-weight: 600; flex: none; }
.details-row dd { margin: 0; text-align: end; word-break: break-word; }

/* Tables */
.row-link { font-weight: 600; }

/* Pagination */
.pagination-wrap { display: flex; justify-content: center; margin-top: 24px; }
.pagination { display: flex; list-style: none; gap: 6px; padding: 0; margin: 0; flex-wrap: wrap; }
.pagination li a, .pagination li span {
    display: grid;
    place-items: center;
    min-width: 38px;
    height: 38px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}
.pagination li a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pagination li.active a { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination li.disabled a, .pagination li.disabled span { opacity: 0.45; pointer-events: none; }

/* Forms */
.field { margin-bottom: 16px; flex: 1; min-width: 0; }
.row { display: flex; gap: 16px; }
.row-4 > .field { flex: 1; }
@media (max-width: 860px) { .row, .row-4 { flex-direction: column; gap: 0; } }

label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="search"], input[type="tel"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
input[type="file"] { padding: 8px; }

.password-wrap { position: relative; }
.password-wrap input { padding-inline-end: 42px; }
.password-toggle {
    position: absolute;
    inset-inline-end: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 4px;
    color: var(--muted);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.password-toggle svg { display: block; }
.password-toggle svg[hidden] { display: none; }

.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 16px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; }
.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .switch-track { position: absolute; inset: 0; border-radius: 9999px; background: #cbd5e1; transition: background 0.15s ease; }
.switch .switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 9999px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); transition: transform 0.15s ease; }
.switch input:checked + .switch-track { background: #2563eb; }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid #2563eb; outline-offset: 2px; }
.switch-label { display: flex; flex-direction: column; gap: 2px; }
.switch-state { font-size: 0.85em; color: #64748b; font-weight: 500; }

.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0 !important; }
.section-title { margin: 24px 0 14px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 15px; font-weight: 700; }
.section-title:first-of-type { border-top: 0; padding-top: 0; margin-top: 4px; }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.logo-preview { margin-bottom: 8px; }
.logo-preview img {
    width: 96px;
    height: 96px;
    object-fit: contain;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: #f8fafc;
    padding: 8px;
}

.notes-text { white-space: pre-wrap; color: #334155; }

/* Auth */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(900px 500px at 80% -10%, rgba(37, 99, 235, 0.18), transparent),
        radial-gradient(700px 400px at 0% 110%, rgba(37, 99, 235, 0.14), transparent),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}
.auth-head { text-align: center; margin-bottom: 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.auth-title { margin: 0; font-size: 20px; font-weight: 700; }
.auth-subtitle { margin: 0; color: var(--muted); font-size: 14px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.empty-state p { margin: 0; }

/* Error page */
.error-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    padding: 24px;
}
.error-code { font-size: 72px; font-weight: 800; color: var(--primary); line-height: 1; }
.error-actions { margin-top: 12px; }

/* Invoice builder */
.invoice-form { max-width: 1080px; }
.invoice-lines { min-width: 720px; }
.invoice-lines .th-product { min-width: 190px; }
.invoice-lines .th-qty { min-width: 90px; }
.invoice-lines .th-price { min-width: 120px; }
.invoice-lines input { padding: 8px 10px; font-size: 13px; }
.invoice-lines select { padding: 8px 10px; font-size: 13px; }
.invoice-lines .line-total { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invoice-lines .th-actions { text-align: end; }
.invoice-line-actions { margin-top: 14px; }
.hint.error { color: var(--danger); }

.details-total {
    border-bottom: 0;
    font-size: 16px;
    font-weight: 700;
}
.details-total dd { font-weight: 700; }

.amount-letters {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 18px;
    padding: 14px 16px;
    background: var(--primary-soft);
    border: 1px solid #dbeafe;
    border-radius: 10px;
    font-size: 14px;
}
.amount-letters-label { font-size: 12px; font-weight: 600; color: var(--primary); }
.amount-letters-text { color: #1e3a8a; line-height: 1.5; }

/* Invoice document (show) */
.invoice-doc { display: flex; flex-direction: column; gap: 26px; }
.invoice-doc-identity { display: flex; justify-content: space-between; gap: 32px; flex-wrap: wrap; }
.invoice-doc-company { max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.invoice-doc-logo { width: 96px; height: 96px; object-fit: contain; border: 1px solid var(--border); border-radius: 12px; padding: 6px; background: #fff; }
.invoice-doc-company-name { margin: 0; font-size: 18px; font-weight: 800; }
.invoice-doc-lines { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.invoice-doc-lines > div { display: flex; gap: 8px; }
.invoice-doc-lines dt { color: var(--muted); font-weight: 600; flex: none; min-width: 64px; }
.invoice-doc-lines dd { margin: 0; word-break: break-word; }
.invoice-doc-company-contact, .invoice-doc-client-contact { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); }

.invoice-doc-meta { text-align: end; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; min-width: 260px; }
.invoice-doc-meta-title { margin: 0; font-size: 20px; font-weight: 800; }
.invoice-doc-meta .invoice-doc-lines { text-align: start; width: 100%; }
.invoice-doc-meta .invoice-doc-lines dt { min-width: 96px; }

.invoice-doc-client {
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    max-width: 420px;
}
.invoice-doc-client-title { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.invoice-doc-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.invoice-doc-totals-inner { width: 100%; max-width: 380px; }

.invoice-doc-notes { padding: 14px 16px; border: 1px dashed var(--border); border-radius: 10px; }
.invoice-doc-notes h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.invoice-doc-notes p { margin: 0; }

.invoice-doc-footer {
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

@media (max-width: 720px) {
    .invoice-doc-meta { text-align: start; align-items: flex-start; }
    .invoice-doc-totals { align-items: stretch; }
    .invoice-doc-totals-inner { max-width: none; }
}

/* Invoice list (index) */
.invoice-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}
.invoice-filters input[type="search"],
.invoice-filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
}
.invoice-filters input[type="search"] { flex: 1 1 220px; min-width: 180px; }
.invoice-filters select { flex: 0 1 auto; }
.invoice-filters-dates { display: flex; gap: 10px; }
.invoice-filters .btn { flex: 0 0 auto; }

.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--primary); text-decoration: none; }

.th-price { text-align: end !important; white-space: nowrap; }
.th-actions { white-space: nowrap; }
.invoice-row-client { font-weight: 600; }
.invoice-row-address { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.invoice-summary { max-width: 640px; }
.invoice-summary-grid { margin: 0; }

/* Invoice selection */
.th-checkbox { width: 40px; text-align: center !important; }
.th-checkbox input,
.td-checkbox input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
.td-checkbox {
    width: 40px;
    text-align: center;
    vertical-align: middle;
}

.invoice-table tbody tr:has(input.invoice-checkbox:checked) {
    background: var(--primary-soft);
}
.invoice-table tbody tr:has(input.invoice-checkbox:checked):hover {
    background: #dbeafe;
}

/* Selection toolbar */
.invoice-selection-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: #1e3a5f;
    color: #fff;
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}
.toolbar-count {
    font-weight: 700;
    font-size: 14px;
}
.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.invoice-selection-toolbar .btn-primary {
    background: #fff;
    color: #1e3a5f;
}
.invoice-selection-toolbar .btn-primary:hover {
    background: #e2e8f0;
}
.invoice-selection-toolbar .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.invoice-selection-toolbar .btn-ghost {
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    border-color: rgba(255, 255, 255, 0.3);
}
.invoice-selection-toolbar .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Sticky table header */
.table-card { padding: 0; overflow: hidden; }
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: start; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th {
    background: #f8fafc;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 900px) {
    .table-responsive { -webkit-overflow-scrolling: touch; }
    .table thead th { position: sticky; top: 0; z-index: 10; }
    .invoice-row-address { max-width: 180px; }
    .cell-actions { flex-wrap: nowrap; overflow-x: auto; }
    .invoice-selection-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .invoice-filters {
        flex-direction: column;
        align-items: stretch;
    }
    .invoice-filters input[type="search"] {
        flex: 1 1 auto;
        min-width: 0;
    }
    .invoice-filters-dates {
        flex-direction: column;
        gap: 8px;
    }
}

/* ============================================================
   Invoice templates (Professional / Modern / Classic)
   ============================================================ */

.invoice-sheet {
    background: #fff;
    color: #111827;
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 40px;
    max-width: 820px;
    margin: 0 auto;
    font-size: 13px;
    line-height: 1.5;
}
@media (max-width: 720px) {
    .invoice-sheet { padding: 18px 14px; }
}

.tpl { position: relative; }

/* Shared building blocks (styled per-template below) */
.tpl-fiscal, .tpl-meta { margin: 0; }
.tpl-fiscal div, .tpl-meta div { display: flex; gap: 6px; padding: 2px 0; }
.tpl-fiscal dt, .tpl-meta dt { color: var(--muted); font-weight: 600; flex: none; min-width: 44px; }
.tpl-fiscal dd, .tpl-meta dd { margin: 0; word-break: break-word; }
.tpl-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.tpl-muted { color: var(--muted); font-weight: 400; }
.tpl-field-label { display: block; margin-bottom: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tpl-notes { margin-top: 18px; padding-top: 10px; border-top: 1px solid #e5e7eb; }
.tpl-notes h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.tpl-notes p { margin: 0; white-space: pre-wrap; }

.tpl-cancelled-stamp {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-18deg);
    z-index: 5;
    font-size: 44px;
    font-weight: 800;
    letter-spacing: 0.15em;
    color: #dc2626;
    border: 5px solid #dc2626;
    border-radius: 12px;
    padding: 6px 26px;
    opacity: 0.35;
    pointer-events: none;
}

/* Items table (shared, per-template colors override below) */
.tpl-items { width: 100%; border-collapse: collapse; margin-top: 22px; font-size: 13px; }
.tpl-items th, .tpl-items td { padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: start; vertical-align: top; }
.tpl-items thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.tpl-col-no { width: 40px; text-align: center; }
.tpl-col-qty { width: 80px; text-align: center; white-space: nowrap; }
.tpl-col-price { text-align: end !important; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Totals (shared structure, per-template styling below) */
.tpl-totals { margin-top: 18px; }
.tpl-totals-list { margin: 0; margin-left: auto; width: 300px; max-width: 100%; }
.tpl-totals-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed #e5e7eb; }
.tpl-totals-row dt { color: var(--muted); font-weight: 600; }
.tpl-totals-row dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tpl-totals-total { border-bottom: 0; padding-top: 10px; font-size: 16px; font-weight: 800; }
.tpl-totals-total dt { color: #111827; }

.tpl-letters { margin-top: 18px; padding: 12px 14px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px; }
.tpl-letters-label { display: block; margin-bottom: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tpl-letters-text { line-height: 1.55; }

/* ---- Template: Professional ---- */
.tpl-professional .tpl-pro-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.tpl-professional .tpl-pro-logo { max-height: 64px; max-width: 160px; object-fit: contain; margin-bottom: 10px; }
.tpl-professional .tpl-pro-company-name { margin: 0 0 2px; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.tpl-professional .tpl-pro-activity { color: var(--muted); margin-bottom: 8px; }
.tpl-professional .tpl-pro-address { color: var(--muted); margin-top: 8px; }
.tpl-professional .tpl-pro-meta { flex: none; min-width: 230px; background: #1e3a5f; color: #fff; border-radius: 10px; padding: 14px 18px; text-align: end; }
.tpl-professional .tpl-pro-doctitle { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.tpl-status { display: inline-block; margin-bottom: 8px; padding: 2px 10px; border: 1px solid rgba(255, 255, 255, 0.55); border-radius: 999px; font-size: 11px; }
.tpl-professional .tpl-pro-meta .tpl-meta div { flex-direction: column; align-items: flex-end; gap: 0; padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.18); }
.tpl-professional .tpl-pro-meta .tpl-meta div:last-child { border-bottom: 0; }
.tpl-professional .tpl-pro-meta .tpl-meta dt { color: rgba(255, 255, 255, 0.75); min-width: 0; }
.tpl-professional .tpl-pro-meta .tpl-meta dd { text-align: end; }
.tpl-professional .tpl-pro-client { margin-top: 22px; padding: 14px 16px; border: 1px solid #e5e7eb; border-left: 4px solid #1e3a5f; border-radius: 8px; }
.tpl-professional .tpl-pro-client-name { display: block; margin-bottom: 4px; font-size: 15px; }
.tpl-professional .tpl-pro-client-address { color: var(--muted); margin-top: 4px; }
.tpl-professional .tpl-items thead th { background: #1e3a5f; color: #fff; }
.tpl-professional .tpl-items tbody tr:nth-child(even) td { background: #f8fafc; }

/* ---- Template: Modern ---- */
.tpl-modern { --accent: #4f46e5; }
.tpl-modern .tpl-mod-band { display: flex; justify-content: space-between; align-items: center; gap: 16px; background: var(--accent); color: #fff; border-radius: 12px; padding: 20px 24px; }
.tpl-modern .tpl-mod-band-company { display: flex; align-items: center; gap: 14px; }
.tpl-modern .tpl-mod-logo { max-height: 54px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 8px; padding: 4px; }
.tpl-modern .tpl-mod-company-name { margin: 0; font-size: 19px; font-weight: 800; }
.tpl-modern .tpl-mod-activity { font-size: 12px; opacity: 0.85; }
.tpl-modern .tpl-mod-doctitle { margin: 0; font-size: 22px; font-weight: 800; text-align: end; }
.tpl-modern .tpl-mod-status { display: inline-block; margin-top: 4px; padding: 2px 10px; border: 1px solid rgba(255, 255, 255, 0.6); border-radius: 999px; font-size: 11px; }
.tpl-modern .tpl-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 0; }
.tpl-modern .tpl-chip { background: #eef2ff; border: 1px solid #e0e7ff; border-radius: 10px; padding: 6px 12px; }
.tpl-modern .tpl-chip dt { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #6366f1; }
.tpl-modern .tpl-chip dd { margin: 0; font-size: 12px; font-weight: 600; }
.tpl-modern .tpl-mod-address { margin-top: 10px; color: var(--muted); }
.tpl-modern .tpl-mod-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.tpl-modern .tpl-mod-card { background: #fafaff; border: 1px solid #e0e7ff; border-radius: 12px; padding: 14px 16px; }
.tpl-modern .tpl-mod-client-name { display: block; margin-bottom: 6px; font-size: 15px; }
.tpl-modern .tpl-mod-client-address { color: var(--muted); margin-top: 4px; }
.tpl-modern .tpl-meta div { padding: 5px 0; border-bottom: 1px dashed #e0e7ff; }
.tpl-modern .tpl-meta div:last-child { border-bottom: 0; }
.tpl-modern .tpl-items thead th { background: var(--accent); color: #fff; }
.tpl-modern .tpl-items tbody tr:nth-child(even) td { background: #f5f6ff; }
.tpl-modern .tpl-totals-list { width: 100%; background: #eef2ff; border-radius: 12px; padding: 12px 16px; }
.tpl-modern .tpl-totals-row { border-bottom-color: #e0e7ff; }
.tpl-modern .tpl-totals-total { border-top: 2px solid var(--accent); }
.tpl-modern .tpl-letters { background: #eef2ff; border-color: #e0e7ff; }

/* ---- Template: Classic ---- */
.tpl-classic .tpl-cla-head { margin-bottom: 20px; padding-bottom: 14px; border-bottom: 3px double #111827; text-align: center; }
.tpl-classic .tpl-cla-logo { max-height: 70px; max-width: 170px; object-fit: contain; margin-bottom: 8px; }
.tpl-classic .tpl-cla-company-name { margin: 0 0 2px; font-family: Georgia, 'Times New Roman', serif; font-size: 24px; font-weight: 700; }
.tpl-classic .tpl-cla-activity { color: var(--muted); }
.tpl-classic .tpl-cla-fiscal { justify-content: center; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; }
.tpl-classic .tpl-cla-fiscal div { display: inline-flex; gap: 6px; }
.tpl-classic .tpl-cla-address { color: var(--muted); margin-top: 6px; }
.tpl-classic .tpl-cla-doctitle { margin: 14px 0 0; font-family: Georgia, 'Times New Roman', serif; font-size: 22px; letter-spacing: 0.2em; text-transform: uppercase; }
.tpl-classic .tpl-cla-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.tpl-classic .tpl-cla-client-name { display: block; font-size: 15px; }
.tpl-classic .tpl-cla-client-address { color: var(--muted); margin-top: 4px; }
.tpl-classic .tpl-cla-box { min-width: 230px; border: 1px solid #111827; padding: 12px 16px; }
.tpl-classic .tpl-cla-box div { padding: 4px 0; }
.tpl-classic .tpl-items thead th { border-bottom: 2px solid #111827; text-transform: uppercase; }
.tpl-classic .tpl-items td { border-bottom: 1px solid #111827; }
.tpl-classic .tpl-items tbody tr:last-child td { border-bottom: 0; }
.tpl-classic .tpl-totals-list { width: 100%; border: 1px solid #111827; padding: 10px 14px; }
.tpl-classic .tpl-totals-row { border-bottom-color: #111827; }
.tpl-classic .tpl-totals-total { border-top: 2px solid #111827; }
.tpl-classic .tpl-letters { background: #fff; border: 1px solid #111827; border-radius: 0; font-style: italic; text-align: center; }

/* Custom (per-company) template - layout driven by CSS variables + toggles */
[hidden] { display: none !important; }
.tpl-custom { font-size: var(--tpl-font-size, 13px); }
.tpl-custom-landscape .tpl-items thead th { white-space: nowrap; }

.tpl-cus-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.tpl-cus-company { min-width: 0; }
.tpl-cus-logo-wrap { margin-bottom: 10px; text-align: var(--tpl-logo-align, left); }
.tpl-cus-logo { max-height: var(--tpl-logo-max-h, 64px); max-width: 180px; object-fit: contain; }
.tpl-cus-logo-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    height: var(--tpl-logo-max-h, 64px);
    padding: 0 16px;
    background: #eef2f7;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #94a3b8;
}
.tpl-cus-name {
    margin: 0 0 2px;
    font-size: var(--tpl-name-size, 20px);
    font-weight: var(--tpl-name-weight, bold);
    text-align: var(--tpl-name-align, left);
}
.tpl-cus-activity { color: var(--muted); margin-bottom: 8px; }
.tpl-cus-fiscal { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.tpl-cus-fiscal div { display: inline-flex; gap: 6px; }
.tpl-cus-address { color: var(--muted); margin-top: 6px; }

.tpl-cus-doc { flex: none; min-width: 240px; padding-left: 16px; text-align: var(--tpl-title-align, right); }
.tpl-cus-title {
    margin: 0 0 6px;
    font-size: var(--tpl-title-size, 22px);
    font-weight: var(--tpl-title-weight, bold);
    color: var(--tpl-title-color, #111827);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.tpl-cus-status {
    display: inline-block;
    margin-bottom: 8px;
    padding: 2px 10px;
    border: 1px solid var(--tpl-accent, #1e3a5f);
    border-radius: 999px;
    font-size: 11px;
    color: var(--tpl-accent, #1e3a5f);
}
.tpl-cus-meta div { justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--tpl-border, #e5e7eb); }
.tpl-cus-meta div:last-child { border-bottom: 0; }
.tpl-cus-meta dt { min-width: 0; }

.tpl-cus-client { margin-top: 22px; padding: 14px 16px; border: 1px solid var(--tpl-border, #e5e7eb); border-left: 4px solid var(--tpl-accent, #1e3a5f); border-radius: 8px; }
.tpl-cus-client-name { display: block; margin-bottom: 4px; font-size: 15px; }
.tpl-cus-client-address { color: var(--muted); margin-top: 4px; }

.tpl-cus-items thead th { background: var(--tpl-head-bg, #1e3a5f); color: var(--tpl-head-color, #fff); }
.tpl-cus-items th, .tpl-cus-items td { border-bottom: 1px solid var(--tpl-border, #e5e7eb); }
.tpl-cus-striped .tpl-cus-items tbody tr:nth-child(even) td { background: #f8fafc; }
.tpl-cus-no-border .tpl-cus-items th, .tpl-cus-no-border .tpl-cus-items td { border-bottom: 0; }
.tpl-col-unit { text-align: center; white-space: nowrap; }

.tpl-cus-header { margin-bottom: 22px; padding-bottom: 10px; border-bottom: 2px solid var(--tpl-border, #e5e7eb); white-space: pre-wrap; font-size: 12px; color: var(--muted); }
.tpl-cus-footer { margin-top: 22px; padding-top: 10px; border-top: 2px solid var(--tpl-border, #e5e7eb); white-space: pre-wrap; font-size: 12px; color: var(--muted); }

/* Template editor */
.tpl-editor { display: grid; grid-template-columns: minmax(360px, 1fr) 1.15fr; gap: 24px; align-items: start; }
@media (max-width: 1020px) { .tpl-editor { grid-template-columns: 1fr; } }
.tpl-editor-form { min-width: 0; }
.tpl-editor-preview { position: sticky; top: 20px; }
@media (max-width: 1020px) { .tpl-editor-preview { position: static; } }
.tpl-editor-preview .invoice-sheet { max-width: 100%; padding: 26px; }
.tpl-editor-preview .invoice-sheet:has(.tpl-custom-landscape) { max-width: 1120px; }
.tpl-preview-label { margin: 0 0 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.tpl-group-title { margin: 22px 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.tpl-group-title:first-child { margin-top: 0; }
.tpl-toggle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 14px; }
.tpl-toggle-item { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; cursor: pointer; color: #334155; }
.tpl-toggle-item input { width: 15px; height: 15px; flex: none; }
.tpl-toggle-item .hint { display: block; }
.tpl-style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tpl-style-grid .field { margin-bottom: 0; }
.tpl-color-grid { display: flex; flex-wrap: wrap; gap: 14px; }
.tpl-color-item { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #334155; }
.tpl-color-item input[type="color"] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
.tpl-badge-default { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; font-size: 12px; font-weight: 700; }
.tpl-index-hint { margin: -6px 0 18px; font-size: 13px; color: var(--muted); max-width: 720px; }
.tpl-swatch { display: inline-block; width: 18px; height: 18px; border-radius: 6px; border: 1px solid var(--border); vertical-align: middle; }
.tpl-layout-group { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tpl-layout-group[open] { border-color: #d1d5db; }
.tpl-layout-summary { padding: 10px 14px; font-size: 13px; font-weight: 600; color: #334155; cursor: pointer; background: #f9fafb; list-style: none; display: flex; align-items: center; gap: 8px; user-select: none; }
.tpl-layout-summary::-webkit-details-marker { display: none; }
.tpl-layout-summary::before { content: '▶'; font-size: 10px; color: #9ca3af; transition: transform 0.15s; }
.tpl-layout-group[open] > .tpl-layout-summary::before { transform: rotate(90deg); }
.tpl-layout-group .tpl-style-grid { padding: 10px 14px 14px; margin-top: 0; }

/* ---- Layout Options CSS ---- */
/* Header styles */
.tpl-cus-header-centered .tpl-cus-head { flex-direction: column; align-items: center; text-align: center; }
.tpl-cus-header-centered .tpl-cus-company, .tpl-cus-header-centered .tpl-cus-doc { align-items: center; }
.tpl-cus-header-split .tpl-cus-head { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tpl-cus-header-full-band .tpl-cus-head { flex-direction: column; background: var(--tpl-accent, #1e3a5f); color: #fff; padding: 16px; border-radius: 6px; }
.tpl-cus-header-full-band .tpl-cus-head .tpl-cus-title { color: #fff; }
.tpl-cus-header-full-band .tpl-cus-head .tpl-cus-meta dt { color: rgba(255,255,255,0.7); }

/* Client styles */
.tpl-cus-client-inline .tpl-cus-client { background: none; border: none; padding: 0; margin-bottom: 16px; }
.tpl-cus-client-sidebar .tpl-cus-client { float: right; width: 45%; margin-left: 16px; margin-bottom: 16px; }
.tpl-cus-client-minimal .tpl-cus-client { background: none; border: none; padding: 0; box-shadow: none; margin-bottom: 16px; }

/* Table styles */
.tpl-cus-table-compact .tpl-cus-items th, .tpl-cus-table-compact .tpl-cus-items td { padding: 5px 8px; font-size: 11px; }
.tpl-cus-table-bordered .tpl-cus-items th, .tpl-cus-table-bordered .tpl-cus-items td { border: 1px solid var(--tpl-border, #e5e7eb); }
.tpl-cus-table-minimal .tpl-cus-items { border: none; }
.tpl-cus-table-minimal .tpl-cus-items th { background: transparent; color: #334155; border-bottom: 2px solid #334155; }
.tpl-cus-table-minimal .tpl-cus-items td { border: none; border-bottom: 1px solid #f3f4f6; }

/* Totals position */
.tpl-cus-totals-center .tpl-totals { text-align: center; }
.tpl-cus-totals-center .tpl-totals-list { margin-left: auto; margin-right: auto; }
.tpl-cus-totals-left .tpl-totals { text-align: left; }
.tpl-cus-totals-left .tpl-totals-list { margin-left: 0; margin-right: auto; }
.tpl-cus-totals-full-width .tpl-totals { width: 100%; }
.tpl-cus-totals-full-width .tpl-totals-list { width: 100%; }

/* Amount in letters styles */
.tpl-cus-letters-boxed .tpl-letters { border: 1px solid var(--tpl-accent, #1e3a5f); padding: 8px 12px; border-radius: 6px; background: #f9fafb; }
.tpl-cus-letters-highlighted .tpl-letters { background: var(--tpl-accent, #1e3a5f); color: #fff; padding: 8px 12px; border-radius: 6px; }
.tpl-cus-letters-highlighted .tpl-letters .tpl-letters-label { color: rgba(255,255,255,0.8); }
.tpl-cus-letters-highlighted .tpl-letters .tpl-letters-text { color: #fff; }

/* Signature */
.tpl-cus-signature { margin-top: 24px; min-height: 50px; }
.tpl-cus-sig-right { text-align: right; }
.tpl-cus-sig-center { text-align: center; }
.tpl-cus-sig-left { text-align: left; }
.tpl-cus-sig-line { border-top: 1px solid #9ca3af; width: 180px; margin-bottom: 6px; }
.tpl-cus-sig-right .tpl-cus-sig-line { margin-left: auto; }
.tpl-cus-sig-center .tpl-cus-sig-line { margin-left: auto; margin-right: auto; }
.tpl-cus-sig-label { font-size: 11px; color: #9ca3af; }

/* Invoice number position */
.tpl-cus-invnum-box { display: inline-block; background: var(--tpl-accent, #1e3a5f); color: #fff; padding: 6px 14px; border-radius: 6px; margin-bottom: 10px; }
.tpl-cus-invnum-box .tpl-cus-invnum-label { font-size: 11px; opacity: 0.8; margin-right: 6px; }
.tpl-cus-invnum-box .tpl-cus-invnum-value { font-weight: 700; font-size: 14px; }

/* Row number styles */
.tpl-cus-rnum-colored .tpl-rnum { color: var(--tpl-accent, #1e3a5f); font-weight: 700; }
.tpl-cus-rnum-circled .tpl-rnum { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: var(--tpl-accent, #1e3a5f); color: #fff; font-size: 11px; font-weight: 700; padding: 0; text-align: center; }

/* Watermark */
.tpl-cus-watermark { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-30deg); font-size: 64px; font-weight: 900; color: rgba(0,0,0,0.03); pointer-events: none; white-space: nowrap; z-index: 0; }
.tpl-cus-wm-pattern { background: repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(0,0,0,0.015) 35px, rgba(0,0,0,0.015) 70px); top: 0; left: 0; right: 0; bottom: 0; transform: none; width: 100%; height: 100%; }

/* Section dividers */
.tpl-cus-div-lines .tpl-cus-head, .tpl-cus-div-lines .tpl-cus-client, .tpl-cus-div-lines .tpl-totals { border-bottom: 1px solid var(--tpl-border, #e5e7eb); padding-bottom: 12px; margin-bottom: 12px; }
.tpl-cus-div-decorative .tpl-cus-head { border-bottom: 2px solid var(--tpl-accent, #1e3a5f); padding-bottom: 12px; margin-bottom: 12px; }
.tpl-cus-div-decorative .tpl-cus-client { border-bottom: 1px dashed var(--tpl-accent, #1e3a5f); padding-bottom: 12px; margin-bottom: 12px; }

/* Two-column info */
.tpl-cus-two-col .tpl-cus-two-col-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.tpl-cus-two-col .tpl-cus-two-col-wrap .tpl-cus-client { margin-bottom: 0; }

/* Merged header */
.tpl-cus-head-merged { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: start; }

/* ---- ETAT TVA Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: auto;
}
.modal-lg { max-width: 700px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 18px; }
.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
    line-height: 1;
}
.btn-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-form-row {
    display: flex;
    gap: 16px;
}
.modal-form-row .form-group { flex: 1; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.modal-preview, .modal-empty {
    margin-top: 20px;
    padding: 16px;
    border-radius: 8px;
    background: var(--primary-soft);
    border: 1px solid #bfdbfe;
}
.modal-empty {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
}
.modal-empty p { margin: 0; }
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}
.preview-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.preview-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.preview-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Copy modal styles */
.copy-companies { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.copy-company-row { display: flex; align-items: center; gap: 12px; }
.copy-company-label { font-weight: 600; min-width: 180px; color: var(--muted); font-size: 14px; }
.copy-company-value { font-weight: 500; }
.copy-error { padding: 12px 16px; background: var(--danger-bg); border: 1px solid var(--danger-border); border-radius: 8px; color: var(--danger); margin-top: 12px; }
.copy-error p { margin: 0; }
.copy-info { padding: 12px 16px; background: #e8f0fe; border: 1px solid #aecbfa; border-radius: 8px; color: #1967d2; margin-top: 12px; }
.copy-info p { margin: 0; }
.copy-warning { padding: 12px 16px; background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: 8px; color: var(--warning); margin-top: 12px; }
.copy-warning p { margin: 0; }
.copy-loading { padding: 16px; text-align: center; color: var(--muted); }
.copy-loading p { margin: 0; }
.copy-success { padding: 16px; background: var(--success-bg); border: 1px solid var(--success-border); border-radius: 8px; margin-top: 12px; }
.copy-success p { margin: 0 0 8px; color: var(--success); font-weight: 600; }
.copy-mapping-line { padding: 4px 0; font-size: 14px; border-bottom: 1px solid var(--border); }
.copy-mapping-line:last-child { border-bottom: none; }
.copy-preview-header { font-weight: 600; margin-bottom: 12px; color: var(--text); }
.copy-preview-table { font-size: 13px; }
.copy-preview-table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---- Print: professional A4 output (and future PDF) ---- */
@media print {
    @page { size: A4; margin: 12mm 10mm; }

    body { background: #fff !important; }

    .sidebar, .topbar, .sidebar-toggle, .sidebar-backdrop, .no-print { display: none !important; }
    .app-shell { display: block; }
    .content { margin: 0 !important; padding: 0 !important; }
    .container { max-width: none !important; padding: 0 !important; margin: 0 !important; }
    .alert { display: none !important; }

    .invoice-sheet {
        box-shadow: none;
        border-radius: 0;
        padding: 0;
        margin: 0;
        max-width: none;
    }
    .tpl-items tr { page-break-inside: avoid; }
    .tpl-totals, .tpl-letters, .tpl-notes, .tpl-pro-meta, .tpl-pro-client,
    .tpl-mod-band, .tpl-mod-cards, .tpl-chips, .tpl-cla-box,
    .tpl-cus-head, .tpl-cus-client, .tpl-cus-header, .tpl-cus-footer { page-break-inside: avoid; }
    .tpl-cancelled-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .tpl-cus-items thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
