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

    --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);

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

/* ----- 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;
    color: var(--text);
}

.topbar .user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* ----- 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: white;
    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: 0 0 0 2px rgba(255, 107, 53, 0.15);
}

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 — basic */
input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--primary);
    width: 1.1em;
    height: 1.1em;
    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;
}

/* ----- 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 {
    background: rgba(0, 212, 255, 0.12);
    color: var(--cyan);
    border: 1px solid rgba(0, 212, 255, 0.3);
}

.badge-validated {
    background: rgba(0, 212, 255, 0.12);
    color: var(--cyan);
    border: 1px solid rgba(0, 212, 255, 0.3);
}

.badge-transmitting {
    background: rgba(255, 167, 38, 0.12);
    color: var(--warning, #ffa726);
    border: 1px solid rgba(255, 167, 38, 0.3);
}

.badge-transmitted {
    background: rgba(68, 138, 255, 0.12);
    color: var(--info);
    border: 1px solid rgba(68, 138, 255, 0.3);
}

.badge-accepted {
    background: rgba(0, 230, 118, 0.12);
    color: var(--success);
    border: 1px solid rgba(0, 230, 118, 0.3);
}

.badge-paid {
    background: rgba(0, 230, 118, 0.12);
    color: var(--success);
    border: 1px solid rgba(0, 230, 118, 0.3);
}

.badge-rejected {
    background: rgba(255, 23, 68, 0.12);
    color: var(--error);
    border: 1px solid rgba(255, 23, 68, 0.3);
}

.badge-cancelled {
    background: rgba(255, 23, 68, 0.12);
    color: var(--error);
    border: 1px solid rgba(255, 23, 68, 0.3);
}

.badge-refused {
    background: rgba(255, 23, 68, 0.12);
    color: var(--error);
    border: 1px solid rgba(255, 23, 68, 0.3);
}

.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: #fff;
    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. Banners ----- */
.sandbox-banner {
    background: rgba(255, 171, 0, 0.1);
    border: 1px solid rgba(255, 171, 0, 0.3);
    color: var(--warning);
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.degraded-banner {
    background: rgba(255, 23, 68, 0.1);
    border: 1px solid rgba(255, 23, 68, 0.3);
    color: var(--error);
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}

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

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

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* --- Line block: card per invoice line --- */
.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: #fff !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 (shown when rate=0%) --- */
.vat-exemption-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px dashed rgba(0, 212, 255, 0.2);
}

.vat-exemption-row > div {
    display: flex;
    flex-direction: column;
}

.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;
}

.vat-exemption-row > div:first-child {
    min-width: 190px;
    flex-shrink: 0;
}

/* --- Désignation textarea: collapsed single-line by default --- */
.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;
}

/* --- Désignation: grow in place on focus --- */
.line-name-input:focus {
    white-space: pre-wrap;
    word-wrap: break-word;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.15);
}

/* --- Note textareas: auto-grow on focus --- */
.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;
}

/* ----- 13. Error box ----- */
.error-box {
    background: rgba(255, 23, 68, 0.1);
    border: 1px solid rgba(255, 23, 68, 0.3);
    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 rgba(255, 23, 68, 0.2);
    color: var(--error);
    font-weight: 600;
}
.error-details td {
    padding: 0.3rem 0.6rem;
    border-bottom: 1px solid rgba(255, 23, 68, 0.1);
    color: var(--text-primary);
}
.error-details code {
    background: rgba(255, 23, 68, 0.08);
    color: var(--error);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.8rem;
}

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

/* ----- 15. HTMX ----- */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline;
}

/* ----- 16. Utility classes ----- */
.text-primary {
    color: var(--primary) !important;
}

.text-cyan {
    color: var(--cyan) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.bg-elevated {
    background: var(--bg-elevated) !important;
    padding: 1rem;
    border-radius: var(--radius);
}

.bg-warning {
    background: rgba(255, 171, 0, 0.1) !important;
    border: 1px solid rgba(255, 171, 0, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--warning);
}

.field-warning {
    margin-top: 0.25rem;
    color: var(--warning, #ffa726);
}

.bg-success {
    background: rgba(0, 230, 118, 0.1) !important;
    border: 1px solid rgba(0, 230, 118, 0.2);
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--success);
}

/* Detail page grids */
.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;
}

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

/* Totals table */
.totals-row-final {
    font-size: 1.1rem;
    border-top: 2px solid var(--primary) !important;
}

.totals-row-final td {
    border-top: 2px solid var(--primary);
}

.totals-value {
    text-align: right;
    font-weight: bold;
}

.totals-value-primary {
    text-align: right;
    font-weight: bold;
    color: var(--cyan);
}

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

/* ----- 17. Tom Select (dark theme) ----- */

/* Hide focus glow on the original select (Tom Select keeps it in the DOM) */
select.tomselected {
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.ts-wrapper {
    margin-bottom: 1rem;
}

/* --- Control (the visible select box) --- */
.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: 0 0 0 2px rgba(255, 107, 53, 0.15) !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;
}

/* --- Caret (dropdown arrow) --- */
.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);
}

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

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

/* Already-selected option: checkmark + accent color */
.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);
}

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

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

/* ----- 19. Address autocomplete dropdown ----- */
.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;
}

/* --- Product catalog Tom Select (compact 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;
}
