/* ============================================================
   FactPulse Billing — Premium dark theme
   Calm surfaces, one accent, precise typography.
   ============================================================ */

/* ----- 1. Variables ----- */
:root {
    --bg-base: #0b0d11;
    --bg-elevated: #10131a;
    --bg-surface: #151922;
    --bg-hover: #1b202b;
    --bg-input: #0e1117;

    --primary: #ff6b35;
    --primary-hover: #ff7d4d;
    --primary-soft: rgba(255, 107, 53, 0.12);
    --primary-ring: rgba(255, 107, 53, 0.28);
    --on-primary: #1a0b04;

    --cyan: #7dd3fc;
    --magenta: #f472b6;
    --success: #4ade80;
    --warning: #fbbf24;
    --error: #f87171;
    --info: #93c5fd;

    --text: #eef0f4;
    --text-secondary: #a3abba;
    --text-muted: #6b7385;
    --text-inverse: #fff;

    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.12);

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);
    --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --focus-ring: 0 0 0 3px var(--primary-ring);

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

    --sidebar-width: 248px;

    /* Semantic tints */
    --cyan-bg: rgba(125, 211, 252, 0.1);
    --cyan-border: rgba(125, 211, 252, 0.22);
    --success-bg: rgba(74, 222, 128, 0.1);
    --success-border: rgba(74, 222, 128, 0.22);
    --warning-bg: rgba(251, 191, 36, 0.1);
    --warning-border: rgba(251, 191, 36, 0.24);
    --error-bg: rgba(248, 113, 113, 0.1);
    --error-border: rgba(248, 113, 113, 0.26);
    --info-bg: rgba(147, 197, 253, 0.1);
    --info-border: rgba(147, 197, 253, 0.22);
}

/* ----- 2. Reset & Base ----- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: dark;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text);
    line-height: 1.55;
}

::selection { background: var(--primary); color: var(--on-primary); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border: 3px solid transparent;
    background-clip: padding-box;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.16); }

a { color: var(--text); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--primary); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

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

pre, code { font-family: var(--font-mono); font-size: 0.82rem; }
code {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 0.1em 0.4em;
    border-radius: 5px;
}
pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
}
pre code { background: none; border: none; padding: 0; }

h1, h2, h3, h4, h5, h6 { color: var(--text); line-height: 1.25; letter-spacing: -0.015em; font-weight: 650; }
h1 { font-size: 1.6rem; letter-spacing: -0.025em; }
h2 { font-size: 1.15rem; margin: 2.25rem 0 1rem; }
h3 { font-size: 1.05rem; margin-bottom: 0.75rem; }
h4 { font-size: 0.95rem; margin-bottom: 0.5rem; }
p { color: var(--text-secondary); }
strong { color: var(--text); font-weight: 600; }

/* ----- 3. Layout ----- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 40;
}

.sidebar .logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0.6rem 0;
    margin-bottom: 1.75rem;
    text-decoration: none;
}
.sidebar .logo img { height: 30px; width: auto; }
.sidebar .logo span {
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1.15;
}
.sidebar .logo span small {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}
.sidebar .logo:hover span { color: var(--text); }

.nav-section {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 0.7rem;
    margin: 1.25rem 0 0.4rem;
}
.sidebar nav .nav-section:first-child { margin-top: 0; }

.sidebar nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.7rem;
    margin-bottom: 2px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar nav a svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke: currentColor;
    opacity: 0.75;
}
.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar nav a.active {
    background: var(--bg-hover);
    color: var(--text);
    box-shadow: var(--highlight);
}
.sidebar nav a.active svg { color: var(--primary); opacity: 1; }
.sidebar nav a.active::before {
    content: '';
    position: absolute;
    left: -0.85rem;
    top: 0.45rem;
    bottom: 0.45rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}

.sidebar .org-selector {
    margin-top: auto;
    padding-top: 1rem;
}
.sidebar .org-selector select { width: 100%; font-size: 0.82rem; margin-bottom: 0.6rem; }

.sidebar .user-section {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.6rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 650;
    color: var(--on-primary);
    background: linear-gradient(135deg, #ffa077, var(--primary));
}

.sidebar .user-email {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.sidebar .logout-link {
    display: inline-flex;
    padding: 0.3rem;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}
.sidebar .logout-link svg { width: 16px; height: 16px; stroke: currentColor; }
.sidebar .logout-link:hover { color: var(--error); background: var(--error-bg); }

.main-content {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 2.25rem 2.5rem 4rem;
}

/* Mobile bar (hidden on desktop) */
.nav-toggle { display: none; }
.mobile-bar { display: none; }
.nav-backdrop { display: none; }

/* ----- 4. Topbar ----- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}
.topbar h1 { margin: 0; }
.topbar-subtitle { margin-top: 0.3rem; font-size: 0.9rem; color: var(--text-muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* ----- 5. Buttons ----- */
button,
[role="button"],
input[type="submit"],
input[type="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--on-primary);
    background: linear-gradient(180deg, #ff7b4a 0%, var(--primary) 100%);
    border: 1px solid #ff7d4d;
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.22);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: filter 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
[role="button"]:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    filter: brightness(1.07);
    color: var(--on-primary);
    text-decoration: none;
}

button:active,
[role="button"]:active,
input[type="submit"]:active,
input[type="button"]:active { filter: brightness(0.95); }

button:focus-visible,
[role="button"]:focus-visible { box-shadow: var(--focus-ring); }

button:disabled,
[role="button"][disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
}

button.outline,
[role="button"].outline,
a[role="button"].outline {
    background: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-sm), var(--highlight);
}
button.outline:hover,
[role="button"].outline:hover,
a[role="button"].outline:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.18);
    filter: none;
}

button.secondary,
[role="button"].secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
button.secondary:hover,
[role="button"].secondary:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
    filter: none;
}

.btn-danger,
button.btn-danger {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error-border);
    box-shadow: none;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.18); color: var(--error); filter: none; }

.btn-sm,
button.btn-sm,
[role="button"].btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; border-radius: var(--radius-sm); }

/* Text link used as a table action */
a.btn-sm:not([role="button"]) {
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
}
a.btn-sm:not([role="button"]):hover { color: var(--text); background: var(--bg-hover); }

[aria-busy="true"]::before {
    content: '';
    width: 0.85em;
    height: 0.85em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- 6. Forms ----- */
label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="url"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    margin-bottom: 1.1rem;
    line-height: 1.4;
}

input:hover,
select:hover,
textarea:hover { border-color: rgba(255, 255, 255, 0.18); }

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    background: var(--bg-elevated);
}

select {
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7385' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
}

input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

input[readonly],
textarea[readonly],
.input-readonly {
    background: var(--bg-surface) !important;
    color: var(--text-secondary);
    cursor: default;
}

select option { background: var(--bg-elevated); color: var(--text); }

/* Checkboxes */
input[type="checkbox"] {
    width: 1.05em;
    height: 1.05em;
    margin: 0;
    accent-color: var(--primary);
    vertical-align: middle;
    cursor: pointer;
}

label:has(> input[type="checkbox"]) {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

/* Toggle switch */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}
.toggle input { display: none; }

.toggle-track {
    position: relative;
    width: 38px;
    height: 22px;
    background: var(--bg-hover);
    border: 1px solid var(--border-strong);
    border-radius: 11px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-secondary);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--primary); border-color: var(--primary); }
.toggle input:checked + .toggle-track::after { left: 18px; background: #fff; }

.toggle-field {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    margin-bottom: 1.1rem;
}

/* ----- 7. Tables ----- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

main > table,
.table-card,
form > table,
#invoice-table > table,
#customer-table > table,
#product-table > table,
#supplier-table > table {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--highlight);
}

thead { background: transparent; }

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-secondary);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

td a { color: var(--text); font-weight: 500; }
td a:hover { color: var(--primary); }

th.num,
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.num { color: var(--text); font-weight: 500; }
.nowrap { white-space: nowrap; }
.cell-strong { color: var(--text); font-weight: 500; }
.cell-muted { color: var(--text-muted); }

.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell a,
.actions-cell button { margin-left: 0.15rem; }

.empty-row { text-align: center; color: var(--text-muted); padding: 3rem 1rem !important; }

/* ----- 8. Stats cards ----- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.85rem;
    margin-bottom: 2rem;
}

.stats-hero {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.85rem;
    margin-bottom: 0.85rem;
}

a.stat-card { text-decoration: none; color: inherit; }
.stat-card {
    position: relative;
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--highlight);
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
a.stat-card:hover { border-color: var(--border-strong); background: var(--bg-hover); color: inherit; }
.stat-card .stat-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}
.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    margin-top: 0.35rem;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.stat-card.stat-hero { padding: 1.4rem 1.5rem; }
.stat-card.stat-hero .stat-value { font-size: 2.1rem; }
.stat-card.stat-accent {
    background:
        radial-gradient(120% 140% at 100% 0%, rgba(255, 107, 53, 0.16) 0%, transparent 55%),
        var(--bg-surface);
    border-color: rgba(255, 107, 53, 0.22);
}
.stat-hint { margin-top: 0.35rem; font-size: 0.78rem; color: var(--text-muted); }

.dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.dot-draft { background: var(--text-muted); }
.dot-validated { background: var(--cyan); }
.dot-transmitted { background: var(--info); }
.dot-paid { background: var(--success); }
.dot-pending { background: var(--warning); }

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin: 2.25rem 0 0.85rem;
}
.section-head h2 { margin: 0; }
.section-head a { font-size: 0.85rem; color: var(--text-secondary); }
.section-head a:hover { color: var(--primary); }

/* ----- 9. Badges ----- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.2em 0.65em 0.2em 0.55em;
    font-size: 0.74rem;
    font-weight: 550;
    line-height: 1.5;
    border-radius: 999px;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge-draft {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border-color: var(--border-strong);
}

.badge-processing,
.badge-validated,
.badge-flow {
    background: var(--cyan-bg);
    color: var(--cyan);
    border-color: var(--cyan-border);
}

.badge-transmitting,
.badge-ereporting-pending {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning-border);
}

.badge-transmitted {
    background: var(--info-bg);
    color: var(--info);
    border-color: var(--info-border);
}

.badge-accepted,
.badge-paid,
.badge-ereporting-submitted,
.badge-ereporting-accepted {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success-border);
}

.badge-rejected,
.badge-cancelled,
.badge-refused,
.badge-ereporting-error {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
}

.badge-error-flag {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    padding: 0.15em 0.55em;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
    margin-left: 0.35rem;
    vertical-align: middle;
    white-space: nowrap;
    cursor: help;
}
.badge-error-flag::before { content: '!'; font-weight: 800; }

/* ----- 10. Section boxes & Form layout ----- */
.form-narrow { max-width: 640px; }
.form-narrow-lg { max-width: 760px; }

.section-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.25rem;
    box-shadow: var(--highlight);
}
.section-box h3,
.section-box h4 { margin-top: 0; }

.section-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.section-label {
    display: block;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
    font-weight: 600;
}

.input-row { display: flex; gap: 0.5rem; align-items: stretch; margin-bottom: 1.1rem; }
.input-row input { flex: 1; margin-bottom: 0; }
.section-box .input-row:last-child { margin-bottom: 0; }
.input-row button,
.input-row [role="button"] { white-space: nowrap; flex-shrink: 0; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }
.form-inline { display: inline; }

.field-feedback { margin-top: 0.75rem; font-size: 0.85rem; }
.field-feedback-sm { margin-top: 0.25rem; font-size: 0.85rem; }
.field-warning { margin-top: 0.25rem; color: var(--warning); }

.logo-preview { max-height: 80px; border-radius: var(--radius); }
.color-input { height: 2.6rem; padding: 0.25rem; }
.label-spaced { margin-top: 1rem; }
.toggle-wrap { display: flex; align-items: end; padding-bottom: 1rem; }
.terms-preview { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.5rem; }

.btn-submit-full { margin-top: 1rem; width: 100%; }
.btn-submit-spaced { margin-top: 1rem; }

.customer-type-badge { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.customer-type-select { font-size: 0.8rem; padding: 0.2em 0.5em; max-width: 200px; }

/* ----- 11. Modal ----- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 6, 9, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 520px;
    width: 92%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.8rem 0.9rem;
    margin-bottom: 0.5rem;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    font-weight: 400;
    white-space: normal;
    justify-content: flex-start;
    cursor: pointer;
}
.modal-option:hover { border-color: var(--primary); background: var(--bg-hover); color: var(--text); filter: none; }
.modal-option strong { color: var(--text); }
.modal-option .meta { font-size: 0.8rem; color: var(--text-muted); margin-left: 0.5rem; }

/* ----- 12. Banners ----- */
.banner,
.sandbox-banner,
.degraded-banner {
    padding: 0.6rem 0.9rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    border: 1px solid;
}

.sandbox-banner,
.banner-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
}

.degraded-banner,
.banner-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error);
}

.alert {
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    border: 1px solid;
}

.alert-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error);
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
}

.alert-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info);
}

/* ----- 13. Timeline ----- */
.lifecycle {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem;
    font-size: 0.82rem;
}
.lifecycle-step {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
}
.lifecycle-step::before { content: '○'; }
.lifecycle-done { color: var(--success); background: var(--success-bg); border-color: transparent; }
.lifecycle-done::before { content: '✓'; }
.lifecycle-warn { color: var(--warning); border-color: var(--warning); }
.lifecycle-warn::before { content: '!'; font-weight: 700; }
.lifecycle-error { color: var(--error); background: var(--error-bg); border-color: transparent; }
.lifecycle-error::before { content: '✕'; }

.timeline {
    position: relative;
    padding-left: 1.5rem;
}

.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
    font-size: 0.875rem;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 0.35rem;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}
.timeline-item::after {
    content: '';
    position: absolute;
    left: calc(-1.5rem + 4px);
    top: 1rem;
    width: 1px;
    height: calc(100% - 0.75rem);
    background: var(--border-strong);
}
.timeline-item:last-child::after { display: none; }
.timeline-item .time { font-size: 0.78rem; color: var(--text-muted); }
.timeline-item.timeline-error::before { background: var(--error); box-shadow: 0 0 0 4px var(--error-bg); }
.timeline-item.timeline-success::before { background: var(--success); box-shadow: 0 0 0 4px var(--success-bg); }
.timeline-item.timeline-muted::before { background: var(--text-muted); box-shadow: none; }

details.timeline-item > summary {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    list-style: none;
    cursor: pointer;
    margin: -0.3rem 0 -0.3rem -0.5rem;
    padding: 0.3rem 1.4rem 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    position: relative;
    transition: background 0.12s ease;
}
details.timeline-item > summary::-webkit-details-marker { display: none; }
details.timeline-item > summary::after {
    content: '';
    position: absolute;
    right: 0.5rem;
    top: 0.65rem;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--text-muted);
    border-bottom: 1.5px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
}
details.timeline-item[open] > summary::after { transform: rotate(45deg); }
details.timeline-item > summary:hover { background: var(--bg-hover); }
details.timeline-item.timeline-error > summary strong { color: var(--error); }
.timeline-subtitle { font-size: 0.82rem; color: var(--text-secondary); }

.timeline-details {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 0.75rem;
    margin: 0.6rem 0 0.25rem;
    padding: 0.7rem 0.8rem;
    font-size: 0.8rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.timeline-details dt { color: var(--text-muted); white-space: nowrap; }
.timeline-details dd { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.timeline-details code { font-size: 0.75rem; white-space: pre-wrap; word-break: break-word; }

/* ----- 14. Invoice form ----- */
.split-view {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}

.preview-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    background: var(--bg-surface);
    box-shadow: var(--highlight);
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
}
.preview-panel h3 {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 1rem;
}

/* Line block */
.line-block {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    margin-bottom: 0.65rem;
    transition: border-color 0.15s ease;
}
.line-block:hover,
.line-block:focus-within { border-color: var(--border-strong); }

.line-block-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }

.line-number {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.line-catalog-picker { flex: 1; min-width: 0; }
.line-catalog-picker .ts-wrapper { margin-bottom: 0; }

.line-remove-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0 !important;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-muted) !important;
    background: transparent !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: none !important;
    cursor: pointer;
    transition: all 0.12s ease;
    flex-shrink: 0;
}
.line-remove-btn:hover {
    color: var(--error) !important;
    background: var(--error-bg) !important;
    border-color: var(--error-border) !important;
    filter: none !important;
}

/* Line fields grid */
.line-fields {
    display: grid;
    grid-template-columns: 3fr 1fr 1.2fr 1fr 1.2fr;
    gap: 0.5rem;
    align-items: end;
    position: relative;
}

.line-field-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-fields input,
.line-fields select {
    font-size: 0.85rem;
    margin-bottom: 0;
    height: 2.4rem;
    font-variant-numeric: tabular-nums;
}
.line-fields select { padding-left: 0.6rem; padding-right: 1.6rem; background-position: right 0.5rem center; }

.line-fields textarea {
    font-size: 0.85rem;
    margin-bottom: 0;
    height: 2.4rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.line-fields input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
    text-align: right;
}
.line-fields input[type="number"]::-webkit-inner-spin-button,
.line-fields input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* VAT exemption row */
.vat-exemption-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px dashed var(--border-strong);
}
.vat-exemption-row > div { display: flex; flex-direction: column; }
.vat-exemption-row > div:first-child { min-width: 190px; flex-shrink: 0; }

.vat-exemption-row select,
.vat-exemption-row input {
    margin-bottom: 0;
    font-size: 0.85rem;
    height: 2.4rem;
}
.vat-exemption-row .ts-wrapper { margin-bottom: 0; }
.vat-exemption-row .ts-control {
    font-size: 0.85rem !important;
    min-height: 2.4rem !important;
    padding: 0 0.8rem !important;
    display: flex !important;
    align-items: center !important;
}

/* Auto-grow textareas (shared by line names and notes) */
.auto-grow-input,
.line-name-input,
.note-input {
    resize: none;
    overflow: hidden;
    white-space: nowrap;
    line-height: 1.4;
}
.auto-grow-input:focus,
.line-name-input:focus,
.note-input:focus {
    white-space: pre-wrap;
    word-wrap: break-word;
}
.note-input[readonly] { background: var(--bg-surface) !important; color: var(--text) !important; cursor: default; }

/* ----- 15. Error box ----- */
.error-box {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
}
.error-box a { color: var(--error); text-decoration: underline; }
.error-box pre { color: var(--text-secondary); background: var(--bg-input); margin-top: 0.5rem; }

.error-details {
    margin-top: 0.75rem;
    margin-bottom: 0;
    font-size: 0.85rem;
    width: 100%;
}
.error-details th {
    text-align: left;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--error-border);
    color: var(--error);
    font-weight: 600;
}
.error-details td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--error-bg);
    color: var(--text);
}
.error-details code {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error);
    font-size: 0.8rem;
}

/* ----- 16. Login & Auth pages ----- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(60% 50% at 50% 0%, rgba(255, 107, 53, 0.12) 0%, transparent 70%),
        var(--bg-base);
}

.auth-page > * { width: 100%; }

.login-container {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 2.25rem 2rem 1.75rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg), var(--highlight);
}
body:not(:has(.auth-page)) .login-container { margin: 8vh auto; }

.auth-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 1.25rem;
}
.auth-brand img { height: 44px; width: auto; }

.login-title {
    text-align: center;
    color: var(--text);
    margin-bottom: 0.35rem;
    font-size: 1.4rem;
    letter-spacing: -0.02em;
}
.login-subtitle {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}
.login-body { text-align: center; margin-bottom: 1rem; }
.login-text { text-align: center; font-size: 0.9rem; }
.login-link { text-align: center; margin-top: 1rem; font-size: 0.875rem; color: var(--text-muted); }
.login-link + .login-link { margin-top: 0.4rem; }
.login-link a { color: var(--text); font-weight: 500; }
.login-link a:hover { color: var(--primary); }
.login-btn { width: 100%; margin-top: 0.4rem; padding-top: 0.7rem; padding-bottom: 0.7rem; }
.login-resend-btn { width: 100%; margin-top: 0.5rem; }
.auth-footer { margin-top: 1.5rem; text-align: center; font-size: 0.78rem; color: var(--text-muted); }

/* ----- 17. HTMX ----- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-swapping, .htmx-request table { opacity: 0.6; transition: opacity 0.15s ease; }

/* ----- 18. Utility classes ----- */
.text-primary { color: var(--primary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-warning-bold { color: var(--warning); font-weight: 600; }
.text-cyan { color: var(--cyan); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-bold { font-weight: 600; }

.d-inline { display: inline; }
.flex-1 { flex: 1; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 1rem; }
.mt-1 { margin-top: 1rem; }

.bg-elevated {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: var(--radius);
}
.bg-warning {
    background: var(--warning-bg) !important;
    border: 1px solid var(--warning-border);
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--warning);
}
.bg-success {
    background: var(--success-bg) !important;
    border: 1px solid var(--success-border);
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--success);
}

.row-archived { opacity: 0.5; }
.no-org-page { text-align: center; margin-top: 100px; }

/* Filter / search bar for list pages */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.filter-bar input,
.filter-bar select { margin-bottom: 0; }
.filter-bar-search { flex: 2; min-width: 200px; }
.filter-bar-search input[type="search"],
.filter-bar input[type="search"] {
    padding-left: 2.3rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7385' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.8rem center;
}
.filter-bar-select { flex: 1; min-width: 160px; max-width: 250px; }

/* ----- 19. Detail page ----- */
.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 2rem;
    align-items: start;
}
.detail-grid > :last-child {
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
}

.detail-meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.detail-meta > div { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.meta-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.15rem;
}
.meta-label-spaced { margin-bottom: 0.5rem; }

.detail-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.detail-parties > div { line-height: 1.6; color: var(--text-secondary); }
.detail-parties strong { color: var(--text); }

.detail-status { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.detail-status .badge { font-size: 0.82rem; }
.detail-status .text-muted { margin-left: 0; font-size: 0.85rem; }

/* Totals table */
.totals-value { text-align: right; font-weight: 600; color: var(--text); white-space: nowrap; }
.totals-value-primary { text-align: right; font-weight: 650; color: var(--text); white-space: nowrap; }
.totals-row-final { font-size: 1.05rem; }
.totals-row-final td { border-top: 1px solid var(--border-strong); color: var(--text); padding-top: 0.9rem; }
.totals-row-final .totals-value-primary { font-size: 1.25rem; letter-spacing: -0.01em; }

.detail-totals-wrap { display: flex; justify-content: flex-end; margin-top: 1rem; }
.detail-totals-table { width: 340px; max-width: 100%; }
.detail-totals-table td { border-bottom: none; padding: 0.45rem 0.25rem; }
.detail-notes { margin-top: 1.75rem; }
.detail-note-item { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.5rem; padding: 0.75rem 0.9rem; font-size: 0.875rem; }
.detail-note-badge { flex-shrink: 0; }
.detail-preceding { margin-top: 1.5rem; }
.detail-paid { margin-top: 1rem; }

/* Preview totals */
.preview-total-label { font-size: 0.78rem; color: var(--text-muted); }
.preview-total-value {
    font-size: 2.1rem;
    font-weight: 650;
    letter-spacing: -0.025em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    margin-bottom: 1rem;
}

.preview-table { font-size: 0.85rem; }
.preview-table td:last-child, .preview-table th:last-child { text-align: right; white-space: nowrap; }

/* ----- 20. PDP settings ----- */
.pdp-status-table { width: 100%; font-size: 0.875rem; }
.pdp-status-table td { padding: 0.4rem 0; border-bottom: none; }
.pdp-status-table td:first-child { color: var(--text-muted); padding-right: 1rem; }
.pdp-status-table code { word-break: break-all; }

/* ----- 21. Tom Select (dark theme) ----- */
select.tomselected { border: none !important; box-shadow: none !important; outline: none !important; }
.ts-wrapper { margin-bottom: 1.1rem; }

.ts-control {
    background: var(--bg-input) !important;
    color: var(--text) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: var(--radius) !important;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    padding: 0.55rem 0.8rem !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}
.focus .ts-control { border-color: var(--primary) !important; box-shadow: var(--focus-ring) !important; }
.ts-control > input { color: var(--text) !important; }
.ts-control > input::placeholder { color: var(--text-muted) !important; }
.ts-control .item { color: var(--text) !important; }

.ts-wrapper.single .ts-control::after {
    border-color: var(--text-muted) transparent transparent transparent !important;
    transition: transform 0.2s ease;
}
.ts-wrapper.single.dropdown-active .ts-control::after { transform: rotate(180deg); }

.ts-dropdown {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg);
    margin-top: 4px;
    overflow: hidden;
}

.ts-dropdown-content {
    max-height: 280px;
    overflow-y: auto;
    padding: 0.3rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.ts-dropdown .option {
    color: var(--text-secondary);
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    transition: background 0.1s ease;
    cursor: pointer;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background: var(--bg-hover) !important;
    color: var(--text) !important;
}

.ts-dropdown .option.selected {
    color: var(--text);
    font-weight: 600;
    position: relative;
    padding-right: 2rem;
}
.ts-dropdown .option.selected::after {
    content: '\2713';
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 0.9rem;
}
.ts-dropdown .option.selected.active,
.ts-dropdown .option.selected:hover { background: var(--bg-hover) !important; color: var(--text) !important; }

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

/* Compact Tom Select for invoice lines */
.ts-wrapper.ts-catalog { margin-bottom: 0; }
.ts-wrapper.ts-catalog .ts-control { font-size: 0.85rem; padding: 0.4rem 0.6rem !important; }
.ts-wrapper.ts-catalog .ts-dropdown .option { padding: 0.4rem 0.6rem; font-size: 0.85rem; }

.ts-dropdown .create {
    padding: 0.5rem 0.65rem;
    color: var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

/* ----- 22. Pagination ----- */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1.25rem;
    justify-content: center;
    flex-wrap: wrap;
    font-variant-numeric: tabular-nums;
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all 0.12s ease;
}
.pagination-link:hover { background: var(--bg-hover); color: var(--text); }
.pagination-link.active {
    background: var(--bg-surface);
    color: var(--text);
    border-color: var(--border-strong);
    font-weight: 600;
}
.pagination-link.disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.pagination-ellipsis { padding: 0.35rem 0.4rem; color: var(--text-muted); font-size: 0.85rem; }

/* ----- 23. Address autocomplete ----- */
.addr-autocomplete { position: relative; }
.addr-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% - 0.9rem);
    z-index: 50;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 240px;
    overflow-y: auto;
    padding: 0.3rem;
}

.addr-suggestions button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.65rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: none;
    font-size: 0.85rem;
    font-weight: 400;
    white-space: normal;
    justify-content: flex-start;
    cursor: pointer;
}
.addr-suggestions button:hover { background: var(--bg-hover); color: var(--text); filter: none; }

/* ----- 24. Prose (guide page) ----- */
.prose { max-width: 46rem; margin: 0 auto; }
.prose h1 { font-size: 1.75rem; margin: 0 0 1.5rem; color: var(--text); }
.prose h2 { font-size: 1.2rem; margin: 2.25rem 0 0.75rem; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.prose h3 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; color: var(--text); }
.prose p { margin: 0.6rem 0; line-height: 1.75; color: var(--text-secondary); }
.prose ul, .prose ol { margin: 0.6rem 0; padding-left: 1.5rem; color: var(--text-secondary); }
.prose li { margin: 0.3rem 0; line-height: 1.65; }
.prose a { color: var(--primary); }
.prose table { width: 100%; margin: 1rem 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.prose th, .prose td { padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-surface); color: var(--text); font-weight: 600; text-transform: none; letter-spacing: 0; font-size: 0.85rem; }
.prose td { color: var(--text-secondary); }
.prose strong { color: var(--text); }

/* ----- 25. Payment settings page ----- */
.input-mono { font-family: var(--font-mono); font-size: 0.85rem; }
.webhook-events-list { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 1rem 1.2rem; padding: 0; }

/* ----- 26. API Keys page ----- */
.api-key-banner { word-break: break-all; }
.api-key-copy-inline { margin-left: 0.5rem; }
.api-key-create-btn { margin-top: 0.5rem; }
.api-key-revoked { opacity: 0.5; }
.api-key-revoke-form { display: inline; }
.api-key-config-wrapper { position: relative; }
.api-key-config-pre { background: var(--bg-input); padding: 1rem; border-radius: var(--radius); overflow-x: auto; font-size: 0.85rem; }
.api-key-config-copy { position: absolute; top: 0.5rem; right: 0.5rem; }

/* ----- 27. Responsive ----- */
@media (max-width: 1100px) {
    .main-content { padding: 2rem 1.75rem 3rem; }
    .split-view { grid-template-columns: minmax(0, 1fr); }
    .preview-panel { position: static; max-height: none; }
    .detail-grid { grid-template-columns: minmax(0, 1fr); }
    .detail-grid > :last-child { position: static; max-height: none; }
}

@media (max-width: 900px) {
    .app-layout { display: block; }

    .mobile-bar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.7rem 1rem;
        background: rgba(11, 13, 17, 0.85);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
    }
    .mobile-bar .logo { display: flex; align-items: center; gap: 0.5rem; font-weight: 650; color: var(--text); }
    .mobile-bar .logo img { height: 26px; width: auto; }
    .mobile-bar .menu-btn {
        display: inline-flex;
        padding: 0.45rem;
        border-radius: var(--radius);
        border: 1px solid var(--border-strong);
        color: var(--text);
        cursor: pointer;
    }
    .mobile-bar .menu-btn svg { width: 20px; height: 20px; stroke: currentColor; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        width: min(82vw, 290px);
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: var(--shadow-lg);
        z-index: 60;
    }
    .nav-toggle:checked ~ .app-layout .sidebar { transform: translateX(0); }
    .nav-toggle:checked ~ .app-layout .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 50;
        background: rgba(5, 6, 9, 0.6);
        backdrop-filter: blur(2px);
    }

    .main-content { padding: 1.25rem 1rem 3rem; }
    .topbar { margin-bottom: 1.25rem; }
    h1 { font-size: 1.35rem; }

    .form-row { grid-template-columns: 1fr; }
    .detail-meta { grid-template-columns: repeat(2, 1fr); }
    .detail-parties { grid-template-columns: 1fr; }
    .line-fields { grid-template-columns: 1fr 1fr; }
    .line-fields > :first-child { grid-column: 1 / -1; }
    .vat-exemption-row { flex-direction: column; align-items: stretch; }
    .vat-exemption-row > div:first-child { min-width: 0; }
    .filter-bar-select { max-width: none; }

    /* Tables scroll horizontally instead of squeezing */
    main table:not(.detail-totals-table):not(.pdp-status-table):not(.error-details):not(.preview-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    main table:not(.detail-totals-table):not(.pdp-status-table):not(.error-details) td,
    main table:not(.detail-totals-table):not(.pdp-status-table):not(.error-details) th { white-space: nowrap; }

    .stats-hero { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stat-card.stat-hero .stat-value { font-size: 1.75rem; }
    .login-container { padding: 1.75rem 1.25rem 1.5rem; }
}
