:root {
    --bg-color: #0a0c13;
    --bg-gradient: linear-gradient(145deg, #0a0c13 0%, #111827 50%, #0f172a 100%);
    --surface-color: rgba(30, 34, 52, 0.7);
    --surface-solid: #1e2234;
    --surface-hover: rgba(40, 45, 65, 0.8);
    --primary-color: #6366f1;
    --primary-light: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --accent-color: #22d3ee;
    --text-primary: #f1f5f9;
    --text-secondary: #7c8db5;
    --text-muted: #4a5578;
    --border-color: rgba(99, 102, 241, 0.12);
    --border-subtle: rgba(255,255,255,0.06);
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --sidebar-width: 300px;
    --glass-blur: blur(16px);
    --glass-bg: rgba(15, 18, 30, 0.75);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.3);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.4);
    --modal-bg: rgba(0, 0, 0, 0.6);
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg-color: #f0f2f7;
    --bg-gradient: linear-gradient(145deg, #e8ecf4 0%, #f0f2f7 50%, #eef1f8 100%);
    --surface-color: rgba(255, 255, 255, 0.85);
    --surface-solid: #ffffff;
    --surface-hover: rgba(245, 247, 252, 0.9);
    --primary-color: #4f46e5;
    --primary-light: #6366f1;
    --primary-glow: rgba(79, 70, 229, 0.2);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: rgba(79, 70, 229, 0.1);
    --border-subtle: rgba(0,0,0,0.06);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.1);
    --modal-bg: rgba(0, 0, 0, 0.3);
    --overlay-bg: rgba(0, 0, 0, 0.2);
}
[data-theme="light"] .sidebar-item.active { color: var(--primary-color); }
[data-theme="light"] #search-input:focus { background: #fff !important; }
[data-theme="light"] .drop-zone { background: rgba(79,70,229,0.03); border-color: rgba(79,70,229,0.2); }
[data-theme="light"] .drop-zone:hover { background: rgba(79,70,229,0.06); border-color: var(--primary-color); }

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

body {
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.app-container {
    width: 100%; padding: 1rem; flex: 1;
    display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

/* ===== HEADER ===== */
.app-header {
    height: 56px; margin-bottom: 0.75rem; display: flex;
    justify-content: space-between; align-items: center; flex-shrink: 0; padding: 0 0.5rem;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-controls { display: flex; align-items: center; gap: 0.5rem; }
.logo h1 {
    font-size: 1.4rem; font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent-color));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.logo p { color: var(--text-muted); font-size: 0.75rem; display: none; }
@media (min-width: 768px) { .logo p { display: block; } }

/* ===== BUTTONS ===== */
.action-btn {
    padding: 0.5rem 1.1rem; font-size: 0.85rem; border-radius: var(--radius-sm);
    cursor: pointer; border: 1px solid transparent; transition: all var(--transition);
    font-family: var(--font-family); display: inline-flex; align-items: center;
    justify-content: center; gap: 0.5rem; font-weight: 500;
}
.action-btn.primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white; box-shadow: 0 4px 16px var(--primary-glow); font-weight: 600;
}
.action-btn.primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px var(--primary-glow); }
.action-btn.secondary { background: transparent; color: var(--text-secondary); font-size: 1.1rem; padding: 0.4rem; }
.action-btn.secondary:hover { color: var(--text-primary); background: var(--surface-color); border-radius: var(--radius-sm); }

.secondary-btn {
    background: var(--surface-color); backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-subtle); color: var(--text-secondary);
    padding: 0.45rem 1rem; border-radius: var(--radius-sm); font-size: 0.82rem;
    cursor: pointer; transition: all var(--transition); font-family: var(--font-family);
}
.secondary-btn:hover { border-color: var(--primary-color); color: var(--primary-light); background: var(--surface-hover); }

.burger-btn {
    display: none; background: var(--surface-color); backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-subtle); color: var(--text-primary); font-size: 1.3rem;
    width: 40px; height: 40px; border-radius: var(--radius-sm); cursor: pointer;
    align-items: center; justify-content: center; transition: all var(--transition); flex-shrink: 0;
}
.burger-btn:hover { border-color: var(--primary-color); background: var(--surface-hover); }

/* ===== UPLOAD ===== */
.upload-container { flex: 1; display: flex; align-items: center; justify-content: center; }
.drop-zone {
    width: 100%; max-width: 520px; padding: 3rem 2rem;
    background: var(--surface-color); backdrop-filter: var(--glass-blur);
    border: 2px dashed var(--border-color); border-radius: var(--radius-xl);
    text-align: center; transition: all 0.3s; cursor: pointer; margin: 1rem;
    box-shadow: var(--shadow-md);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary-color); box-shadow: 0 0 40px var(--primary-glow); }
.drop-zone .icon { font-size: 3rem; margin-bottom: 1rem; animation: float 3s ease-in-out infinite; }
.drop-zone h2 { font-size: 1rem; font-weight: 500; color: var(--text-secondary); }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ===== SPLIT VIEW ===== */
.split-view { display: flex; gap: 0.75rem; flex: 1; height: calc(100% - 70px); overflow: hidden; }

.sidebar {
    width: var(--sidebar-width); background: var(--glass-bg); backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
    display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
@media (max-width: 768px) {
    .split-view { flex-direction: column; }
    .sidebar {
        position: fixed; top: 0; left: 0; width: 85%; max-width: 340px; height: 100vh;
        border-radius: 0 var(--radius-xl) var(--radius-xl) 0; z-index: 1000;
        transform: translateX(-105%); transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
        box-shadow: none; background: var(--surface-solid);
    }
    .sidebar.drawer-open { transform: translateX(0); box-shadow: 4px 0 30px rgba(0,0,0,0.4); }
    .burger-btn { display: flex; }
}

.sidebar-overlay {
    position: fixed; inset: 0; background: var(--overlay-bg); z-index: 999;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

.sidebar-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-subtle);
    background: rgba(99,102,241,0.03);
}
.sidebar-header h3 { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: 0.1em; }
.sidebar-list { list-style: none; overflow-y: auto; flex: 1; padding: 0.4rem; }

.sidebar-item {
    padding: 0.65rem 0.9rem; margin-bottom: 2px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 0.85rem; color: var(--text-secondary);
    display: flex; justify-content: space-between; align-items: center;
    transition: all var(--transition); border: 1px solid transparent;
}
.sidebar-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.sidebar-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(34,211,238,0.06));
    color: var(--text-primary); border-color: var(--border-color);
    box-shadow: 0 2px 8px rgba(99,102,241,0.1);
}

.status-indicator {
    display: none; width: 18px; height: 18px; background: var(--success-color);
    border-radius: 50%; align-items: center; justify-content: center;
    font-size: 10px; color: #fff; margin-left: 8px; box-shadow: 0 2px 6px rgba(52,211,153,0.3);
    flex-shrink: 0;
}
.status-indicator.visible { display: flex; }

/* ===== EDITOR PANEL ===== */
.editor-panel {
    flex: 1; background: var(--glass-bg); backdrop-filter: var(--glass-blur);
    border-radius: var(--radius-lg); border: 1px solid var(--border-subtle);
    display: flex; flex-direction: column; overflow: hidden; position: relative;
    box-shadow: var(--shadow-sm);
}
.editor-header {
    padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border-subtle);
    display: flex; justify-content: space-between; align-items: center;
    background: rgba(99,102,241,0.02); flex-shrink: 0; flex-wrap: wrap; gap: 0.75rem;
}
.editor-header h2 { font-size: 1.05rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-actions { display: flex; align-items: center; gap: 0.4rem; }
@media (max-width: 600px) {
    .editor-header { flex-direction: column; align-items: stretch; padding: 0.75rem; }
    .editor-header h2 { text-align: center; }
    .editor-actions { justify-content: center; width: 100%; }
}

/* ===== PROGRESS BAR ===== */
.progress-bar-container {
    padding: 0 1.25rem 0; flex-shrink: 0;
    background: rgba(99,102,241,0.02); border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.6rem; padding-top: 0.4rem;
}
.progress-info {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.35rem;
}
.progress-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }
.progress-count { font-size: 0.72rem; color: var(--primary-light); font-weight: 600; }
.progress-track {
    width: 100%; height: 4px; background: var(--border-subtle); border-radius: 4px; overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 4px; transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    box-shadow: 0 0 8px var(--primary-glow);
}

/* ===== STICKY CATEGORY HEADER ===== */
.sticky-category-bar {
    position: sticky; top: 0; z-index: 5; padding: 0.5rem 0;
    background: var(--glass-bg); backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-subtle); margin: 0 -2rem 1rem;
    padding-left: 2rem; padding-right: 2rem;
    font-size: 0.78rem; color: var(--primary-light); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em;
    display: none;
}
.sticky-category-bar.visible { display: flex; align-items: center; gap: 0.5rem; }

/* ===== ID CARD ===== */
.id-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(34, 211, 238, 0.05) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}
[data-theme="light"] .id-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(34, 211, 238, 0.02) 100%);
}
.id-card-header {
    display: flex; align-items: center; gap: 0.75rem;
    margin-bottom: 1.2rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}
.id-card-header h2 {
    font-size: 1.25rem; font-weight: 600; color: var(--text-primary); margin: 0;
}
.id-card-header .id-icon { font-size: 1.5rem; }
.id-card-body {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem;
}
.id-card-item { display: flex; flex-direction: column; gap: 0.4rem; }
.id-card-label {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); font-weight: 600;
}
.id-card-value {
    font-size: 0.95rem; color: var(--text-primary); font-weight: 500;
}

/* ===== FORM ===== */
.form-container {
    flex: 1; padding: 1.5rem 2rem; overflow-y: auto; width: 100%;
    margin: 0 auto; max-width: 960px; scroll-behavior: smooth; position: relative;
}
/* Transition animation */
.form-container.fade-out { opacity: 0; transform: translateY(8px); transition: all 0.15s ease-out; }
.form-container.fade-in { opacity: 1; transform: translateY(0); transition: all 0.2s ease-in; }

.form-category { margin-bottom: 2.5rem; }
.form-category h3 {
    color: var(--primary-light); font-size: 0.82rem; margin-bottom: 1.25rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
    display: flex; align-items: center; gap: 0.5rem;
    padding-bottom: 0.6rem; border-bottom: 1px solid var(--border-color);
}
.category-icon { font-size: 1rem; }

.field-group {
    margin-bottom: 1.25rem; padding: 1rem 1.25rem; border-radius: var(--radius-md);
    background: var(--surface-color); border: 1px solid var(--border-subtle);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.field-group:hover { border-color: var(--border-color); }
.field-group:focus-within { border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(99,102,241,0.1); }

.field-question {
    display: block; font-size: 0.9rem; color: var(--text-primary);
    margin-bottom: 0.7rem; line-height: 1.5; font-weight: 500;
}
/* Greyed out question for optional fields */
.field-question.question-optional { color: var(--text-muted); }

.badge-optional {
    display: inline-block; font-size: 0.68rem; color: var(--text-secondary);
    background: rgba(148, 163, 184, 0.15); padding: 0.15rem 0.5rem; border-radius: 20px;
    margin-left: 0.5rem; font-style: normal; font-weight: 600;
    border: 1px solid rgba(148, 163, 184, 0.3);
}
.badge-test-required {
    color: var(--danger-color); font-size: 0.68rem; font-weight: 600; margin-left: 0.5rem;
    background: rgba(248,113,113,0.1); padding: 0.15rem 0.5rem; border-radius: 20px;
    border: 1px solid rgba(248,113,113,0.15);
}

/* ===== INPUTS ===== */
input[type="text"], input[type="number"], input[type="date"], textarea {
    background: rgba(0,0,0,0.2); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; color: var(--text-primary);
    font-family: inherit; font-size: 0.9rem; width: 100%;
    transition: all var(--transition);
}
[data-theme="light"] input[type="text"], [data-theme="light"] input[type="number"],
[data-theme="light"] input[type="date"], [data-theme="light"] textarea {
    background: rgba(0,0,0,0.03);
}
input:focus, textarea:focus {
    outline: none; border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15); background: rgba(99,102,241,0.03);
}
input[type="number"] { width: 140px; }
input[type="date"] { width: auto; min-width: 140px; }
textarea { resize: vertical; min-height: 72px; }

.search-input-themed {
    width: 100%; padding-left: 2.2rem !important;
    background: var(--surface-color) !important; border: 1px solid var(--border-subtle) !important;
    color: var(--text-primary) !important; border-radius: 20px !important;
}
#search-input:focus { background: rgba(99,102,241,0.05) !important; border-color: var(--primary-color) !important; }

.input-disabled, input:disabled, textarea:disabled {
    opacity: 0.5; background: rgba(0,0,0,0.1); cursor: not-allowed;
    border-color: transparent; color: var(--text-muted);
}

/* ===== TOGGLE PILLS (replaces radio buttons) ===== */
.pill-group {
    display: flex; gap: 0; border-radius: var(--radius-sm); overflow: hidden;
    border: 1px solid var(--border-subtle); background: rgba(0,0,0,0.15); width: fit-content;
}
[data-theme="light"] .pill-group { background: rgba(0,0,0,0.04); }
.pill-group.disabled-group { opacity: 0.35; pointer-events: none; filter: grayscale(80%); }

.pill-option {
    position: relative; cursor: pointer; display: flex; align-items: center;
    justify-content: center; font-size: 0.82rem; font-weight: 500;
    color: var(--text-secondary); transition: all var(--transition);
    padding: 0.5rem 1.2rem; border-right: 1px solid var(--border-subtle);
    user-select: none;
}
.pill-option:last-child { border-right: none; }
.pill-option:hover { color: var(--text-primary); background: rgba(99,102,241,0.05); }
.pill-option input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

.pill-option.selected {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white; box-shadow: 0 2px 8px var(--primary-glow);
}
.pill-option.selected-success {
    background: linear-gradient(135deg, #059669, var(--success-color));
    color: white; box-shadow: 0 2px 8px rgba(52,211,153,0.3);
}
.pill-option.selected-danger {
    background: linear-gradient(135deg, #dc2626, var(--danger-color));
    color: white; box-shadow: 0 2px 8px rgba(248,113,113,0.3);
}

/* ===== GREY TOGGLE ===== */
.grey-toggle-wrapper { position: relative; display: flex; align-items: center; }
.grey-toggle-checkbox {
    width: 15px; height: 15px; cursor: pointer; accent-color: var(--text-muted);
    opacity: 0.4; transition: opacity 0.2s;
}
.grey-toggle-checkbox:hover { opacity: 0.8; }
.grey-toggle-checkbox:checked { accent-color: var(--primary-light); opacity: 1; }
.grey-toggle-wrapper .tooltip-text {
    visibility: hidden; opacity: 0; position: absolute; right: calc(100% + 8px); top: 50%;
    transform: translateY(-50%); background: var(--surface-solid); color: var(--text-secondary);
    font-size: 0.7rem; padding: 0.3rem 0.6rem; border-radius: 6px; white-space: nowrap;
    border: 1px solid var(--border-subtle); box-shadow: var(--shadow-md);
    transition: opacity 0.2s, visibility 0.2s; pointer-events: none; z-index: 10;
}
.grey-toggle-wrapper:hover .tooltip-text { visibility: visible; opacity: 1; }

.disabled-group {
    pointer-events: none;
}
.disabled-group > *:not(:first-child) {
    opacity: 0.35;
    filter: grayscale(80%);
}
/* Keep the header wrapper (label + checkbox) fully visible and interactive */
.disabled-group > div:first-child {
    pointer-events: auto;
    opacity: 1;
    filter: none;
}
/* Label stays readable even when group is disabled */
.disabled-group .grey-toggle-checkbox, .disabled-group .grey-toggle-wrapper {
    pointer-events: auto; filter: none; opacity: 1;
}

/* Readonly fields (Structural: Bâtiments, etc.) - functionally disabled but full opacity */
.pill-group.readonly-group {
    pointer-events: none; cursor: not-allowed;
}
.input-readonly {
    pointer-events: none; cursor: not-allowed;
    background: rgba(0,0,0,0.1) !important;
}
[data-theme="light"] .input-readonly {
    background: rgba(0,0,0,0.02) !important;
}

/* ===== FAB BUTTONS ===== */
.fab-btn, .fab-scroll-top {
    position: fixed; width: 46px; height: 46px; border-radius: 50%;
    color: white; border: none; cursor: pointer; display: flex;
    align-items: center; justify-content: center; z-index: 100;
    transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow: var(--shadow-md);
}
.fab-btn {
    bottom: 28px; right: 28px; font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
}
.fab-btn:hover { transform: scale(1.12); box-shadow: 0 8px 24px var(--primary-glow); }
.fab-scroll-top {
    bottom: 84px; right: 28px; font-size: 1rem;
    background: var(--surface-color); backdrop-filter: var(--glass-blur);
    color: var(--text-secondary); border: 1px solid var(--border-subtle);
    opacity: 0; pointer-events: none; transform: translateY(10px);
}
.fab-scroll-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.fab-scroll-top:hover { color: var(--primary-light); border-color: var(--primary-color); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0; background: var(--modal-bg); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; z-index: 2000;
    animation: fadeIn 0.15s ease; padding: 1rem;
}
.modal-dialog {
    background: var(--surface-solid); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl); padding: 2rem; max-width: 400px; width: 100%;
    text-align: center; box-shadow: var(--shadow-lg); animation: modalSlideIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.modal-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.4rem; }
.modal-message { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }
.modal-btn {
    padding: 0.55rem 1.4rem; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 500;
    cursor: pointer; border: 1px solid var(--border-subtle); background: var(--surface-color);
    color: var(--text-secondary); font-family: var(--font-family); transition: all var(--transition);
}
.modal-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.modal-btn.modal-btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white; border-color: transparent; box-shadow: 0 4px 12px var(--primary-glow);
}
.modal-btn.modal-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px var(--primary-glow); }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.empty-state { text-align: center; margin-top: 20%; color: var(--text-muted); font-size: 0.9rem; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalSlideIn { from { transform: scale(0.92) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }