/* ═══════════════════════════════════════════════════════════
   DocGen — Enterprise Flat Design System (Dark Edition)
   ═══════════════════════════════════════════════════════════ */

:root {
    /* ── Surface Colors ── */
    --bg-app: #0a0c12;
    --bg-sidebar: #0f131d;
    --bg-main: #0c0f17;
    --bg-card: #141824;
    --bg-card-hover: #181d2c;
    --bg-input: #171d2b;
    --bg-input-focus: #1a2133;
    --bg-hover: #20273a;
    --bg-surface-subtle: rgba(255, 255, 255, 0.03);

    /* ── Borders ── */
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);
    --border-focus: #4f46e5;
    --border-subtle: rgba(255, 255, 255, 0.04);

    /* ── Brand & Accent ── */
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-light: #6366f1;
    --accent-surface: rgba(79, 70, 229, 0.12);
    --accent-border: rgba(79, 70, 229, 0.35);

    /* ── Functional Colors ── */
    --text: #f1f3f9;
    --text-muted: #8b92a9;
    --text-dim: #5c6279;
    --success: #10b981;
    --success-surface: rgba(16, 185, 129, 0.12);
    --success-border: rgba(16, 185, 129, 0.3);
    --warning: #f59e0b;
    --warning-surface: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-surface: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.3);

    /* ── Shapes & Geometry ── */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* ── Transitions ── */
    --transition-fast: 120ms ease;
    --transition: 180ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    color-scheme: dark;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-app);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    color-scheme: dark;
    -webkit-font-smoothing: antialiased;
}

/* ── App Layout ──────────────────────────── */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ── Sidebar ─────────────────────────────── */
.sidebar {
    width: 295px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 18px 16px;
    gap: 16px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: #ffffff;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.2;
}

.sidebar-brand h1 {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-brand .badge-pro {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    background: var(--accent-surface);
    color: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-full);
}

.sidebar-brand p {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    font-weight: 600;
}

/* ── Radio Cards (Doc Type Selector) ──────── */
.radio-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.radio-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted);
    user-select: none;
}

.radio-card input {
    display: none;
}

.radio-card .radio-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    flex-shrink: 0;
    transition: color var(--transition-fast);
}

.radio-card .radio-icon svg {
    width: 15px;
    height: 15px;
}

.radio-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
    color: var(--text);
}

.radio-card:hover .radio-icon {
    color: var(--text);
}

.radio-card.active {
    border-color: var(--accent);
    background: var(--accent-surface);
    color: #ffffff;
    font-weight: 600;
}

.radio-card.active .radio-icon {
    color: var(--accent-light);
}

/* ── Theme Selector (Flat Modern Grid) ───── */
.theme-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    user-select: none;
}

.theme-option input {
    display: none;
}

.theme-option span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.theme-preview-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.modern-dot { background: #0ea5e9; }
.classic-dot { background: #d97706; }
.minimal-dot { background: #94a3b8; }
.corporate-dot { background: #2563eb; }
.creative-dot { background: #14b8a6; }
.executive-dot { background: #b45309; }
.stripe-dot { background: #6366f1; }
.bold-dot { background: #3b82f6; }
.compact-dot { background: #64748b; }
.elegant-dot { background: #a1a1aa; }
.i2e-dot { background: linear-gradient(135deg, #0284c7 0%, #f97316 100%); }

.theme-option:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
    color: var(--text);
}

.theme-option.active {
    border-color: var(--accent);
    background: var(--accent-surface);
    color: #ffffff;
    font-weight: 600;
}

.theme-option.active .theme-preview-dot {
    box-shadow: 0 0 0 2px var(--bg-sidebar), 0 0 0 3px var(--accent);
}

/* ── Toggle Group (FR / MG) ──────────────── */
.toggle-group {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 3px;
    border: 1px solid var(--border);
}

.toggle-btn {
    flex: 1;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 500;
    border-radius: 5px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.toggle-btn:hover {
    color: var(--text);
}

.toggle-btn.active {
    background: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

/* ── Inputs & Selects ────────────────────── */
.select-field,
.input-field,
.textarea {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.select-field {
    cursor: pointer;
}

.select-field:hover,
.input-field:hover,
.textarea:hover {
    border-color: var(--border-hover);
}

.select-field:focus,
.input-field:focus,
.textarea:focus {
    border-color: var(--accent);
    background: var(--bg-input-focus);
}

.date-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.date-input-wrapper input {
    padding-right: 34px !important;
    cursor: pointer;
}

.date-input-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

.date-input-icon svg {
    width: 14px;
    height: 14px;
}

.date-input-wrapper:hover .date-input-icon {
    opacity: 1;
    color: var(--accent);
}

/* ── Flatpickr Dark Modern Theme ─────────── */
.flatpickr-calendar {
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6) !important;
    font-family: inherit !important;
    color: var(--text) !important;
    width: 290px !important;
    padding: 6px !important;
}

.flatpickr-calendar::before,
.flatpickr-calendar::after {
    border-bottom-color: var(--bg-card) !important;
}

.flatpickr-months {
    background: transparent !important;
    padding: 6px 4px 4px 4px !important;
    align-items: center !important;
}

.flatpickr-months .flatpickr-month {
    color: var(--text) !important;
    fill: var(--text) !important;
    height: 34px !important;
}

.flatpickr-current-month {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: var(--text) !important;
    padding: 4px 0 0 0 !important;
}

.flatpickr-current-month .cur-month {
    font-weight: 600 !important;
    color: var(--text) !important;
}

.flatpickr-current-month input.cur-year {
    font-weight: 600 !important;
    color: var(--text-muted) !important;
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    color: var(--text-muted) !important;
    fill: var(--text-muted) !important;
    padding: 6px !important;
    border-radius: 4px !important;
    transition: all var(--transition-fast) !important;
}

.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
    background: var(--bg-hover) !important;
    color: var(--text) !important;
    fill: var(--text) !important;
}

.flatpickr-months .flatpickr-prev-month svg,
.flatpickr-months .flatpickr-next-month svg {
    width: 14px !important;
    height: 14px !important;
}

.flatpickr-weekdays {
    background: transparent !important;
    margin-bottom: 4px !important;
}

span.flatpickr-weekday {
    color: var(--text-dim) !important;
    font-size: 10.5px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

.flatpickr-days {
    width: 100% !important;
}

.dayContainer {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
}

.flatpickr-day {
    color: var(--text) !important;
    border-radius: var(--radius-sm) !important;
    border-color: transparent !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    height: 34px !important;
    line-height: 34px !important;
    margin: 1px 0 !important;
    max-width: none !important;
    transition: all var(--transition-fast) !important;
}

.flatpickr-day:hover {
    background: var(--bg-hover) !important;
    border-color: transparent !important;
    color: #ffffff !important;
}

.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
    color: var(--text-dim) !important;
    opacity: 0.35 !important;
}

.flatpickr-day.today {
    border: 1px solid var(--accent-border) !important;
    background: var(--accent-surface) !important;
    color: var(--accent-light) !important;
    font-weight: 700 !important;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4) !important;
}

.input-field::placeholder,
.textarea::placeholder {
    color: var(--text-dim);
}

.textarea {
    resize: vertical;
    min-height: 60px;
}

.select-field option {
    background: var(--bg-card);
    color: var(--text);
}

/* ── Flat Action Buttons ─────────────────── */
.sidebar-actions {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.btn-flat {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    user-select: none;
}

.btn-flat svg {
    width: 15px;
    height: 15px;
    stroke-width: 2;
    flex-shrink: 0;
}

/* Secondary Button (Dark Flat) */
.btn-flat-secondary {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-flat-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text);
}

/* Primary Button (Indigo Flat) */
.btn-flat-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

.btn-flat-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-flat-primary:active {
    transform: translateY(1px);
}

.btn-flat-primary.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Success Flat Button */
.btn-flat-success {
    background: var(--success-surface);
    border-color: var(--success-border);
    color: var(--success);
}

.btn-flat-success:hover {
    background: var(--success);
    border-color: var(--success);
    color: #ffffff;
}

.btn-flat-success.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Accent Outline Flat Button (Preview) */
.btn-flat-accent {
    background: var(--accent-surface);
    border-color: var(--accent-border);
    color: var(--accent-light);
}

.btn-flat-accent:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.generate-status {
    text-align: center;
    font-size: 11px;
    margin-top: 4px;
    min-height: 16px;
    font-weight: 500;
}

.generate-status.success {
    color: var(--success);
}

.generate-status.error {
    color: var(--danger);
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

/* ── Main Content Area ───────────────────── */
.main {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-main);
}

/* ── Form Section Cards (Flat) ───────────── */
.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    transition: border-color var(--transition-fast);
}

.form-section:hover {
    border-color: var(--border-hover);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.section-title-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-light);
}

.section-title-icon svg {
    width: 16px;
    height: 16px;
}

.section-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-mini-flat {
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition-fast);
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-mini-flat svg {
    width: 12px;
    height: 12px;
}

.btn-mini-flat:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent-light);
}

.btn-add-item {
    margin-left: auto;
    padding: 4px 12px;
    border: 1px solid var(--accent-border);
    background: var(--accent-surface);
    color: var(--accent-light);
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition-fast);
}

.btn-add-item svg {
    width: 13px;
    height: 13px;
}

.btn-add-item:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

/* ── Form Grids ──────────────────────────── */
.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.btn-auto-num {
    background: none;
    border: none;
    color: var(--accent-light);
    font-size: 10px;
    cursor: pointer;
    font-weight: 600;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: color var(--transition-fast);
}

.btn-auto-num svg {
    width: 11px;
    height: 11px;
}

.btn-auto-num:hover {
    color: #ffffff;
}

/* ── Parties Row ─────────────────────────── */
.parties-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ── Logo Upload ─────────────────────────── */
.logo-upload {
    cursor: pointer;
}

.logo-preview {
    width: 80px;
    height: 48px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: all var(--transition-fast);
    background: var(--bg-input);
}

.logo-preview:hover {
    border-color: var(--accent);
    background: var(--accent-surface);
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.logo-placeholder-text {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Items Edit Table ────────────────────── */
.items-table-wrapper {
    overflow-x: auto;
}

.items-edit-table {
    width: 100%;
    border-collapse: collapse;
}

.items-edit-table th {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    padding: 8px 6px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.items-edit-table td {
    padding: 5px 4px;
    vertical-align: middle;
}

.items-edit-table .input-field {
    padding: 6px 8px;
    font-size: 12px;
}

.col-narrow { width: 32px; text-align: center; }
.col-num { width: 85px; }
.col-unit { width: 75px; }

.items-edit-table .input-field.readonly {
    background: transparent;
    border-color: transparent;
    color: var(--accent-light);
    font-weight: 600;
    cursor: default;
    text-align: right;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.btn-row-action, .btn-remove-item {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-row-action svg, .btn-remove-item svg {
    width: 13px;
    height: 13px;
}

.btn-row-action:hover {
    background: var(--bg-surface);
    color: var(--accent-light);
}

.btn-remove-item:hover {
    background: var(--danger-surface);
    color: var(--danger);
}

.btn-due-chip {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-due-chip:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.row-number {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 500;
    text-align: center;
}

/* ── Totals Bar ──────────────────────────── */
.totals-bar {
    display: flex;
    justify-content: flex-end;
    gap: 24px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.total-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.total-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    font-weight: 600;
}

.total-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.total-grand .total-value {
    font-size: 18px;
    color: #ffffff;
}

/* ── Modals (Flat Modern) ────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    width: 700px;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.modal.modal-sm { width: 480px; }
.modal.modal-lg { width: 840px; max-width: 92vw; }

.modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
}

.modal-header h2 {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header h2 svg {
    width: 16px;
    height: 16px;
    color: var(--accent-light);
}

.modal-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.modal-tab {
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.modal-tab:hover {
    color: var(--text);
}

.modal-tab.active {
    background: var(--accent);
    color: #ffffff;
}

.modal-close {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close svg {
    width: 16px;
    height: 16px;
}

.modal-close:hover {
    color: #ffffff;
    background: var(--bg-hover);
}

.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Contacts Toolbar & List ─────────────── */
.contacts-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.contacts-filter {
    display: flex;
    gap: 4px;
}

.filter-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.filter-btn:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

.filter-btn.active {
    background: var(--accent-surface);
    border-color: var(--accent);
    color: #ffffff;
}

.contacts-list,
.documents-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 50vh;
    overflow-y: auto;
}

.contact-card,
.doc-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.contact-card:hover,
.doc-card:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
}

.contact-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-surface);
    color: var(--accent-light);
    border: 1px solid var(--accent-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.contact-info,
.doc-info {
    flex: 1;
    min-width: 0;
}

.contact-info .name,
.doc-info .doc-number {
    font-weight: 600;
    font-size: 12.5px;
    color: #ffffff;
}

.contact-info .sub,
.doc-info .doc-client {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-type-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.contact-type-badge.fournisseur {
    background: var(--accent-surface);
    color: var(--accent-light);
    border: 1px solid var(--accent-border);
}

.contact-type-badge.client {
    background: var(--success-surface);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.contact-actions,
.doc-actions {
    display: flex;
    gap: 4px;
}

.contact-action-btn,
.doc-action-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.contact-action-btn svg,
.doc-action-btn svg {
    width: 13px;
    height: 13px;
}

.contact-action-btn:hover,
.doc-action-btn:hover {
    border-color: var(--accent);
    color: #ffffff;
    background: var(--accent-surface);
}

.contact-action-btn.delete:hover,
.doc-action-btn.delete:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-surface);
}

.modal-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

/* ── Preview Overlay (Flat & Sleek) ──────── */
.preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.preview-overlay.open {
    display: flex;
    opacity: 1;
}

.preview-panel {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.preview-loading {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(10, 12, 18, 0.75);
    backdrop-filter: blur(4px);
    z-index: 10;
    color: var(--text-muted);
    font-size: 13px;
}

.preview-loading.active {
    display: flex;
}

.preview-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.preview-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-title {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-title svg {
    width: 16px;
    height: 16px;
    color: var(--accent-light);
}

.preview-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: #ffffff;
}

.preview-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-tool-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition-fast);
}

.preview-tool-btn svg {
    width: 15px;
    height: 15px;
}

.preview-tool-btn:hover {
    background: var(--bg-hover);
    color: #ffffff;
    border-color: var(--border-hover);
}

.preview-tool-btn.close:hover {
    background: var(--danger-surface);
    color: var(--danger);
    border-color: var(--danger-border);
}

.preview-zoom-level {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 42px;
    text-align: center;
}

.preview-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 24px;
    background: var(--bg-app);
}

.preview-page-wrapper {
    width: 210mm;
    min-height: 297mm;
    background: white;
    border-radius: 4px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    transform-origin: top center;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.preview-frame {
    width: 210mm;
    min-height: 297mm;
    border: none;
    display: block;
    background: white;
}

/* ── Scrollbars ──────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ── Confirmation Modal ──────────────────── */
.confirm-modal {
    max-width: 380px !important;
    text-align: center;
    padding: 24px 20px 20px 20px !important;
    border-radius: var(--radius-lg) !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7) !important;
    animation: modalPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopIn {
    from {
        opacity: 0;
        transform: scale(0.92);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.confirm-icon-badge {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin: 0 auto 14px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger-surface);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.confirm-icon-badge.primary {
    background: var(--accent-surface);
    color: var(--accent-light);
    border-color: var(--accent-border);
}

.confirm-icon-badge svg {
    width: 22px;
    height: 22px;
}

.confirm-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.confirm-message {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.45;
    margin-bottom: 20px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-actions .btn-flat {
    flex: 1;
    padding: 9px 14px;
    font-size: 12.5px;
    font-weight: 600;
}

.btn-flat-danger {
    background: var(--danger);
    color: #ffffff;
    border: 1px solid transparent;
}

.btn-flat-danger:hover {
    background: #dc2626;
}

/* ── Modern Toast Notification System ────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 380px;
}

.toast-item {
    pointer-events: auto;
    background: #141824;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: all 0.2s ease;
}

.toast-item.removing {
    opacity: 0;
    transform: translateX(30px);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-icon svg {
    width: 18px;
    height: 18px;
}

.toast-item.success {
    border-left: 3px solid var(--success);
}
.toast-item.success .toast-icon {
    color: var(--success);
}

.toast-item.error {
    border-left: 3px solid var(--danger);
}
.toast-item.error .toast-icon {
    color: var(--danger);
}

.toast-item.warning {
    border-left: 3px solid var(--warning);
}
.toast-item.warning .toast-icon {
    color: var(--warning);
}

.toast-item.info {
    border-left: 3px solid var(--accent-light);
}
.toast-item.info .toast-icon {
    color: var(--accent-light);
}

.toast-content {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.15s ease;
}

.toast-close:hover {
    color: var(--text);
}
/* États documentaires et gestion des sociétés */
[hidden] { display: none !important; }
.btn-flat:disabled { opacity: .45; cursor: not-allowed; }
#companyDialog::backdrop { background: rgba(0,0,0,.65); }
#companyDialog h2 { margin-bottom: 16px; }
#companyDialog .form-group { margin-bottom: 8px; }
#companyError { color: var(--danger); min-height: 20px; }
