/* ============================================================
   COMPTAFLOW - Design System Dark Mode (Stitch Redesign)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    /* Palette */
    --bg: #0f172a;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.07);
    --surface-3: #1e293b;
    --border: rgba(255, 255, 255, 0.08);
    --border-2: rgba(255, 255, 255, 0.12);

    /* Brand */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --violet: #8b5cf6;

    /* Accents */
    --green: #22c55e;
    --green-dim: rgba(34, 197, 94, 0.15);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.15);
    --orange: #fb923c;
    --blue: #38bdf8;
    --emerald: #10b981;

    /* Text */
    --text: #f1f5f9;
    --text-muted: #64748b;
    --text-subtle: #475569;

    /* Layout */
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    --font: 'Manrope', 'Inter', system-ui, sans-serif;
}

/* ============================================================
   RESET & BASE
   ============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 60% at 20% -10%, rgba(99, 102, 241, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 80% 110%, rgba(139, 92, 246, 0.08) 0%, transparent 60%);
    color: var(--text);
    font-family: var(--font);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   GLASS PANELS
   ============================================================ */

.glass-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: var(--transition);
}

.glass-panel:hover {
    border-color: var(--border-2);
}

/* ============================================================
   LAYOUT
   ============================================================ */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem 1.5rem;
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1.5rem;
}

@media (max-width: 1100px) {
    .container {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   HEADER
   ============================================================ */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

header h1 {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
}

header p {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 1px;
}

/* ============================================================
   NAVIGATION TABS
   ============================================================ */

.main-nav {
    display: flex;
    gap: 0;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
}

.nav-tab {
    background: none;
    border: none;
    padding: 1rem 1.25rem;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    font-size: 0.88rem;
    font-family: var(--font);
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.nav-tab:hover {
    color: var(--text);
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ============================================================
   VIEW SECTIONS
   ============================================================ */

.view-section {
    display: none;
    animation: fadeIn 0.25s ease;
    padding-top: 1.5rem;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   FORM ELEMENTS - Global
   ============================================================ */

input,
select,
textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 0.65rem 0.875rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-subtle);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select option {
    background: #1e293b;
    color: var(--text);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--violet) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.25rem;
    font-weight: 700;
    font-size: 0.88rem;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px var(--primary-glow);
    width: 100%;
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.settings-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 0.5rem 0.875rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.settings-btn:hover {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border-2);
}

.glass-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font);
}

/* ============================================================
   TOGGLE WIDGET (Recette / Dépense & HT / TTC)
   ============================================================ */

.toggle-wrapper {
    display: flex;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.toggle-option {
    flex: 1;
    text-align: center;
    padding: 0.45rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
    user-select: none;
}

.toggle-option.active {
    background: var(--surface-3);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Type toggle specific colors */
#typeToggle .toggle-option[data-value="recette"].active {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

#typeToggle .toggle-option[data-value="depense"].active {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

/* ============================================================
   ENTRY FORM (Left sidebar)
   ============================================================ */

.entry-form {
    padding: 1.5rem;
    height: fit-content;
    position: sticky;
    top: calc(56px + 49px + 1.5rem);
}

.entry-form h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 1.25rem;
    letter-spacing: -0.01em;
}

/* Live Preview Box */
.preview-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.875rem 1rem;
    margin-bottom: 1rem;
}

.preview-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
}

.preview-row+.preview-row {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--border-2);
}

.preview-row .label {
    color: var(--text-muted);
}

.preview-row .value {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
}

/* ============================================================
   DASHBOARD (Right column)
   ============================================================ */

.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Filter Header */
.filter-header {
    padding: 0.875rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.month-selector {
    padding: 0.4rem 0.75rem;
    width: auto;
    height: 36px;
    font-size: 0.85rem;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Deadline Cards */
.deadline-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 800px) {
    .deadline-grid {
        grid-template-columns: 1fr;
    }
}

.deadline-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
}

.deadline-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.deadline-card.urssaf::before {
    background: linear-gradient(90deg, var(--red), #fb923c);
}

.deadline-card.tva::before {
    background: linear-gradient(90deg, var(--primary), var(--blue));
}

.deadline-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.deadline-badge.urssaf {
    background: rgba(248, 113, 113, 0.15);
    color: var(--red);
}

.deadline-badge.tva {
    background: var(--primary-glow);
    color: var(--primary);
}

.deadline-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.deadline-period {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
}

.deadline-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.deadline-amount {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.04em;
}

.deadline-due {
    text-align: right;
}

.deadline-due-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: block;
}

.deadline-due-date {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-card {
    padding: 1.1rem 1.25rem;
}

.stat-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.stat-value {
    display: block;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    color: var(--text);
}

.stat-value.income {
    color: var(--green);
}

.stat-value.expense {
    color: var(--red);
}

.stat-sub {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ============================================================
   JOURNAL TABLE
   ============================================================ */

.journal-container {
    overflow: hidden;
}

.journal-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.journal-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 700;
    font-size: 0.9rem;
}

.journal-count {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}

#journalSearch {
    width: 260px;
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    height: 36px;
}

.table-wrapper {
    overflow-x: auto;
}

#journalTable {
    width: 100%;
    border-collapse: collapse;
}

#journalTable thead th {
    padding: 0.65rem 1rem;
    text-align: left;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-subtle);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

#journalTable tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.15s ease;
    cursor: pointer;
}

#journalTable tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

#journalTable tbody tr:last-child {
    border-bottom: none;
}

#journalTable td {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    vertical-align: middle;
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.monospace {
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ============================================================
   JOURNAL DETAIL PANEL
   ============================================================ */

#journalDetailPanel {
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    flex-shrink: 0;
}

/* ============================================================
   MODAL (Generic)
   ============================================================ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #0f172a;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-xl);
    padding: 2rem;
    width: 90%;
    max-width: 520px;
    position: relative;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
    font-family: var(--font);
}

.close-modal:hover {
    background: var(--red-dim);
    color: var(--red);
}

.modal-content h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* ============================================================
   PROJECTION MODAL
   ============================================================ */

#projectionModal .modal-content {
    max-width: 860px;
}

.proj-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.88rem;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
}

.proj-row:last-child {
    border-bottom: none;
}

.proj-row .proj-val {
    font-weight: 700;
    font-family: monospace;
    color: var(--text);
    font-size: 0.9rem;
}

.proj-sep {
    height: 1px;
    background: var(--border-2);
    margin: 0.75rem 0;
}

.proj-row.bold {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    border-bottom: none;
}

.proj-row.bold .proj-val {
    font-size: 1.1rem;
    color: var(--emerald);
}

/* ============================================================
   RECURRING MODAL
   ============================================================ */

#recurringModal .modal-content {
    max-width: 640px;
}

/* ============================================================
   DOCUMENT LIST VIEW
   ============================================================ */

.doc-list-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-new-devis,
.btn-new-facture {
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
}

.btn-new-devis {
    background: rgba(139, 92, 246, 0.15);
    color: var(--violet);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.btn-new-devis:hover {
    background: rgba(139, 92, 246, 0.25);
    transform: translateY(-1px);
}

.btn-new-facture {
    background: linear-gradient(135deg, var(--primary), var(--violet));
    color: white;
    box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-new-facture:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.doc-list-table {
    width: 100%;
    border-collapse: collapse;
}

.doc-list-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-subtle);
    font-weight: 700;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
}

.doc-list-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.88rem;
    vertical-align: middle;
    color: var(--text);
}

.doc-row:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.doc-row:last-child td {
    border-bottom: none;
}

/* Type Badges */
.doc-type-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.doc-type-devis {
    background: rgba(139, 92, 246, 0.15);
    color: var(--violet);
    border: 1px solid rgba(139, 92, 246, 0.25);
}

.doc-type-facture {
    background: var(--primary-glow);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Status Badge */
.doc-status-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

/* Action Buttons */
.doc-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
}

.doc-action-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
    color: var(--text-muted);
}

.doc-action-btn:hover {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.doc-action-delete:hover {
    background: var(--red-dim);
    border-color: rgba(248, 113, 113, 0.3);
    color: var(--red);
}

/* ============================================================
   INVOICE EDITOR OVERLAY
   ============================================================ */

.editor-overlay {
    position: fixed;
    inset: 0;
    background: #080e1c;
    z-index: 3000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.editor-overlay.active {
    display: flex;
}

.editor-toolbar {
    background: rgba(15, 23, 42, 0.95);
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    z-index: 10;
}

.editor-back-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    font-family: var(--font);
    transition: var(--transition);
}

.editor-back-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.editor-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.editor-status-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text-muted);
}

/* Editor Buttons */
.editor-btn {
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: var(--font);
    transition: var(--transition);
    white-space: nowrap;
}

.editor-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--violet));
    color: white;
    box-shadow: 0 2px 10px var(--primary-glow);
}

.editor-btn-primary:hover {
    transform: translateY(-1px);
}

.editor-btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-2);
}

.editor-btn-secondary:hover {
    background: var(--surface-3);
}

.editor-btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.editor-btn-danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

.editor-btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--border-2);
}

.editor-btn-ghost:hover {
    background: var(--surface-2);
    border-color: var(--primary);
    color: var(--primary);
}

.editor-icon-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

.editor-icon-btn:hover {
    background: var(--surface-3);
}

/* Status Action Buttons */
.status-actions-group {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--border);
    display: flex;
    gap: 2px;
}

.status-btn {
    padding: 0.35rem 0.75rem;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: var(--transition);
    white-space: nowrap;
    font-family: var(--font);
    letter-spacing: 0.02em;
}

.status-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.status-btn.active {
    color: white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.status-btn.status-brouillon.active {
    background: #475569;
    border-color: #64748b;
}

.status-btn.status-envoye.active {
    background: #2563eb;
    border-color: #3b82f6;
}

.status-btn.status-encaisse.active {
    background: #16a34a;
    border-color: #22c55e;
}

.status-btn.status-accepte.active {
    background: #059669;
    border-color: #10b981;
}

.status-btn.status-refuse.active {
    background: #dc2626;
    border-color: #ef4444;
}

/* Scroll Area */
.editor-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 2.5rem 2rem;
    display: flex;
    justify-content: center;
    background: linear-gradient(180deg, #080e1c 0%, #0d1424 100%);
}

/* ============================================================
   INVOICE PAPER (A4-like white on dark bg)
   ============================================================ */

.invoice-paper {
    background: white;
    width: 100%;
    max-width: 1080px;
    min-height: 60vh;
    padding: 0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    color: #1a1a2e;
    font-size: 14px;
    margin: 0 auto;
    border-radius: 6px;
    overflow: visible;
    position: relative;
}

.invoice-color-band {
    height: 6px;
    background: linear-gradient(90deg, var(--primary), var(--violet));
    width: 100%;
    border-radius: 6px 6px 0 0;
    flex-shrink: 0;
}

.invoice-paper form {
    padding: 2.5rem 3rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    color: #1e293b;
}

/* Override inputs inside paper to light mode */
.invoice-paper input,
.invoice-paper select,
.invoice-paper textarea {
    background: white;
    border-color: #e2e8f0;
    color: #1e293b;
    font-family: var(--font);
}

.invoice-paper input:focus,
.invoice-paper select:focus,
.invoice-paper textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
    background: white;
}

.invoice-paper input::placeholder,
.invoice-paper textarea::placeholder {
    color: #94a3b8;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2.5rem;
    gap: 2rem;
}

.company-info {
    flex: 1;
    font-size: 0.85rem;
    color: #64748b;
    line-height: 1.6;
}

.company-info h3 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.4rem;
    letter-spacing: -0.02em;
}

.client-info {
    flex: 1;
    max-width: 320px;
    background: #f8fafc;
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.invoice-label {
    display: block;
    font-size: 0.62rem !important;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 0.4rem;
}

.invoice-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 0.88rem;
    background: white;
    color: #1e293b;
}

.client-details-display {
    margin-top: 0.6rem;
    font-size: 0.84rem;
    white-space: pre-wrap;
    line-height: 1.5;
    color: #1e293b;
}

.invoice-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #e8ecf1;
}

.doc-number-input {
    font-size: 1.55rem !important;
    font-weight: 800 !important;
    color: #1e293b !important;
    border: none !important;
    border-bottom: 2px dashed #e2e8f0 !important;
    padding: 0.2rem 0 !important;
    background: transparent !important;
    letter-spacing: -0.02em;
    width: 100%;
}

.doc-number-input:focus {
    border-bottom-color: var(--primary) !important;
    outline: none;
    box-shadow: none !important;
}

.invoice-dates {
    display: flex;
    gap: 1.25rem;
    text-align: right;
}

.date-field {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.invoice-date-input {
    padding: 0.4rem 0.6rem !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 6px !important;
    font-size: 0.85rem !important;
    color: #1e293b;
    width: auto !important;
}

/* Lines Table */
.lines-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.lines-table thead th {
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    padding: 0.6rem 0.75rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
}

.lines-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.lines-table tbody tr:hover {
    background: #fafbfc;
}

.lines-table td {
    padding: 0.45rem 0.75rem;
    vertical-align: top;
}

.lines-table .line-desc {
    width: 100%;
    min-height: 30px;
    overflow: hidden;
    word-wrap: break-word;
    white-space: pre-wrap;
    resize: none;
}

.lines-table input,
.lines-table select,
.lines-table textarea {
    border: 1px solid transparent;
    padding: 0.35rem 0.5rem;
    font-size: 0.86rem;
    background: transparent;
    color: #1a1a2e;
    resize: none;
    border-radius: 4px;
    box-shadow: none;
}

.lines-table input:hover,
.lines-table select:hover,
.lines-table textarea:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.lines-table input:focus,
.lines-table select:focus,
.lines-table textarea:focus {
    background: white;
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.lines-table input[type="number"] {
    text-align: right;
    -moz-appearance: textfield;
    appearance: textfield;
}

.lines-table input[type="number"]::-webkit-outer-spin-button,
.lines-table input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.btn-delete-line {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.25rem;
    border-radius: 4px;
    opacity: 0.3;
    transition: var(--transition);
}

.lines-table tr:hover .btn-delete-line {
    opacity: 1;
}

.btn-delete-line:hover {
    background: #fef2f2;
}

.add-line-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 2rem;
    padding-top: 0.5rem;
}

.add-line-btn {
    background: transparent;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    color: #64748b;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: var(--transition);
}

.add-line-btn:hover {
    background: #f8fafc;
    border-color: var(--primary);
    color: var(--primary);
}

.quick-product-select {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.82rem;
    color: #64748b;
    background: white;
}

/* Totals */
.invoice-totals-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 2rem;
}

.invoice-totals {
    width: 280px;
    background: #f8fafc;
    border-radius: 8px;
    padding: 1.25rem;
    border: 1px solid #e8ecf1;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    font-size: 0.9rem;
    color: #475569;
}

.total-row.final {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
    border-top: 2px solid #e2e8f0;
    margin-top: 0.4rem;
    padding-top: 0.75rem;
}

/* Footer Section */
.invoice-footer-section {
    display: flex;
    gap: 2rem;
    margin-top: auto;
    padding-top: 2rem;
    border-top: 1px solid #e8ecf1;
}

.invoice-notes {
    flex: 1;
}

.invoice-textarea {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-size: 0.84rem;
    color: #475569;
    resize: vertical;
    font-family: var(--font);
    background: white;
}

.invoice-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.invoice-signature-zone {
    text-align: center;
    min-width: 200px;
}

.signature-box {
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    padding: 1.25rem;
}

.signature-box p {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 1rem;
}

.signature-line {
    height: 40px;
    border-bottom: 1px solid #cbd5e1;
    margin-bottom: 0.5rem;
}

.signature-label {
    font-size: 0.68rem;
    color: #94a3b8;
}

.footer-section {
    flex: 1;
}

.footer-legal-input {
    width: 100%;
    border: none;
    border-bottom: 1px dashed #e2e8f0;
    padding: 0.3rem 0;
    font-size: 0.78rem;
    color: #94a3b8;
    background: transparent;
    font-family: var(--font);
}

/* Print only helpers (hidden on screen) */
.print-only-title,
.print-date-display,
.print-select-val {
    display: none;
}

/* ============================================================
   RESPONSIVE — TABLETTE & MOBILE
   Beaucoup de grilles sont posées en style inline depuis le HTML/JS :
   les surcharges ci-dessous utilisent !important pour les reprendre.
   ============================================================ */

/* Les enfants de grille/flex refusent par défaut de passer sous leur largeur
   min-content (min-width:auto) : une table large pousse alors toute la page.
   min-width:0 les autorise à rétrécir, le défilement restant local à la table. */
.container>*,
.dashboard>* {
    min-width: 0;
}

/* ---------- Tablette (≤ 900px) ---------- */
@media (max-width: 900px) {

    /* En-tête : titre au-dessus, contrôles en dessous et repliables */
    header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.9rem 1rem;
    }

    header>div:last-child {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    header h1 {
        font-size: 1.2rem;
    }

    /* Onglets : défilement horizontal plutôt que retour à la ligne */
    .main-nav {
        padding: 0 0.5rem;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .main-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-tab {
        padding: 0.85rem 0.9rem;
        font-size: 0.82rem;
        flex-shrink: 0;
    }

    /* Le formulaire de saisie ne colle plus en haut (il mangeait l'écran) */
    .entry-form {
        position: static;
        padding: 1.15rem;
    }

    .container {
        padding: 0 1rem 1rem;
        gap: 1rem;
    }

    /* Grilles de cartes posées en inline (clients, produits, KPI…) */
    #clientList,
    #productList {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Tables larges : défilement horizontal dans leur conteneur
       (!important : ces conteneurs portent un overflow:hidden en style inline) */
    .table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .doc-list-table {
        min-width: 640px;
    }

    /* Éditeur de document */
    .editor-toolbar {
        padding: 0.6rem 0.8rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .editor-scroll-area {
        padding: 1rem 0.75rem;
    }

    /* Formulaire admin utilisateurs : 2 colonnes */
    .user-admin-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* ---------- Mobile (≤ 600px) ---------- */
@media (max-width: 600px) {

    /* Cibles tactiles : 16px sur les champs évite le zoom auto iOS */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    header {
        padding: 0.75rem 0.85rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    header p {
        display: none;
    }

    /* Le sélecteur de société prend toute la largeur */
    .company-switch-wrapper {
        width: 100%;
        justify-content: space-between;
    }

    #headerCompanySelect {
        flex: 1;
        min-width: 0;
    }

    /* Badge utilisateur : les boutons se répartissent sur la largeur */
    #userHeaderBadge {
        width: 100%;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .nav-tab {
        padding: 0.8rem 0.7rem;
        font-size: 0.78rem;
    }

    .container {
        padding: 0 0.75rem 0.75rem;
    }

    .view-section {
        padding-top: 1rem;
    }

    /* Toutes les grilles multi-colonnes repassent sur une colonne */
    .stats-grid,
    .deadline-grid,
    #clientList,
    #productList,
    #recurringForm,
    .user-admin-grid {
        grid-template-columns: 1fr !important;
    }

    /* Grilles inline génériques (formulaires 2 colonnes des modals) */
    .modal-content [style*="grid-template-columns:1fr 1fr"],
    .modal-content [style*="grid-template-columns: 1fr 1fr"],
    .modal-box [style*="grid-template-columns:1fr 1fr"],
    .modal-box [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Modals : quasi plein écran, contenu défilable */
    .modal-overlay {
        padding: 0.5rem;
        align-items: flex-start;
    }

    .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh;
        margin-top: 0.5rem;
        display: flex;
        flex-direction: column;
    }

    .modal-box>div:last-child {
        overflow-y: auto;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        padding: 1.25rem;
        max-height: 92vh;
        border-radius: var(--radius-lg);
    }

    .modal-header {
        padding: 0.9rem 1rem;
    }

    /* Tables : défilement horizontal partout */
    .doc-list-table,
    #usersListTable table,
    #permissionsMatrixContainer table {
        min-width: 560px;
    }

    #usersListTable,
    #permissionsMatrixContainer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Éditeur de facture : plein écran utile, lignes lisibles au doigt */
    .editor-toolbar {
        padding: 0.5rem 0.6rem;
    }

    /* Sélecteur de barème : sur une ligne à lui, sinon le flex l'écrase */
    .editor-actions {
        flex-wrap: wrap;
    }

    .grid-picker {
        flex: 1 0 100%;
    }

    #pricingGridSelect {
        flex: 1;
        min-width: 0;
        max-width: none !important;
    }

    .editor-btn,
    .editor-back-btn {
        padding: 0.45rem 0.7rem;
        font-size: 0.78rem;
    }

    .editor-title-group h2 {
        font-size: 0.92rem !important;
    }

    .editor-scroll-area {
        padding: 0.5rem 0.4rem;
    }

    .invoice-paper {
        font-size: 12px;
    }

    .lines-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Barre de filtres : empilée */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .filter-actions button {
        flex: 1;
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    @page {
        size: A4 portrait;
        margin: 15mm;
    }

    body {
        background: white;
        padding: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color: #1e293b;
    }

    header,
    .main-nav,
    .editor-toolbar,
    .no-print,
    .add-line-bar {
        display: none !important;
    }

    body:has(.editor-overlay.active) .view-section {
        display: none !important;
    }

    .editor-overlay.active {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        background: white;
        display: block !important;
    }
    
    .editor-overlay:not(.active) {
        display: none !important;
    }

    .editor-scroll-area {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        padding: 0;
        background: white;
        display: block !important;
    }

    .invoice-paper {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .invoice-paper form {
        padding: 0; 
    }

    /* Transform inputs into plain text for print */
    .invoice-paper input:not([type="checkbox"]),
    .invoice-paper textarea {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 0 !important;
        resize: none !important;
    }

    /* Hide form elements that have print equivalents or are redundant */
    .invoice-select,
    .editor-icon-btn,
    .invoice-date-input,
    .lines-table select,
    .invoice-doc-number input {
        display: none !important;
    }

    /* Display print equivalents injected by JS */
    .print-date-display {
        display: block !important;
        font-weight: 700;
        font-size: 0.95rem;
        color: #1e293b;
    }

    .print-select-val {
        display: block !important;
    }

    /* Print header title */
    .print-only-title {
        display: flex !important;
        flex-direction: column;
        align-items: flex-end;
        margin-bottom: 2rem;
        text-align: right;
        border-bottom: 2px solid #e8ecf1;
        padding-bottom: 1rem;
    }

    .print-doc-type {
        font-size: 2.2rem;
        letter-spacing: 0.2rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .print-doc-devis { color: #f97316; }
    .print-doc-facture { color: #3b82f6; }

    .print-doc-number {
        font-size: 1.1rem;
        font-weight: 700;
        color: #64748b;
        margin-top: 0.2rem;
    }
    
    /* Refine table layout for paper */
    .invoice-paper * {
        box-sizing: border-box !important;
    }

    .lines-table { 
        margin-bottom: 2rem; 
        table-layout: fixed; /* prevent infinite stretch */
        width: 100% !important;
    }
    
    .lines-table thead th { background: #f1f5f9; color: #475569; border-bottom: 2px solid #cbd5e1; font-size: 0.65rem !important; }
    .lines-table tbody tr { border-bottom: 1px solid #e2e8f0; }

    /* Make content lines smaller */
    .lines-table td {
        padding: 0.15rem 0.5rem !important;
        vertical-align: middle !important;
    }

    .lines-table input,
    .lines-table textarea,
    .lines-table .print-select-val,
    .lines-table .line-total {
        font-size: 0.75rem !important;
        padding: 0 !important;
        margin: 0 !important;
        min-height: 0 !important;
        line-height: 1.2 !important;
    }

    /* Fix crucial bug: Hide the action column completely to prevent orphaned cells forcing the table to overflow A4 width */
    .lines-table th:last-child,
    .lines-table td:last-child {
        display: none !important;
    }

    /* Totals styling for paper */
    .invoice-totals {
        border-color: #cbd5e1;
        background: transparent;
        width: 320px;
    }
    
    .total-row.final {
        border-top-color: #cbd5e1;
        font-size: 1.25rem;
    }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================================
   CATEGORY SELECT (Accounting form)
   ============================================================ */

.category-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: 8px;
    padding: 0.65rem 0.875rem;
    font-family: var(--font);
    font-size: 0.88rem;
    width: 100%;
}

/* ============================================================
   MODALS
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

/* Modal ouvert depuis la barre d'outils de l'éditeur : il doit passer
   au-dessus de .editor-overlay (z-index 3000), sinon il s'ouvre derrière. */
#pricingGridsModal {
    z-index: 3500;
}

.modal-box {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}