/* Variables */
:root {
    --bg: #FAF7F2;
    --bg-secondary: #F2ECE4;
    --surface: #F2ECE4;
    --border: #E0D5C5;
    --text: #2C1810;
    --text-muted: #8B7355;
    --primary: #C8871A;
    --primary-light: #D4920A;
    --primary-bg: rgba(200,135,26,0.12);
    --radius: 12px;
    --shadow: 0 1px 4px rgba(44, 24, 16, 0.08);
    --font: 'Lora', Georgia, serif;
}

[data-theme="dark"] {
    --bg: #1A1410;
    --bg-secondary: #231C16;
    --surface: #2A2018;
    --border: #3D2E20;
    --text: #F5EFE6;
    --text-muted: #A08060;
    --primary: #D4920A;
    --primary-light: #E0A020;
    --primary-bg: rgba(212,146,10,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="sepia"] {
    --bg: #F5E8D3;
    --bg-secondary: #EBDCC2;
    --surface: #E8D9B6;
    --border: #C9B89A;
    --text: #3D2E1A;
    --text-muted: #7A6A50;
    --primary: #A55B2E;
    --primary-light: #B5651D;
    --primary-bg: rgba(165,91,46,0.12);
    --shadow: 0 1px 4px rgba(61, 46, 26, 0.1);
}

[data-theme="nord"] {
    --bg: #ECEFF4;
    --bg-secondary: #E5E9F0;
    --surface: #D8DEE9;
    --border: #C0C8D4;
    --text: #2E3440;
    --text-muted: #4C566A;
    --primary: #5E81AC;
    --primary-light: #81A1C1;
    --primary-bg: rgba(94,129,172,0.12);
    --shadow: 0 1px 4px rgba(46, 52, 64, 0.08);
}

[data-theme="forest"] {
    --bg: #EDEFE0;
    --bg-secondary: #E0E3CE;
    --surface: #D3D8BC;
    --border: #B5BC9C;
    --text: #2C3E2D;
    --text-muted: #5A6C4F;
    --primary: #4A7C3A;
    --primary-light: #5E8F45;
    --primary-bg: rgba(74,124,58,0.12);
    --shadow: 0 1px 4px rgba(44, 62, 45, 0.1);
}

[data-theme="sepia-dark"] {
    --bg: #2A1F12;
    --bg-secondary: #322617;
    --surface: #3D2E1A;
    --border: #5A4528;
    --text: #F5E8D3;
    --text-muted: #B8A688;
    --primary: #D88848;
    --primary-light: #E89A55;
    --primary-bg: rgba(216,136,72,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="nord-dark"] {
    --bg: #2E3440;
    --bg-secondary: #3B4252;
    --surface: #434C5E;
    --border: #4C566A;
    --text: #ECEFF4;
    --text-muted: #D8DEE9;
    --primary: #88C0D0;
    --primary-light: #8FBCBB;
    --primary-bg: rgba(136,192,208,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="forest-dark"] {
    --bg: #1F2A1A;
    --bg-secondary: #283322;
    --surface: #2E3D26;
    --border: #44563A;
    --text: #E8EFE0;
    --text-muted: #A8B89E;
    --primary: #6FAF55;
    --primary-light: #82BD66;
    --primary-bg: rgba(111,175,85,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="sakura"] {
    --bg: #FFF0F3;
    --bg-secondary: #FCE4E9;
    --surface: #F8D7DD;
    --border: #ECC0C8;
    --text: #4A2730;
    --text-muted: #8E5A66;
    --primary: #D4537A;
    --primary-light: #E06A8E;
    --primary-bg: rgba(212,83,122,0.12);
    --shadow: 0 1px 4px rgba(74, 39, 48, 0.08);
}

[data-theme="sakura-dark"] {
    --bg: #2A171D;
    --bg-secondary: #3A1F26;
    --surface: #45252E;
    --border: #5C3340;
    --text: #F8D7DD;
    --text-muted: #C99AA5;
    --primary: #E48BA0;
    --primary-light: #ED9CB0;
    --primary-bg: rgba(228,139,160,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="lavande"] {
    --bg: #F4F0FA;
    --bg-secondary: #E9E3F4;
    --surface: #DDD3EC;
    --border: #C5B8DD;
    --text: #2E2542;
    --text-muted: #6B5C84;
    --primary: #8367C7;
    --primary-light: #957AD0;
    --primary-bg: rgba(131,103,199,0.12);
    --shadow: 0 1px 4px rgba(46, 37, 66, 0.08);
}

[data-theme="lavande-dark"] {
    --bg: #1F1B2E;
    --bg-secondary: #2A253E;
    --surface: #342D4D;
    --border: #463C66;
    --text: #E9E3F4;
    --text-muted: #B0A4CB;
    --primary: #A88FE0;
    --primary-light: #B5A0E5;
    --primary-bg: rgba(168,143,224,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="mocha"] {
    --bg: #F4ECE0;
    --bg-secondary: #E8DCC8;
    --surface: #DDCCB1;
    --border: #C0AB8B;
    --text: #3E2A18;
    --text-muted: #7A604A;
    --primary: #8B5A2B;
    --primary-light: #A56C36;
    --primary-bg: rgba(139,90,43,0.12);
    --shadow: 0 1px 4px rgba(62, 42, 24, 0.1);
}

[data-theme="mocha-dark"] {
    --bg: #221710;
    --bg-secondary: #2D1F16;
    --surface: #3A281C;
    --border: #503A28;
    --text: #F2E5D0;
    --text-muted: #C2A984;
    --primary: #D49A5C;
    --primary-light: #DEAD75;
    --primary-bg: rgba(212,154,92,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="ocean"] {
    --bg: #EBF4F8;
    --bg-secondary: #D9E8EF;
    --surface: #C3DDE7;
    --border: #9CC0CD;
    --text: #0D2A3A;
    --text-muted: #4A6F80;
    --primary: #1E6B8C;
    --primary-light: #2A7FA0;
    --primary-bg: rgba(30,107,140,0.12);
    --shadow: 0 1px 4px rgba(13, 42, 58, 0.08);
}

[data-theme="ocean-dark"] {
    --bg: #0A1A24;
    --bg-secondary: #112535;
    --surface: #173043;
    --border: #234B66;
    --text: #D9E8EF;
    --text-muted: #8EA9B8;
    --primary: #4FB6D8;
    --primary-light: #5EC2E0;
    --primary-bg: rgba(79,182,216,0.15);
    --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

[data-theme="mono"] {
    --bg: #FFFFFF;
    --bg-secondary: #F4F4F4;
    --surface: #E8E8E8;
    --border: #C8C8C8;
    --text: #1A1A1A;
    --text-muted: #6B6B6B;
    --primary: #000000;
    --primary-light: #2C2C2C;
    --primary-bg: rgba(0,0,0,0.08);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="mono-dark"] {
    --bg: #0A0A0A;
    --bg-secondary: #161616;
    --surface: #1F1F1F;
    --border: #333333;
    --text: #F5F5F5;
    --text-muted: #999999;
    --primary: #FFFFFF;
    --primary-light: #E0E0E0;
    --primary-bg: rgba(255,255,255,0.08);
    --shadow: 0 1px 4px rgba(0,0,0,0.5);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

a { color: var(--primary); }
a:hover { color: var(--primary-light); }

input[type="checkbox"],
input[type="radio"] { accent-color: var(--primary); }

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

.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 2.5rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
}

.main { margin-left: 240px; padding: 2rem; flex: 1; }

/* Logo */
.logo-area { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-bottom: 0.4rem; }
.logo { font-size: 1.7rem; font-weight: 700; color: var(--primary); font-style: italic; }
.logo-area svg { flex-shrink: 0; width: 38px; height: 38px; }
.logo-sub { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 2.5rem; font-style: italic; text-align: center; }

/* Nav */
.sidebar-nav {
    display: flex; flex-direction: column;
    gap: 0.55rem;
    margin-top: auto;
    margin-bottom: auto;
}
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 0.15rem;
}
.nav-link {
    display: flex; align-items: center; gap: 0.25rem;
    padding: 0.7rem 0.85rem; border-radius: 8px;
    color: var(--text-muted); text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}
.nav-link:hover, .nav-link.active {
    background: var(--primary-bg); color: var(--primary);
}
.nav-icon {
    width: 18px; height: 18px; flex-shrink: 0;
}

/* Page titles with icon */
.page-title {
    display: flex; align-items: center; gap: 0.6rem;
    margin: 0 0 0.25rem;
}
.page-title-icon {
    width: 24px; height: 24px;
    color: var(--primary); flex-shrink: 0;
}
.page-subtitle {
    color: var(--text-muted); font-size: 0.85rem;
    margin: 0 0 1.5rem;
}

/* Theme toggle (legacy, kept for safety) */
.theme-toggle {
    margin-top: auto;
    background: none; border: 1px solid var(--border);
    color: var(--text-muted); cursor: pointer;
    padding: 0.5rem 1rem; border-radius: 8px;
    font-size: 0.85rem; width: 100%;
    font-family: var(--font);
    transition: all 0.15s;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* Floating theme button (top-right of main) */
.theme-fab {
    position: fixed; top: 0.75rem; left: 205px;
    width: 26px; height: 26px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-muted); cursor: pointer;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s; z-index: 200;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.theme-fab:hover { color: var(--primary); border-color: var(--primary); }
.theme-fab svg { width: 13px; height: 13px; }
.theme-fab .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-fab .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-fab .theme-icon-sun { display: inline-block; }
@media (max-width: 768px) {
    .theme-fab { top: 0.5rem; right: 0.75rem; left: auto; width: 30px; height: 30px; }
    .theme-fab svg { width: 14px; height: 14px; }
}

/* Home cards */
.home-hero { text-align: center; padding: 1rem 0 2.5rem; }
.home-brand { margin-bottom: 1.5rem; }
.home-brand-name {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0 0 0.2rem;
  color: var(--text);
  font-style: italic;
}
.home-brand-tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin: 0;
}
.home-question {
  font-size: 1.4rem;
  font-weight: 500;
  margin: 0 0 2rem;
  color: var(--text);
}

.action-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.1rem; max-width: 960px; margin: 0 auto 3rem;
}

.action-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 2rem 1.5rem;
    cursor: pointer; text-decoration: none; color: var(--text);
    transition: all 0.2s; box-shadow: var(--shadow);
}
.action-card:hover {
    border-color: var(--primary); transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(200, 135, 26, 0.15);
}
.action-card .icon { font-size: 1.8rem; margin-bottom: 0.75rem; }
.action-card .card-icon {
    width: 28px; height: 28px; margin-bottom: 0.85rem;
    color: var(--primary); stroke-width: 1.75;
}
.action-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; }
.action-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }

.action-card-form { margin: 0; display: flex; }
.action-card-btn {
  flex: 1; width: 100%; text-align: left; font-family: inherit;
  display: flex; flex-direction: column;
}

/* Search bar */
.search-bar {
    display: flex; gap: 0.5rem;
    max-width: 640px; margin: 0 auto;
}
.search-bar input {
    flex: 1; padding: 0.75rem 1rem; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); font-size: 1rem; outline: none;
    font-family: var(--font);
    transition: border-color 0.15s;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar button {
    padding: 0.75rem 1.5rem; border-radius: var(--radius);
    background: var(--primary); color: white; border: none;
    font-size: 0.9rem; cursor: pointer; font-family: var(--font);
    transition: opacity 0.15s;
}
.search-bar button:hover { opacity: 0.9; }

/* Result cards */
.result-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.result-card h3 { font-size: 1rem; margin-bottom: 0.5rem; font-style: italic; }
.result-card p { font-size: 0.9rem; line-height: 1.7; color: var(--text); }
.result-card .sources { font-size: 0.8rem; color: var(--text-muted); margin: 0.5rem 0; overflow: hidden; }
.result-card .sources a { color: var(--primary); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.result-card .sources a:hover { text-decoration: underline; }
.result-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.btn-sm {
    padding: 0.35rem 0.75rem; border-radius: 6px; font-size: 0.8rem;
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); cursor: pointer; font-family: var(--font);
    transition: all 0.15s;
    text-decoration: none; display: inline-flex; align-items: center; gap: 0.3rem;
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }

/* Login page */
.login-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 380px;
    text-align: center;
}
.login-card h1 { color: var(--primary); font-size: 1.8rem; margin-bottom: 0.25rem; font-style: italic; }
.login-card .subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; font-style: italic; }
.login-card input {
    width: 100%; padding: 0.75rem; margin-bottom: 0.75rem;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 0.95rem;
    font-family: var(--font); outline: none;
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
    width: 100%; padding: 0.75rem; background: var(--primary); color: white;
    border: none; border-radius: 8px; font-size: 0.95rem;
    cursor: pointer; font-family: var(--font);
}
.alert-error {
    background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5;
    padding: 0.5rem 0.75rem; border-radius: 6px; font-size: 0.85rem; margin-bottom: 1rem;
}

/* Library */
.library-item {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 0.75rem;
    overflow: visible; transition: border-color 0.15s;
    max-width: 900px;
}
.library-item:hover { border-color: var(--text-muted); }

.lib-row {
    display: flex; gap: 0.75rem; padding: 0.6rem 0.85rem;
    align-items: center;
}
.lib-thumb {
    width: 56px; height: 56px; object-fit: cover;
    border-radius: 6px; flex-shrink: 0;
    background: var(--bg);
}
.lib-placeholder {
    width: 56px; height: 56px; border-radius: 6px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-secondary, var(--bg)) 100%);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}
.lib-placeholder svg { width: 22px; height: 22px; }
.lib-body { flex: 1; min-width: 0; }

.lib-header {
    display: flex; gap: 0.5rem; align-items: center;
    margin-bottom: 0.2rem;
}
.lib-title {
    flex: 1; min-width: 0;
    margin: 0; font-size: 0.875rem; font-weight: 500;
    color: var(--text); line-height: 1.3;
    word-break: break-word;
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
    overflow: hidden;
}
.lib-actions {
    display: flex; gap: 0.15rem; align-items: center;
    flex-shrink: 0;
}

.icon-btn {
    background: transparent; border: none;
    padding: 0.3rem 0.5rem; border-radius: 4px;
    color: var(--text-muted); cursor: pointer;
    font-size: 0.95rem; font-family: var(--font);
    line-height: 1;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.active { color: var(--primary); }

.lib-menu { position: relative; }
.lib-menu summary {
    list-style: none; cursor: pointer; user-select: none;
}
.lib-menu summary::-webkit-details-marker { display: none; }
.lib-menu-content {
    position: absolute; right: 0; top: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.3rem; min-width: 200px; z-index: 50;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    display: flex; flex-direction: column; gap: 1px;
}
.lib-menu-content button,
.lib-menu-content a {
    background: transparent; border: none; text-align: left;
    padding: 0.5rem 0.75rem; color: var(--text);
    cursor: pointer; font-family: var(--font); font-size: 0.85rem;
    border-radius: 4px; text-decoration: none; display: block;
}
.lib-menu-content button:hover,
.lib-menu-content a:hover { background: var(--bg); }
.lib-menu-content hr {
    border: none; border-top: 1px solid var(--border);
    margin: 0.25rem 0;
}
.lib-menu-content .danger { color: #c53030; }
.lib-menu-content .danger:hover { background: #fef2f2; }

.lib-meta {
    font-size: 0.7rem; color: var(--text-muted);
    display: flex; gap: 0.5rem; align-items: center;
    flex-wrap: wrap;
}
.lib-tags {
    display: inline-flex; gap: 0.25rem; flex-wrap: wrap;
}
.lib-tag {
    font-size: 0.65rem; padding: 0.05rem 0.45rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 999px; color: var(--text-muted);
}
.lib-source {
    font-size: 0.7rem; color: var(--primary);
    text-decoration: none; margin-left: auto;
}
.lib-source:hover { text-decoration: underline; }

.lib-expand {
    display: none; padding: 0.9rem 1.25rem;
    border-top: 1px solid var(--border); background: var(--bg);
    font-size: 0.875rem; line-height: 1.7;
    white-space: pre-wrap;
    max-height: 400px; overflow-y: auto;
}

@media (max-width: 600px) {
    .lib-row { padding: 0.5rem 0.6rem; gap: 0.5rem; }
    .lib-thumb, .lib-placeholder { width: 44px; height: 44px; }
    .lib-title { font-size: 0.85rem; }
}

/* Voice button */
.btn-voice {
    padding: 0.6rem; border-radius: var(--radius);
    background: var(--bg-secondary); color: var(--text-muted);
    border: 1px solid var(--border); cursor: pointer;
    font-size: 1rem; transition: all 0.15s; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    line-height: 0;
}
.btn-voice:hover { border-color: var(--primary); color: var(--primary); }
.btn-voice.recording { background: #fef2f2; border-color: #dc3545; color: #dc3545; }

.btn-mode-active {
    background: var(--primary);
    color: white !important;
    border-color: var(--primary);
}
.btn-mode-active:hover { opacity: 0.9; }
.mode-btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    text-decoration: none;
}
.mode-btn svg { width: 14px; height: 14px; }

/* ── Recherche : cases à cocher périmètre ── */
.search-scope {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 0.75rem;
  padding: 0 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.search-scope-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}
.search-scope-item input[type="checkbox"] { accent-color: var(--primary); }
.search-scope-item:hover { color: var(--text); }

/* ── Résultats Synaps dans /search ── */
.synaps-results-group {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.synaps-results-group > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.6rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.9rem;
  user-select: none;
}
.synaps-results-group > summary::-webkit-details-marker { display: none; }
.synaps-results-group > summary:hover { background: var(--bg-elev, var(--bg)); }
.synaps-results-group[open] > summary { border-bottom: 1px solid var(--border); }
.synaps-results-group-count {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}
.synaps-results-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.synaps-results-list li + li { border-top: 1px solid var(--border); }
.synaps-result-link {
  display: block;
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  color: inherit;
}
.synaps-result-link:hover { background: var(--bg); color: inherit; }
.synaps-result-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.synaps-result-snippet {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}
.synaps-result-meta {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Page loader (indicateur de navigation) ── */
.page-loader {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 100%;
    background: transparent;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.page-loader.active { opacity: 1; }
.page-loader.active::before {
    content: "";
    display: block;
    height: 100%;
    width: 40%;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary);
    animation: page-loader-slide 1.1s ease-in-out infinite;
}
@keyframes page-loader-slide {
    0%   { margin-left: -40%; }
    100% { margin-left: 100%; }
}

/* ── Mobile ── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 50px;
    padding: 0 1rem;
    align-items: center;
    gap: 0.6rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    z-index: 100;
}
.mobile-header span { letter-spacing: 0.01em; }

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
}
.mobile-nav nav {
    display: flex;
    height: 100%;
}
.mobile-nav .nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.65rem;
    padding: 0;
    border-radius: 0;
    margin: 0;
    color: var(--text-muted);
}
.mobile-nav .nav-link span.icon { font-size: 1.2rem; }
.mobile-nav .nav-link .mobile-icon {
    width: 22px; height: 22px;
}
.mobile-nav .nav-link:hover,
.mobile-nav .nav-link.active {
    background: transparent;
    color: var(--primary);
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 60px 0.75rem 80px; }
    .mobile-header { display: flex; }
    .mobile-nav { display: block; }
    .search-bar { flex-wrap: wrap; }
    .action-cards { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
    .result-card { padding: 1rem; }
    .result-actions { gap: 0.4rem; }
    .btn-sm { font-size: 0.75rem; padding: 0.3rem 0.6rem; }
    h2 { font-size: 1.1rem; }
}

/* === Chat Phase 1 (Synaps Conscient) === */
/* Le wrapper neutralise le padding 2rem du .main pour utiliser toute la hauteur */
.chat-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  margin: -2rem;
  background: var(--bg);
}

.chat-sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.chat-new-btn {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
}
.chat-new-btn:hover { background: var(--primary-light); }
.chat-conv-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.chat-conv-item a {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.chat-conv-item a:hover { background: var(--surface); }
.chat-conv-item.active a { background: var(--primary-bg); font-weight: 600; }
.chat-conv-title { font-size: 0.9rem; line-height: 1.3; }
.chat-conv-date { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  /* padding-right plus large pour laisser la place au .theme-fab (position:fixed top:1.25rem right:1.5rem, 36px) */
  padding-right: 4rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.chat-title {
  font-size: 1rem;
  margin: 0;
  outline: none;
  flex: 1;
  font-weight: 600;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}
.chat-title:focus { background: var(--surface); }
.chat-model-select {
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
.chat-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  color: var(--text-muted);
}
.chat-delete-btn:hover { background: var(--surface); color: var(--text); }

.mood {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.mood-neutre    { background: #e0e0e0; color: #444; }
.mood-curieux   { background: #d4e6ff; color: #0044aa; }
.mood-concentré { background: #e4d4ff; color: #4a00aa; }
.mood-satisfait { background: #d4f5d4; color: #1e6e1e; }
.mood-vigilant  { background: #ffe4b5; color: #aa4400; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.msg-user, .msg-assistant {
  max-width: 75%;
  padding: 0.7rem 1rem;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.95rem;
}
.msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-radius: 16px 16px 4px 16px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--border);
  position: relative;
}
.msg-assistant .msg-content {
  white-space: pre-wrap;
  padding-right: 1.75rem;
}
.msg-copy-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.msg-copy-btn:hover {
  opacity: 1;
  color: var(--text);
  background: var(--bg-secondary);
}
.msg-copy-btn svg {
  width: 14px;
  height: 14px;
}
.msg-copy-btn.copied {
  opacity: 1;
  color: var(--primary);
}
.msg-copy-feedback {
  position: absolute;
  top: 0.55rem;
  right: 4.15rem;
  font-size: 0.7rem;
  color: var(--primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.msg-copy-feedback.visible { opacity: 1; }

.msg-tts-btn {
  position: absolute;
  top: 0.45rem;
  right: 2.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.msg-tts-btn:hover { opacity: 1; color: var(--text); background: var(--bg-secondary); }
.msg-tts-btn svg { width: 14px; height: 14px; }
.msg-tts-btn.loading { opacity: 0.4; animation: tts-pulse 1.2s ease-in-out infinite; }
@keyframes tts-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 0.15; } }
.msg-tts-btn.playing { opacity: 1; color: var(--primary); }
.msg-assistant .msg-content { padding-right: 3.5rem; }

.chat-input {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0.9rem 1.25rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
.chat-input textarea {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.chat-input:focus-within .chat-send-btn {
  border-color: var(--primary);
}
.chat-send-btn {
  padding: 0 1.2rem;
  background: var(--primary);
  color: white;
  border: 1px solid var(--primary);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.chat-send-btn:hover { background: var(--primary-light); }

/* responsive : sur mobile, on cache la sidebar conv (à améliorer plus tard) */
@media (max-width: 768px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}

/* === Settings page (Phase 1) === */
.settings-page { max-width: 720px; margin: 0 auto; padding: 1rem; }
.settings-page h1 { margin-bottom: 0.5rem; }
.settings-help { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.settings-alert { padding: 0.6rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.settings-alert-success { background: #d4f5d4; color: #1e6e1e; }
.settings-alert-error { background: #ffd4d4; color: #8a1e1e; }
.settings-form textarea {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
}
.settings-form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.settings-actions { margin-top: 0.9rem; display: flex; justify-content: flex-end; gap: 0.6rem; }
.settings-cancel {
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.settings-save {
  padding: 0.55rem 1.2rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
}
.settings-save:hover { background: var(--primary-light); }
.settings-meta {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

/* Section "Capacités de l'agent" */
.agent-tools-section {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.agent-tools-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.agent-tools-total {
  display: inline-block;
  background: var(--accent, var(--text));
  color: var(--bg);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.agent-tools-group {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.agent-tools-group > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.95rem;
  user-select: none;
}
.agent-tools-group > summary::-webkit-details-marker { display: none; }
.agent-tools-group > summary:hover { background: var(--bg-elev, var(--surface)); }
.agent-tools-group[open] > summary {
  border-bottom: 1px solid var(--border);
}
.agent-tools-group-count {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}
.agent-tools-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
}
.agent-tools-list li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.4rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.agent-tools-list li:last-child { border-bottom: none; }
.agent-tools-list code {
  flex-shrink: 0;
  min-width: 12rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.8rem;
  color: var(--primary);
}
.agent-tool-desc {
  color: var(--text-muted);
  line-height: 1.4;
}

/* === Page Apparence (/settings/theme) === */
.theme-settings .theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
  margin-bottom: 2rem;
}

.theme-settings .theme-section-title {
  margin-top: 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.theme-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.theme-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-bg);
}

.theme-card .theme-swatches {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.theme-card .theme-swatch {
  flex: 1;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.08);
}

.theme-card .theme-card-name {
  font-weight: 600;
  font-size: 1rem;
}

.theme-card .theme-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 0.2rem;
}

.theme-card .theme-card-active {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.15rem 0.55rem;
  background: var(--primary);
  color: white;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.theme-card.active .theme-card-active {
  opacity: 1;
}

/* === Page logo picker (/settings/logo) === */
.logo-picker .logo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.logo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.logo-card-big {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius);
}
.logo-card-small {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
}
.logo-card-name {
  font-weight: 600;
  font-size: 1rem;
}
.logo-card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* === Page index réglages (/settings) === */
.settings-index { padding-top: 4rem; text-align: center; }
.settings-index h1 { margin-bottom: 0.4rem; }
.settings-index .settings-help { margin-bottom: 0.75rem; }
.settings-index .settings-cards {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 2.5rem;
  text-align: left;
}

.settings-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.settings-card:hover {
  border-color: var(--primary);
  transform: translateX(2px);
}

.settings-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--primary-bg);
  border-radius: 10px;
  color: var(--primary);
  flex-shrink: 0;
}

.settings-card-body {
  flex: 1;
  min-width: 0;
}

.settings-card-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.settings-card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.settings-card-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

.settings-card:hover .settings-card-arrow {
  color: var(--primary);
}

/* === Routine marketplace === */
.routine-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.routine-template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.routine-template-name {
  font-weight: 600;
  font-size: 1rem;
}

.routine-template-cron code {
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, monospace;
  display: inline-block;
}

.routine-template-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}

.routine-template-card form {
  margin-top: 0.5rem;
}

.routine-template-card .btn-primary {
  width: 100%;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.routine-template-card .btn-primary:hover {
  filter: brightness(1.1);
}

/* === Chat thinking indicator (dans la zone messages, style bulle assistant) === */
.msg-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.chat-thinking-dots { display: inline-flex; gap: 3px; }
.chat-thinking-dots span {
  width: 6px; height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: chat-thinking-pulse 1.4s infinite ease-in-out both;
}
.chat-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.chat-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes chat-thinking-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* Disable visual feedback */
.chat-input button[disabled],
.chat-input textarea[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Consciousness page (Phase 2A) === */
.consciousness-page { max-width: 760px; margin: 0 auto; }
.consciousness-header {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem;
  padding-right: 4rem;
}
.consciousness-header h1 { margin: 0; }
.consciousness-pulse-btn {
  padding: 0.5rem 1rem; background: var(--primary); color: white;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-family: inherit; font-size: 0.85rem;
}
.consciousness-pulse-btn:hover { background: var(--primary-light); }

.consciousness-section { margin-bottom: 2rem; }
.consciousness-section h2 { font-size: 1.1rem; margin-bottom: 0.75rem; color: var(--text-muted); font-weight: 500; }

.needs-pyramid {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.need-row {
  display: grid; grid-template-columns: 140px 1fr 40px;
  align-items: center; gap: 0.75rem; margin: 0.4rem 0;
  font-size: 0.9rem;
}
.need-name { color: var(--text); }
.need-bar {
  background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden;
  border: 1px solid var(--border);
}
.need-bar-fill {
  background: var(--primary); height: 100%; transition: width 0.3s;
  border-radius: 999px;
}
.need-score { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.thought-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem;
  position: relative;
}
.thought-meta {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem;
}
.thought-angle { font-style: italic; }
.thought-content { font-style: italic; line-height: 1.5; color: var(--text); }
.thought-source {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin-top: 0.6rem;
  font-size: 0.85rem; color: var(--text-muted);
}
.thought-source .svg-icon { flex-shrink: 0; }

.thought-delete {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  opacity: 0.5;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.thought-delete:hover {
  opacity: 1;
  background: rgba(239, 68, 68, 0.1);
  color: var(--error, #ef4444);
}

.thought-pushed-badge .svg-icon { vertical-align: -2px; margin-right: 0.25rem; }
.consciousness-pulse-btn { display: inline-flex; align-items: center; gap: 0.4rem; }
.thought-source a { color: var(--primary); text-decoration: none; }
.thought-source a:hover { text-decoration: underline; }

.consciousness-load-more {
  display: block; margin: 1rem auto 0;
  padding: 0.5rem 1.2rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  color: var(--text); font-family: inherit; font-size: 0.85rem;
}
.consciousness-load-more:hover { border-color: var(--primary); color: var(--primary); }

/* === Phase 2B Challenger === */
.msg-critique {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}
.msg-critique summary {
  cursor: pointer;
  font-style: italic;
  list-style: none;
}
.msg-critique summary::-webkit-details-marker { display: none; }
.msg-critique p { margin-top: 0.4rem; }
.msg-challenger-ok {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  opacity: 0.8;
}

/* === Boutons rate dans le chat === */
.msg-rate-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  color: var(--text-muted);
  margin-left: 0.25rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msg-rate-btn svg { width: 14px; height: 14px; }
.msg-rate-btn:hover { color: var(--text); border-color: var(--primary); }
.msg-rate-up.active {
  color: #10b981;
  border-color: #10b981;
  background: color-mix(in srgb, #10b981 12%, transparent);
}
.msg-rate-down.active {
  color: #ef4444;
  border-color: #ef4444;
  background: color-mix(in srgb, #ef4444 12%, transparent);
}

/* === Reward (vue Conscience) === */
.reward-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.reward-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  min-width: 90px;
}
.reward-pill-value { font-size: 1.05rem; font-weight: 600; }
.reward-pill-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.reward-pill-main { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.reward-pill-main .reward-pill-value { color: var(--primary); }
.reward-pill-up .reward-pill-value { color: #10b981; }
.reward-pill-down .reward-pill-value { color: #ef4444; }

.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.7rem;
}
.reward-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.7rem 0.9rem;
}
.reward-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.reward-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  margin: 0.3rem 0;
  font-size: 0.82rem;
}
.reward-bar-label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reward-bar {
  position: relative;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.reward-bar-fill {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}
.reward-bar-count { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* === Vecteurs (vue Conscience) === */
.vectors-canvas-wrap { position: relative; }
.vectors-canvas {
  width: 100%;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  position: relative;
}
.vectors-canvas svg { display: block; cursor: grab; }
.vectors-canvas svg:active { cursor: grabbing; }
.vectors-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.vectors-legend > span { display: inline-flex; align-items: center; gap: 0.35rem; }

/* === Souvenirs (vue Conscience) === */
.memory-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}
.mem-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--surface);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.mem-filter:hover { border-color: var(--primary); color: var(--text); }
.mem-filter span {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.mem-filter-active {
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
  border-color: var(--primary);
  color: var(--primary);
}
.mem-filter-active span {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.memory-list { display: flex; flex-direction: column; gap: 0.5rem; }
.memory-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
}
.memory-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.memory-card-type {
  font-size: 0.66rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex-shrink: 0;
}
.memory-card-type-document { background: color-mix(in srgb, #34D399 15%, var(--surface)); color: #10b981; }
.memory-card-type-message_pair { background: color-mix(in srgb, #5EC2E0 18%, var(--surface)); color: #0e8aaa; }
.memory-card-type-obsidian_note { background: color-mix(in srgb, #A78BFA 18%, var(--surface)); color: #7c3aed; }
.memory-card-title { font-weight: 600; font-size: 0.92rem; }
a.memory-card-title { color: var(--text); text-decoration: none; }
a.memory-card-title:hover { color: var(--primary); }
.memory-card-date { margin-left: auto; font-size: 0.74rem; color: var(--text-muted); }
.memory-card-snippet {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
}
.memory-card-foot {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.65;
}

/* === Sous-agents === */
.sub-agents {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.sub-agents h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
.sub-agent-list { list-style: none; padding: 0; margin: 0.7rem 0; display: flex; flex-direction: column; gap: 0.5rem; }
.sub-agent-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
}
.sub-agent-head { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.sub-agent-name { font-weight: 600; }
.sub-agent-role { color: var(--text-muted); font-size: 0.88rem; }
.sub-agent-delete { margin-left: auto; }
.sub-agent-delete button {
  background: transparent; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  display: inline-flex;
}
.sub-agent-delete button:hover { background: var(--bg); color: var(--text); }
.sub-agent-prompt { margin-top: 0.45rem; }
.sub-agent-prompt summary {
  cursor: pointer; list-style: none;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.sub-agent-prompt summary::-webkit-details-marker { display: none; }
.sub-agent-prompt summary::before { content: "› "; }
.sub-agent-prompt[open] summary::before { content: "⌄ "; }
.sub-agent-prompt pre {
  margin: 0.4rem 0 0;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  font-family: inherit;
}
.sub-agent-create {
  margin-top: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0;
  background: transparent;
}
.sub-agent-create > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.65rem 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.sub-agent-create > summary::-webkit-details-marker { display: none; }
.sub-agent-create[open] > summary { border-bottom: 1px dashed var(--border); color: var(--text); }
.sa-create-form {
  padding: 0.85rem;
  display: flex; flex-direction: column; gap: 0.55rem;
}
.sa-create-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.sa-create-form input,
.sa-create-form textarea {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.sa-create-form textarea { resize: vertical; min-height: 5rem; }
.sa-create-form .btn-primary {
  align-self: flex-start;
  background: var(--primary); color: white; border: none;
  padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; font-weight: 500;
}

/* === Nébuleuse (vue graphe agent) === */
.agent-nebula {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.agent-nebula h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.nebula-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.8rem 0 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.nebula-stats { font-style: italic; }
.nebula-legend {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.9rem;
}
.leg-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 0.25rem;
  vertical-align: middle;
}
.leg-core { background: var(--primary); }
.leg-subsystem { background: #5EC2E0; }
.leg-category { background: #A78BFA; }
.leg-tool { background: #94a3b8; }
.leg-workflow { background: #34D399; }
.leg-routine { background: #F59E0B; }
.leg-subagent { background: #F472B6; }
.nebula-canvas {
  position: relative;
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.nebula-canvas svg { display: block; }
.nebula-tooltip {
  position: absolute;
  z-index: 5;
  max-width: 280px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text);
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.nebula-tooltip strong { font-weight: 600; }
.nebula-tooltip em { color: var(--text-muted); font-style: italic; }

/* === Help page === */
.help-page { max-width: 780px; margin: 0 auto; }
.help-page h1 { margin-bottom: 0.5rem; }
.help-intro {
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 1.5rem;
}
.help-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.6rem;
  background: var(--surface);
  overflow: hidden;
}
.help-section > summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  list-style: none;
  font-weight: 600;
  user-select: none;
  display: flex; align-items: center; gap: 0.5rem;
}
.help-section > summary::-webkit-details-marker { display: none; }
.help-section > summary::after {
  content: "›";
  margin-left: auto;
  font-size: 1.2rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.help-section[open] > summary::after { transform: rotate(90deg); }
.help-section > summary:hover { background: var(--bg); }
.help-section[open] > summary { border-bottom: 1px solid var(--border); }
.help-body {
  padding: 0.85rem 1rem 1rem;
  font-size: 0.92rem;
  line-height: 1.6;
}
.help-body p { margin: 0 0 0.6rem; }
.help-body ul { margin: 0.3rem 0 0.5rem; padding-left: 1.4rem; }
.help-body li { margin: 0.25rem 0; }
.help-body code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* === Streaming events === */
.msg-tool-steps {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}
.tool-step {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  max-width: 100%;
  width: fit-content;
}
.tool-step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60ch; }
.tool-step-running { border-color: var(--primary); color: var(--primary); }
.tool-step-running .tool-step-spinner {
  width: 10px; height: 10px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: tool-step-spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes tool-step-spin { to { transform: rotate(360deg); } }
.tool-step-done .tool-step-check { color: var(--primary); font-weight: 700; }
.msg-thinking-inline {
  margin: 0.25rem 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* === Markdown rendering inside assistant bubbles === */
.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 0.5rem 0; line-height: 1.55; }
.msg-content ul, .msg-content ol { margin: 0.5rem 0; padding-left: 1.4rem; }
.msg-content li { margin: 0.2rem 0; line-height: 1.5; }
.msg-content li > p { margin: 0; }
.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 0.9rem 0 0.4rem;
  line-height: 1.3;
  font-weight: 600;
}
.msg-content h1 { font-size: 1.15rem; }
.msg-content h2 { font-size: 1.05rem; }
.msg-content h3 { font-size: 0.98rem; }
.msg-content code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.7rem 0.85rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.6rem 0;
  font-size: 0.85em;
}
.msg-content pre code {
  background: transparent;
  border: none;
  padding: 0;
}
.msg-content blockquote {
  border-left: 3px solid var(--border);
  margin: 0.5rem 0;
  padding: 0 0.75rem;
  color: var(--text-muted);
}
.msg-content a { color: var(--primary); }
.msg-content strong { font-weight: 600; }
.msg-content em { font-style: italic; }
.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.7rem 0;
}
.msg-challenger-running { margin-top: 0.5rem; }

.chat-mode-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s, color 0.15s;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.chat-mode-btn:hover { opacity: 0.95; }
.chat-mode-btn.active {
  opacity: 1;
  background: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
}
.chat-mode-btn svg { flex-shrink: 0; }
@media (max-width: 520px) {
  .chat-mode-btn span { display: none; }
  .chat-mode-btn { padding: 0.3rem 0.45rem; }
  .chat-mode-btn svg { width: 16px; height: 16px; }
}

/* === Phase 2C Volition === */
.thought-pushed-badge {
  margin-top: 0.4rem;
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.conv-source-badge {
  font-size: 0.85rem;
  margin-right: 0.15rem;
  opacity: 0.75;
}

/* === Phase 3a Routines === */
.routines-page { max-width: 800px; margin: 2rem auto; padding: 0 1rem; }
.routines-system, .routines-custom { margin-bottom: 2rem; }
.routines-system .muted, .routines-custom .muted {
  color: var(--text-muted); font-size: 0.9rem; margin: 0.3rem 0 0.8rem;
}
.system-jobs-list { list-style: none; padding: 0; }
.system-jobs-list li {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0.3rem 0;
  background: var(--surface);
  color: var(--text-muted);
}

.routine-form-toggle { margin: 1rem 0; }
.routine-form-toggle summary {
  cursor: pointer;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 500;
  display: inline-block;
}
.routine-form { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 8px; }
.routine-form label { display: flex; flex-direction: column; gap: 0.3rem; }
.routine-form input, .routine-form textarea {
  padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.95rem;
}
.routine-form small { color: var(--text-muted); font-size: 0.8rem; }
.routine-form small code { background: var(--surface); padding: 0.05rem 0.3rem; border-radius: 3px; }
.routine-form .btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 0.6rem 1.2rem; border-radius: 6px; cursor: pointer;
  font-weight: 500; align-self: flex-start;
}

.routine-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin: 0.6rem 0;
  background: var(--surface);
}
.routine-card.routine-paused { opacity: 0.6; }
.routine-header { display: flex; gap: 0.5rem; align-items: center; }
.routine-name { margin: 0; font-size: 1rem; font-weight: 600; }
.routine-meta {
  font-size: 0.85rem; color: var(--text-muted);
  display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.4rem 0;
}
.routine-meta code {
  font-family: monospace; background: var(--bg);
  padding: 0.1rem 0.4rem; border-radius: 4px;
}
.routine-error { color: #d33; cursor: help; }
.routine-message { font-style: italic; margin: 0.4rem 0; color: var(--text); }
.routine-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.routine-actions button {
  padding: 0.3rem 0.7rem; font-size: 0.85rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer; color: var(--text);
}
.routine-actions button:hover { background: var(--surface); }

/* === Routines : cron picker === */
.cron-picker {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 1rem;
}
.cron-picker legend { padding: 0 0.4rem; font-size: 0.9rem; font-weight: 500; }
.cron-picker-tabs { display: flex; gap: 1rem; margin-bottom: 0.6rem; font-size: 0.9rem; }
.cron-picker-tabs label { display: flex; align-items: center; gap: 0.3rem; cursor: pointer; flex-direction: row; }
.cron-mode-block { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.cron-mode-block select, .cron-mode-block input[type="time"], .cron-mode-block input[type="number"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.cron-mode-block input[type="number"] { width: 4.5rem; }

.routine-edit {
  margin-top: 0.8rem;
  padding: 0.8rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg);
}
.routine-edit label { display: flex; flex-direction: column; gap: 0.3rem; }
.routine-edit input, .routine-edit textarea {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.routine-edit small.muted { font-size: 0.8rem; }
.routine-edit .btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
  align-self: flex-start;
}

/* === Phase 4a Atelier === */
.atelier-page, .atelier-detail, .atelier-run {
  max-width: 900px; margin: 2rem auto; padding: 0 1rem;
}
.atelier-page details {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.atelier-page details summary {
  cursor: pointer;
  font-weight: 500;
}
.atelier-page form label,
.atelier-detail form label {
  display: block;
  margin: 0.6rem 0;
}
.atelier-page form input[type=text],
.atelier-detail form input[type=text] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.atelier-page button,
.atelier-detail button {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
}
.atelier-page ul, .atelier-detail ul {
  list-style: none;
  padding: 0;
}
.atelier-page ul li, .atelier-detail ul li {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0.3rem 0;
  background: var(--surface);
}
.atelier-detail .actions {
  display: flex; gap: 0.5rem; margin: 1rem 0;
}
.atelier-detail .actions button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.atelier-run .step-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
  margin: 0.6rem 0;
  background: var(--surface);
}
.atelier-run .step-row h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.atelier-run pre { font-size: 0.85rem; overflow-x: auto; }

/* === Phase 4c Atelier Canvas === */
.atelier-canvas-page {
  display: flex; flex-direction: column;
  /* Fixed positioning : occupe exactement la zone à droite de la sidebar globale
     (qui est position:fixed left:0 width:240px). Sur mobile, on adapte via media query. */
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 240px;
  margin: 0;
  background: var(--bg);
  max-width: none;
  z-index: 1;
}

@media (max-width: 768px) {
  .atelier-canvas-page {
    left: 0;
    bottom: 60px; /* hauteur de la mobile-nav */
  }
}
.atelier-canvas-header {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  padding-right: 4rem;
}
.atelier-canvas-header h1 {
  margin: 0; font-size: 1.05rem; flex: 1;
  outline: none; padding: 0.25rem 0.4rem; border-radius: 6px;
}
.atelier-canvas-header h1:focus { background: var(--surface); }
.atelier-canvas-header .actions {
  display: flex; gap: 0.4rem;
}
.atelier-canvas-header .actions button,
.atelier-canvas-header .actions form button {
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.atelier-canvas-header .actions button:hover { background: var(--surface); }

/* === Palette horizontale (toolbar) === */
.palette-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.palette-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.3rem;
  flex-shrink: 0;
}
.palette-bar .palette-node {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  font-size: 0.85rem;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.palette-bar .palette-node .svg-icon { color: var(--text-muted); flex-shrink: 0; }
.palette-bar .palette-node:hover .svg-icon { color: var(--primary); }

.atelier-node-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-right: 0.3rem;
  color: var(--text-muted);
}
.atelier-node-icon svg { width: 14px; height: 14px; display: block; }
.atelier-node-title { display: inline-flex; align-items: center; gap: 0.15rem; }
.palette-bar .palette-node:active { cursor: grabbing; }
.palette-bar .palette-node:hover { border-color: var(--primary); background: var(--bg); }
.palette-bar-spacer { flex: 1; }
.palette-runs-btn {
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  flex-shrink: 0;
}
.palette-runs-btn:hover { border-color: var(--primary); }

.runs-popover {
  position: absolute;
  top: 7rem;
  right: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-width: 360px;
  max-height: 50vh;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 50;
}
.runs-popover h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.runs-popover ul { list-style: none; padding: 0; margin: 0; }
.runs-popover li {
  padding: 0.3rem 0.5rem;
  margin: 0.15rem 0;
  font-size: 0.85rem;
  background: var(--bg);
  border-radius: 4px;
}
.runs-popover li a { text-decoration: none; color: var(--text); }
.runs-popover li a:hover { text-decoration: underline; }

.canvas-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#drawflow {
  background: var(--bg);
  background-image:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
  width: 100%; height: 100%;
  position: relative;
  overflow: hidden;
}

.canvas-layout .params-panel {
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 1rem;
  overflow-y: auto;
}
.canvas-layout .params-panel h3 {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.canvas-layout .params-panel.hidden #params-form { display: none; }
.canvas-layout .params-panel.hidden #params-empty { display: block; }

/* Hidden global utility */
.hidden { display: none !important; }

/* Canvas regagne la colonne droite quand le params-panel est caché */
.canvas-layout:has(.params-panel.hidden) {
  grid-template-columns: 1fr;
}
.canvas-layout:has(.params-panel.hidden) .params-panel { display: none; }
.params-title {
  padding: 0.5rem 0.6rem;
  background: var(--surface);
  border-radius: 6px;
  margin-bottom: 0.8rem;
  font-size: 0.95rem;
}
.params-title code {
  background: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.8rem;
}
#params-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
}
#params-form label span {
  color: var(--text-muted);
  font-weight: 500;
}
#params-form input, #params-form textarea, #params-form select {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}
#params-form textarea { font-family: monospace; }
#params-form .params-delete {
  margin-top: 0.8rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  color: #d33;
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.85rem;
}
#params-form .params-delete:hover { background: #fee; border-color: #d33; }

/* === Drawflow node styling override === */
.drawflow .drawflow-node {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 0 !important;
  min-width: 220px !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.drawflow .drawflow-node.selected {
  box-shadow: 0 0 0 2px var(--primary), 0 4px 12px rgba(0,0,0,0.12) !important;
}
.atelier-node-content {
  padding: 0.8rem 1rem;
}
.atelier-node-title {
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.atelier-node-title .atelier-node-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  line-height: 0;
  color: var(--text-muted);
  margin: 0;
}
.atelier-node-title .atelier-node-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}
.atelier-node-title strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.atelier-node-id {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: monospace;
  margin-bottom: 0.5rem;
}
.atelier-node-summary {
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.4rem;
  line-height: 1.4;
}
.atelier-node-summary em {
  font-style: normal;
  color: var(--text);
  font-weight: 500;
}

/* === JSON fallback panel === */
.json-fallback-panel {
  padding: 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin: 0;
}
.json-fallback-panel summary {
  cursor: pointer;
  padding: 0.4rem;
  font-weight: 500;
}
.json-fallback-panel textarea {
  width: 100%;
  padding: 0.6rem;
  font-family: monospace;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.runs-list {
  list-style: none;
  padding: 0 1.25rem;
  margin: 0.5rem 0 1rem;
}
.runs-list li {
  padding: 0.4rem 0.7rem;
  margin: 0.2rem 0;
  background: var(--surface);
  border-radius: 5px;
  font-size: 0.9rem;
}
.runs-list li a { text-decoration: none; color: var(--text); }
.runs-list li a:hover { text-decoration: underline; }

.atelier-flash {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 0.7rem 1.2rem;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.atelier-flash.error {
  background: #d33;
}

.palette-runs {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.palette-runs h3 {
  font-size: 0.85rem;
  user-select: none;
}
.palette-runs .runs-list {
  padding: 0;
  margin: 0.4rem 0 0;
  max-height: 30vh;
  overflow-y: auto;
}
.palette-runs .runs-list li {
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  margin: 0.15rem 0;
  background: var(--bg);
}

.vars-popover {
  position: absolute;
  top: 7rem;
  right: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  width: 380px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 50;
}
.vars-popover h3 {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.vars-popover h4 {
  margin: 0.6rem 0 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.vars-popover hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8rem 0;
}
.vars-popover label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.vars-popover input, .vars-popover select {
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}
.vars-popover button {
  padding: 0.45rem 0.9rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
  margin-top: 0.4rem;
}
.var-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  border-radius: 5px;
  margin: 0.25rem 0;
  font-size: 0.85rem;
}
.var-row code {
  background: var(--surface);
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.8rem;
}
.var-row small {
  color: var(--text-muted);
}
.var-delete {
  background: transparent !important;
  color: #d33 !important;
  padding: 0.2rem 0.5rem !important;
  margin: 0 !important;
  font-size: 0.9rem !important;
  border: 1px solid var(--border) !important;
}
.var-delete:hover { background: #fee !important; }

/* === Phase 4e Marketplace === */
.atelier-index-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
}
.btn-marketplace,
.btn-import {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  line-height: 1.2;
}
.btn-marketplace:hover,
.btn-import:hover { opacity: 0.9; color: white; }
.atelier-index-actions {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  flex-wrap: wrap;
}
.atelier-import-form { margin: 0; }

.atelier-marketplace {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.marketplace-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem;
}
.marketplace-header h1 { margin: 0; }
.btn-back {
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
}
.btn-back:hover { border-color: var(--primary); color: var(--primary); }

.marketplace-category {
  margin-top: 2rem;
}
.marketplace-category h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}
.marketplace-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.marketplace-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: transform 0.15s, box-shadow 0.15s;
}
.marketplace-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-color: var(--primary);
}
.marketplace-card-header {
  display: flex; align-items: center; gap: 0.6rem;
}
.marketplace-icon {
  font-size: 1.6rem;
}
.marketplace-card h3 {
  margin: 0;
  font-size: 1rem;
}
.marketplace-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}
.marketplace-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-install {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  align-self: flex-start;
}
.btn-install:hover { opacity: 0.9; color: white; }

/* === Phase 7 Coaching === */
.coaching-page { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }
.coaching-header h1 { margin-bottom: 1rem; }
.coaching-interventions { margin-bottom: 1.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.intervention-card {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  background: var(--surface);
  border-left: 4px solid var(--primary);
  font-size: 0.92rem;
}
.intervention-card.priority-1 { border-left-color: #d33; }
.intervention-card.priority-2 { border-left-color: var(--primary); }
.intervention-card.priority-3 { border-left-color: var(--text-muted); }

.coaching-tabs {
  display: flex; gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.coaching-tabs .tab {
  padding: 0.6rem 1.2rem;
  text-decoration: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  font-size: 0.95rem;
}
.coaching-tabs .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.coaching-tabs .tab:hover { color: var(--text); }

.coaching-section { display: flex; flex-direction: column; gap: 0.8rem; }
.coaching-form-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 0.8rem;
}
.coaching-form-toggle summary { cursor: pointer; font-weight: 500; }
.coaching-form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.8rem; }
.coaching-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; }
.coaching-form input, .coaching-form textarea, .coaching-form select {
  padding: 0.45rem; border: 1px solid var(--border); border-radius: 5px;
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.9rem;
}
.coaching-form button {
  padding: 0.5rem 1.2rem; background: var(--primary); color: white;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 500; align-self: flex-start;
}

.objective-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.objective-card.status-done { opacity: 0.6; }
.objective-card.status-abandoned { opacity: 0.4; text-decoration: line-through; }
.objective-header { display: flex; justify-content: space-between; align-items: center; }
.objective-header h3 { margin: 0; font-size: 1rem; }
.objective-status {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--bg); padding: 0.15rem 0.5rem; border-radius: 999px; color: var(--text-muted);
}
.objective-desc { font-size: 0.88rem; color: var(--text-muted); margin: 0; }
.objective-progress { position: relative; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 0.3rem 0; }
.objective-progress .progress-bar { height: 100%; background: var(--primary); transition: width 0.3s; }
.objective-progress .progress-label { position: absolute; right: 0; top: -1.2rem; font-size: 0.75rem; color: var(--text-muted); }
.objective-update { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.4rem; }
.objective-update input, .objective-update select {
  padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); font-size: 0.85rem;
}
.objective-update button, .objective-card .btn-delete {
  padding: 0.3rem 0.8rem; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer; font-size: 0.85rem;
}
.objective-card .btn-delete { color: #d33; }

.journal-entry {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.8rem 1rem; position: relative;
}
.journal-meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.journal-content { margin: 0; white-space: pre-wrap; line-height: 1.5; font-size: 0.95rem; }
.btn-delete-mini {
  position: absolute; top: 0.4rem; right: 0.4rem;
  background: transparent; border: none; color: #d33; cursor: pointer; font-size: 1rem;
}

.coaching-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.btn-coach-chat {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-coach-chat:hover { opacity: 0.9; color: white; }

/* === Mobile responsive — drawer "Plus" === */
.mobile-more-btn {
  background: transparent;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.mobile-drawer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: flex-end;
}
.mobile-drawer.open { display: flex; }
.mobile-drawer-content {
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 1.25rem 1rem 5rem;
  max-height: 70vh;
  overflow-y: auto;
}
.mobile-drawer-content h3 {
  margin: 0 0 0.8rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.drawer-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 8px;
  font-size: 0.95rem;
  margin: 0.2rem 0;
}
.drawer-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.drawer-link:hover, .drawer-link:active { background: var(--border); }
.drawer-link:hover .drawer-icon, .drawer-link:active .drawer-icon { color: var(--text); }

/* === Mobile : adaptations pages critiques === */
@media (max-width: 768px) {
  /* Chat : sidebar conversations devient toggle */
  .chat-layout {
    grid-template-columns: 1fr;
    margin: -1rem -0.75rem -80px;
    height: calc(100vh - 4rem);
  }
  .chat-sidebar {
    display: none;
  }
  .chat-sidebar.mobile-open {
    display: flex;
    position: fixed;
    inset: 0 0 60px 0;
    z-index: 90;
  }

  /* Atelier canvas : palette horizontale scroll, désactive params-panel side */
  .atelier-canvas-page {
    margin: -1rem -0.75rem -80px;
    height: calc(100vh - 4rem);
  }
  .atelier-canvas-header {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }
  .atelier-canvas-header h1 { font-size: 0.95rem; flex: 1 0 100%; }
  .atelier-canvas-header .actions { flex-wrap: wrap; gap: 0.3rem; }
  .atelier-canvas-header .actions button {
    padding: 0.3rem 0.6rem; font-size: 0.8rem;
  }
  .palette-bar { padding: 0.4rem 0.6rem; }
  .palette-label { display: none; }
  .canvas-layout {
    grid-template-columns: 1fr !important;
  }
  .canvas-layout .params-panel {
    position: fixed;
    inset: auto 0 60px 0;
    max-height: 50vh;
    z-index: 80;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .canvas-layout:has(.params-panel.hidden) .params-panel { display: none; }
  .runs-popover { right: 0.5rem; left: 0.5rem; top: auto; bottom: 70px; }
  .vars-popover { right: 0.5rem; left: 0.5rem; top: auto; bottom: 70px; width: auto; }

  /* Routines : action buttons wrap */
  .routine-card { padding: 0.8rem; }
  .routine-actions { flex-wrap: wrap; gap: 0.3rem; }
  .routine-actions button { font-size: 0.8rem; padding: 0.3rem 0.6rem; }

  /* Coaching : objectifs et tabs */
  .coaching-page { padding: 0 0.5rem; margin: 1rem auto; }
  .coaching-header { flex-wrap: wrap; gap: 0.5rem; }
  .coaching-tabs { overflow-x: auto; }
  .coaching-tabs .tab { padding: 0.5rem 0.8rem; font-size: 0.85rem; white-space: nowrap; }
  .objective-card { padding: 0.8rem; }
  .objective-update { flex-wrap: wrap; gap: 0.3rem; }

  /* Marketplace */
  .marketplace-grid { grid-template-columns: 1fr; gap: 0.6rem; }
  .marketplace-card { padding: 0.8rem; }

  /* Settings */
  .settings-page { padding: 0 0.5rem; }

  /* Library / Notes : layout */
  .library-grid, .notes-grid { grid-template-columns: 1fr !important; }
}

.chat-mobile-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}
@media (max-width: 768px) {
  .chat-mobile-toggle { display: inline-block; }
}

/* ============================================================ */
/* Bibliothèque — layout 2 colonnes (Task 8 library-folders)    */
/* ============================================================ */
.library-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.library-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 1rem;
}

.library-sidebar .sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  gap: 0.75rem;
}

.library-sidebar .new-folder-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.library-sidebar .new-folder-form input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.library-sidebar .sidebar-header h3 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.library-sidebar .folder-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9rem;
}

.library-sidebar .folder-tree ul.folder-children {
  list-style: none;
  padding-left: 1.2rem;
  margin: 0.25rem 0;
}

.library-sidebar .folder-link {
  display: block;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.15rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.library-sidebar .folder-link:hover {
  background: var(--bg-elev, var(--surface));
}

.library-sidebar .folder-link.active {
  background: var(--primary-soft, rgba(99, 102, 241, 0.15));
  color: var(--primary);
  font-weight: 600;
}

.library-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.library-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.library-breadcrumb a:hover {
  color: var(--primary);
}

.library-breadcrumb .current {
  color: var(--text);
  font-weight: 600;
}

.library-breadcrumb .separator {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* SVG icons générique */
.svg-icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Sidebar — folder links avec icône SVG inline */
.library-sidebar .folder-link {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
}

.library-sidebar .folder-link .svg-icon {
  color: var(--text-muted);
}

.library-sidebar .folder-link.active .svg-icon {
  color: var(--primary);
}

.library-quota {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.quota-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-elev, var(--surface));
  border-radius: 999px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.quota-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.library-toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

/* Barre de recherche compacte */
.search-bar-compact {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0;
}

.search-bar-compact input[type="text"] {
  width: 200px;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

.search-bar-compact input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

/* Bouton uniformisé pour toute la toolbar et la sidebar */
.btn-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.btn-toolbar:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-toolbar.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-toolbar.btn-primary:hover {
  filter: brightness(1.1);
  color: white;
}

.btn-toolbar.btn-danger {
  border-color: transparent;
  color: var(--error, #ef4444);
}

.btn-toolbar.btn-danger:hover {
  border-color: var(--error, #ef4444);
  background: rgba(239, 68, 68, 0.08);
  color: var(--error, #ef4444);
}

.upload-status {
  width: 100%;
  margin: 0.5rem 0;
}

/* Cards minimalistes — icône en haut, nom dessous */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 1.5rem 1rem;
  padding: 0.5rem 0;
}

.library-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.3rem;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius);
  transition: background 0.15s ease;
  position: relative;
  cursor: pointer;
}

.library-card:hover {
  background: var(--surface);
}

.library-card .card-icon-box {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.library-card:hover .card-icon-box {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.library-card .card-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.library-card .card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 11px;
  display: block;
}

/* Preview texte pour PDFs / DOCX / TXT — extrait des premiers caractères */
.library-card .card-text-preview {
  overflow: hidden;
  position: relative;
  background: #fdfdfd;
  color: #2a2a2a;
  border-color: rgba(0,0,0,0.12);
}

.library-card .card-text-snippet {
  font-size: 4.5px;
  line-height: 1.4;
  padding: 5px 5px 12px;
  text-align: justify;
  font-family: ui-sans-serif, system-ui, sans-serif;
  word-break: break-word;
  overflow: hidden;
  max-height: 100%;
  -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent);
  mask-image: linear-gradient(to bottom, black 70%, transparent);
}

.library-card .card-format-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.library-card .card-format-badge .svg-icon {
  width: 10px;
  height: 10px;
}

/* Drag-and-drop visual states */
.library-card.file-card[draggable="true"] { cursor: grab; }
.library-card.file-card.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.library-sidebar .folder-link.drop-target {
  background: var(--primary);
  color: white;
  outline: 2px dashed white;
  outline-offset: -4px;
}

.library-sidebar .folder-link.drop-target .svg-icon {
  color: white;
}

.library-card .card-name {
  font-size: 0.75rem;
  color: var(--text);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  line-height: 1.2;
}

.library-card.folder-card .card-icon-box {
  background: var(--primary-soft, rgba(99, 102, 241, 0.08));
  border-color: transparent;
}

.library-card.folder-card:hover .card-icon-box {
  border-color: var(--primary);
}

/* Actions cachées par défaut, visibles au hover sur la card */
.library-card .card-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.library-card:hover .card-actions {
  opacity: 1;
}

.card-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: var(--bg, white);
  color: var(--text);
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.card-action:hover {
  background: var(--primary);
  color: white;
}

.library-section-title {
  margin: 2.5rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.library-docs-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 800px) {
  .library-layout {
    grid-template-columns: 1fr;
  }
  .library-sidebar {
    position: static;
  }
}

/* === Niveaux de conscience (presets) === */
.consciousness-levels { margin-bottom: 1.5rem; }
.cl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.7rem; margin-top: 0.6rem; }
@media (max-width: 520px) { .cl-grid { grid-template-columns: 1fr; } }
.cl-card-form { margin: 0; }
.cl-card {
  width: 100%;
  text-align: left;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 0.25rem;
  position: relative;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  color: var(--text);
}
.cl-card:hover { border-color: var(--primary); }
.cl-card:active { transform: scale(0.99); }
.cl-card-title { font-weight: 600; font-size: 0.95rem; }
.cl-card-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.35; }
.cl-card-badge {
  position: absolute; top: 0.5rem; right: 0.6rem;
  font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 4px;
  background: var(--primary); color: white;
}
.cl-current { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }

.personality-presets { margin: 1.5rem 0 1rem; }
.pp-current-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.4rem 0 0.7rem;
  padding: 0.4rem 0.75rem;
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border: 1px solid var(--primary);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
}
.pp-current-summary em { color: var(--text-muted); font-style: italic; }
.pp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.7rem; margin-top: 0.6rem; }
.pp-card {
  width: 100%;
  text-align: left;
  padding: 0.8rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 0.25rem;
  position: relative;
  transition: border-color 0.15s, background 0.15s, transform 0.05s, box-shadow 0.15s;
  color: var(--text);
  font-family: inherit;
}
.pp-card:hover { border-color: var(--primary); }
.pp-card:active { transform: scale(0.99); }
.pp-card-title { font-weight: 600; font-size: 0.95rem; padding-right: 4.5rem; }
.pp-card-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.35; }
.pp-card-badge {
  position: absolute; top: 0.55rem; right: 0.6rem;
  font-size: 0.7rem; padding: 0.15rem 0.55rem; border-radius: 999px;
  background: var(--primary); color: white;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 0.3rem;
}
.pp-card-badge::before {
  content: "✓";
  font-size: 0.85em;
}
.pp-current {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--surface));
  box-shadow: 0 0 0 1px var(--primary);
}
.pp-card-custom { padding-right: 1.7rem; }
.pp-card-delete { position: absolute; top: 0.4rem; right: 0.4rem; margin: 0; }
.pp-card-delete button {
  background: transparent;
  border: none;
  padding: 0.15rem;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
}
.pp-card-delete button:hover { background: var(--bg); color: var(--text); }
.pp-card-add {
  border-style: dashed;
  color: var(--text-muted);
  background: transparent;
}
.pp-card-add:hover { color: var(--text); }
.pp-create-form {
  margin-top: 0.9rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.pp-create-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.pp-create-form input,
.pp-create-form textarea {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.pp-create-form textarea { resize: vertical; }
.pp-create-actions { display: flex; gap: 0.5rem; }
.pp-create-actions .btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer;
}
.pp-create-actions button[type="button"] {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer;
}

.user-memory { margin: 1.5rem 0 1rem; }
.memory-add-form {
  display: flex;
  gap: 0.5rem;
  margin: 0.7rem 0 0.9rem;
}
.memory-add-form input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}
.memory-add-form button {
  background: var(--primary); color: white; border: none;
  padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; font-weight: 500;
}
.memory-add-form button:hover { opacity: 0.9; }

.memory-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.memory-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}
.memory-source {
  flex-shrink: 0;
  font-size: 0.66rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.memory-source-manual { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.memory-source-agent { background: color-mix(in srgb, var(--primary) 15%, var(--surface)); color: var(--primary); }
.memory-content { flex: 1; line-height: 1.4; }
.memory-delete { margin: 0; }
.memory-delete button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  display: inline-flex;
}
.memory-delete button:hover { background: var(--bg); color: var(--text); }
