/* ============================================================
   FactPulse Billing — Giscard Punk Theme
   Dark / neo-brutalist — aligned with FactPulse SaaS
   ============================================================ */

/* ----- 1. Variables ----- */
:root {
    --bg-base: #0f1419;
    --bg-elevated: #1a2332;
    --bg-surface: #232a3b;
    --bg-hover: #2a3347;

    --primary: #ff6b35;
    --primary-hover: #e55a2b;
    --cyan: #00d4ff;
    --magenta: #ff0080;
    --success: #00e676;
    --warning: #ffab00;
    --error: #ff1744;
    --info: #448aff;

    --text: #f5f0e6;
    --text-secondary: #a0aec0;
    --text-muted: #6b7a90;
    --text-inverse: #fff;

    --border: #2a3347;
    --border-strong: #3d4f6a;

    --radius: 6px;
    --radius-lg: 10px;
    --shadow-hard: 3px 3px 0 rgba(0, 0, 0, 0.5);
    --shadow-hard-primary: 3px 3px 0 rgba(255, 107, 53, 0.3);
    --focus-ring: 0 0 0 2px rgba(255, 107, 53, 0.15);

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

    /* Semantic opacity variants */
    --cyan-bg: rgba(0, 212, 255, 0.12);
    --cyan-border: rgba(0, 212, 255, 0.3);
    --success-bg: rgba(0, 230, 118, 0.12);
    --success-border: rgba(0, 230, 118, 0.3);
    --warning-bg: rgba(255, 171, 0, 0.1);
    --warning-border: rgba(255, 171, 0, 0.3);
    --error-bg: rgba(255, 23, 68, 0.12);
    --error-border: rgba(255, 23, 68, 0.3);
    --info-bg: rgba(68, 138, 255, 0.12);
    --info-border: rgba(68, 138, 255, 0.3);
}

/* ----- 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;
}

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

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

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

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

pre, code { font-family: var(--font-mono); font-size: 0.85rem; }
code { background: var(--bg-surface); padding: 0.15em 0.4em; border-radius: 3px; }
pre { background: var(--bg-surface); padding: 1rem; border-radius: var(--radius); overflow-x: auto; }

h1, h2, h3, h4, h5, h6 { color: var(--text); line-height: 1.3; }
strong { color: var(--text); }

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

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

.sidebar .logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0;
    margin-bottom: 1.5rem;
    text-decoration: none;
}

.sidebar .logo img { max-height: 48px; width: auto; }
.sidebar .logo span {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
}
.sidebar .logo:hover { text-decoration: none; }
.sidebar .logo:hover span { color: var(--primary); }

.sidebar nav a {
    display: block;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: all 0.15s ease;
}
.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: var(--bg-base); font-weight: 600; }

.sidebar .org-selector {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.sidebar .org-selector select { width: 100%; font-size: 0.85rem; }

.sidebar .user-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding: 0.5rem 0.65rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.sidebar .logout-link {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    margin-left: 0.5rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.15s ease;
}
.sidebar .logout-link:hover { color: var(--error); border-color: var(--error); text-decoration: none; }

.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

/* ----- 4. Topbar ----- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.5rem; }
.topbar-actions { display: flex; gap: 0.5rem; }

/* ----- 5. Buttons ----- */
button,
[role="button"],
input[type="submit"],
input[type="button"] {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--bg-base);
    background: var(--primary);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.12s ease;
    box-shadow: var(--shadow-hard-primary);
    line-height: 1.4;
}

button:hover,
[role="button"]:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 rgba(255, 107, 53, 0.4);
    text-decoration: none;
}

button:active,
[role="button"]:active,
input[type="submit"]:active,
input[type="button"]:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 rgba(255, 107, 53, 0.3);
}

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

button.outline,
[role="button"].outline,
a[role="button"].outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    box-shadow: var(--shadow-hard);
}
button.outline:hover,
[role="button"].outline:hover,
a[role="button"].outline:hover {
    background: var(--primary);
    color: var(--bg-base);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.6);
}

button.secondary,
[role="button"].secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 2px solid var(--border-strong);
    box-shadow: var(--shadow-hard);
}
button.secondary:hover,
[role="button"].secondary:hover {
    background: var(--error);
    color: var(--text-inverse);
    border-color: var(--error);
}

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

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

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.75rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s ease;
    margin-bottom: 1rem;
    line-height: 1.4;
}

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

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

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

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

/* Checkboxes */
input[type="checkbox"] {
    width: 1.1em;
    height: 1.1em;
    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: 600;
    color: var(--text-secondary);
}
.toggle input { display: none; }

.toggle-track {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--bg-base);
    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-muted);
    border-radius: 50%;
    transition: all 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--primary); border-color: var(--primary); }
.toggle input:checked + .toggle-track::after { left: 20px; background: var(--bg-base); }

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

/* ----- 7. Tables ----- */
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-elevated); }

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-strong);
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

tbody tr:hover { background: var(--bg-hover); }

.actions-cell { white-space: nowrap; }
.actions-cell a,
.actions-cell button { margin-right: 0.25rem; }

.empty-row { text-align: center; color: var(--text-muted); }

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

a.stat-card { text-decoration: none; color: inherit; }
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: border-color 0.15s ease;
    cursor: pointer;
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 0.25rem;
    color: var(--text);
}

/* ----- 9. Badges ----- */
.badge {
    display: inline-block;
    padding: 0.2em 0.6em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-draft {
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
}

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

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

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

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

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

.badge-error-flag {
    display: inline-block;
    padding: 0.15em 0.5em;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 3px;
    background: var(--error);
    color: var(--text-inverse);
    margin-left: 0.4rem;
    vertical-align: middle;
    cursor: help;
    animation: error-pulse 2s ease-in-out infinite;
}

@keyframes error-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

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

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

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

.section-label {
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
}

.input-row { display: flex; gap: 0.5rem; align-items: start; }
.input-row input { flex: 1; margin-bottom: 0; }
.input-row button { white-space: nowrap; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.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.5rem; padding: 0.25rem; }
.label-spaced { margin-top: 1rem; }
.toggle-wrap { display: flex; align-items: end; padding-bottom: 1rem; }
.terms-preview { color: var(--cyan); 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(0, 0, 0, 0.5);
    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: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.modal-option:hover { border-color: var(--cyan); }
.modal-option strong { color: var(--cyan); }
.modal-option .meta { font-size: 0.8rem; color: var(--text-muted); margin-left: 0.5rem; }

/* ----- 12. Banners ----- */
.banner {
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    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: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    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);
}

/* ----- 13. Timeline ----- */
.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 0.25rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 6px rgba(255, 107, 53, 0.4);
}
.timeline-item::after {
    content: '';
    position: absolute;
    left: -1.25rem;
    top: 0.75rem;
    width: 2px;
    height: calc(100% - 0.5rem);
    background: var(--border-strong);
}
.timeline-item:last-child::after { display: none; }
.timeline-item .time { font-size: 0.8rem; color: var(--text-muted); }

/* ----- 14. Invoice form ----- */
.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.preview-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    background: var(--bg-elevated);
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}
.preview-panel h3 { color: var(--cyan); margin-bottom: 1rem; }

/* Line block */
.line-block {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    transition: border-color 0.15s ease;
}
.line-block:hover { border-left-color: var(--primary); }

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

.line-number {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg-base);
    padding: 0.15rem 0.45rem;
    border-radius: 3px;
    flex-shrink: 0;
}

.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: 26px;
    height: 26px;
    padding: 0 !important;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-muted) !important;
    background: transparent !important;
    border: 1px solid var(--border) !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    cursor: pointer;
    transition: all 0.12s ease;
    flex-shrink: 0;
}
.line-remove-btn:hover {
    color: var(--text-inverse) !important;
    background: var(--error) !important;
    border-color: var(--error) !important;
    transform: none !important;
    box-shadow: none !important;
}

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

.line-field-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0.2rem;
    line-height: 1.3;
}

.line-fields input,
.line-fields select {
    font-size: 0.85rem;
    margin-bottom: 0;
    height: 2.375rem;
}

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

.line-fields input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}
.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.6rem;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--cyan-border);
}
.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.375rem;
}
.vat-exemption-row .ts-wrapper { margin-bottom: 0; }
.vat-exemption-row .ts-control {
    font-size: 0.85rem !important;
    min-height: 2.375rem !important;
    padding: 0 0.75rem !important;
    display: flex !important;
    align-items: center !important;
}

/* Auto-grow textareas (shared by line names and notes) */
.auto-grow-input {
    resize: none;
    overflow: hidden;
    white-space: nowrap;
    line-height: 1.4;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.auto-grow-input:focus {
    white-space: pre-wrap;
    word-wrap: break-word;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

/* Legacy aliases — keep until templates fully migrated */
.line-name-input { resize: none; overflow: hidden; white-space: nowrap; line-height: 1.4; transition: box-shadow 0.15s ease, border-color 0.15s ease; }
.line-name-input:focus { white-space: pre-wrap; word-wrap: break-word; border-color: var(--primary); box-shadow: var(--focus-ring); }
.note-input { resize: none; overflow: hidden; white-space: nowrap; line-height: 1.4; transition: box-shadow 0.15s ease, border-color 0.15s ease; }
.note-input:focus { white-space: pre-wrap; word-wrap: break-word; }
.note-input[readonly] { background: var(--bg-elevated) !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: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.error-box pre { color: var(--text-secondary); background: var(--bg-base); margin-top: 0.5rem; }

.error-details {
    margin-top: 0.75rem;
    margin-bottom: 0;
    font-size: 0.85rem;
    border-collapse: collapse;
    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.3rem 0.6rem;
    border-bottom: 1px solid var(--error-bg);
    color: var(--text);
}
.error-details code {
    background: var(--error-bg);
    color: var(--error);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.8rem;
}

/* ----- 16. Login & Auth pages ----- */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 2rem;
}
.login-title {
    text-align: center;
    color: var(--primary);
    margin-bottom: 2rem;
    font-size: 1.8rem;
    letter-spacing: -0.5px;
}
.login-body { text-align: center; margin-bottom: 1rem; }
.login-text { text-align: center; font-size: 0.9rem; }
.login-link { text-align: center; margin-top: 0.75rem; font-size: 0.9rem; }
.login-link + .login-link { margin-top: 0.5rem; }
.login-btn { width: 100%; margin-top: 1rem; }
.login-resend-btn { width: 100%; margin-top: 0.5rem; }

/* ----- 17. HTMX ----- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ----- 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: bold; }

.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-elevated) !important;
    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;
    gap: 1rem;
    margin-bottom: 1rem;
}
.filter-bar-search { flex: 2; min-width: 200px; }
.filter-bar-select { flex: 1; min-width: 160px; max-width: 250px; }

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

.detail-meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}
.meta-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; }
.meta-label-spaced { margin-bottom: 0.5rem; }

.detail-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.detail-status { margin-bottom: 1.5rem; }
.detail-status .badge { font-size: 0.9rem; }
.detail-status .text-muted { margin-left: 1rem; }

/* Totals table */
.totals-value { text-align: right; font-weight: bold; }
.totals-value-primary { text-align: right; font-weight: bold; color: var(--cyan); }
.totals-row-final { font-size: 1.1rem; }
.totals-row-final td { border-top: 2px solid var(--primary); }

.detail-totals-wrap { display: flex; justify-content: flex-end; margin-top: 1rem; }
.detail-totals-table { width: 300px; }
.detail-notes { margin-top: 1.5rem; }
.detail-note-item { margin-bottom: 0.5rem; padding: 0.75rem; }
.detail-note-badge { margin-right: 0.5rem; }
.detail-preceding { margin-top: 1.5rem; }
.detail-paid { margin-top: 1rem; }

/* Preview totals */
.preview-total-label { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); }
.preview-total-value { font-size: 2rem; font-weight: bold; color: var(--cyan); }

.preview-table { font-size: 0.85rem; }

/* ----- 20. PDP settings ----- */
.pdp-status-table { width: 100%; font-size: 0.9rem; }
.pdp-status-table td { padding: 0.35rem 0; border-bottom: none; }
.pdp-status-table td:first-child { color: var(--text-muted); }

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

.ts-control {
    background: var(--bg-elevated) !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.5rem 0.75rem !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; font-style: italic; }
.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-elevated) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 0 0 var(--radius) var(--radius) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    margin-top: 2px;
}

.ts-dropdown-content {
    max-height: 280px;
    overflow-y: auto;
    padding: 0.25rem 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.ts-dropdown-content::-webkit-scrollbar { width: 6px; }
.ts-dropdown-content::-webkit-scrollbar-track { background: transparent; }
.ts-dropdown-content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.ts-dropdown .option {
    color: var(--text-secondary);
    padding: 0.55rem 0.75rem;
    border-left: 3px solid transparent;
    transition: all 0.1s ease;
    cursor: pointer;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background: var(--bg-hover) !important;
    color: var(--text) !important;
    border-left-color: var(--cyan);
}

.ts-dropdown .option.selected {
    color: var(--primary);
    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(--primary) !important;
    border-left-color: var(--primary);
}

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

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

/* Tom Select create option */
.ts-dropdown .create {
    padding: 0.55rem 0.75rem;
    color: var(--cyan);
    cursor: pointer;
}

/* ----- 22. Pagination ----- */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.pagination-link {
    display: inline-block;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.12s ease;
}
.pagination-link:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-strong);
    text-decoration: none;
}
.pagination-link.active {
    background: var(--primary);
    color: var(--bg-base);
    border-color: var(--primary);
    font-weight: 600;
}
.pagination-link.disabled { opacity: 0.4; 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: 100%;
    z-index: 50;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    max-height: 240px;
    overflow-y: auto;
}

.addr-suggestions button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.1s ease;
}
.addr-suggestions button:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-left: 3px solid var(--cyan);
    transform: none;
    box-shadow: none;
}
.addr-suggestions button:last-child { border-bottom: none; }

/* ----- 24. Prose (guide page) ----- */
.prose { max-width: 48rem; margin: 0 auto; }
.prose h1 { font-size: 1.75rem; margin: 0 0 1.5rem; color: var(--text); }
.prose h2 { font-size: 1.3rem; margin: 2rem 0 0.75rem; color: var(--cyan); border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.prose h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; color: var(--text); }
.prose p { margin: 0.5rem 0; line-height: 1.7; color: var(--text-secondary); }
.prose ul, .prose ol { margin: 0.5rem 0; padding-left: 1.5rem; color: var(--text-secondary); }
.prose li { margin: 0.25rem 0; line-height: 1.6; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.prose th, .prose td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-surface); color: var(--text); font-weight: 600; }
.prose td { color: var(--text-secondary); }
.prose strong { color: var(--text); }

/* ----- 25. 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-surface, #f5f5f5); padding: 1rem; border-radius: 4px; overflow-x: auto; font-size: 0.85rem; }
.api-key-config-copy { position: absolute; top: 0.5rem; right: 0.5rem; }
