/* ────────────────────────────────────────────────────────────────────────
   espace.css — Styles Mon Espace Templates DiagMobile
   Cohérent avec le design Bootstrap 5.1 de membre/
──────────────────────────────────────────────────────────────────────── */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
    --espace-primary:    #667eea;
    --espace-secondary:  #764ba2;
    --espace-accent:     #2563eb;
    --espace-danger:     #ef4444;
    --espace-success:    #10b981;
    --espace-warning:    #f59e0b;
    --espace-bg:         #f8f9fc;
    --espace-card:       #ffffff;
    --espace-border:     #e2e8f0;
    --espace-text:       #1e293b;
    --espace-muted:      #64748b;
    --sidebar-w:         260px;
}

/* ── Reset & base ──────────────────────────────────────────────────────── */
body {
    background: var(--espace-bg);
    color: var(--espace-text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}

a { color: var(--espace-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ────────────────────────────────────────────────────────────── */
.espace-navbar {
    background: linear-gradient(135deg, var(--espace-primary) 0%, var(--espace-secondary) 100%);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.espace-navbar .brand {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.espace-navbar .nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
}

.espace-navbar .nav-links a {
    color: rgba(255,255,255,.85);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    transition: background .15s;
}

.espace-navbar .nav-links a:hover,
.espace-navbar .nav-links a.active {
    background: rgba(255,255,255,.2);
    color: #fff;
    text-decoration: none;
}

.espace-navbar .user-info {
    color: rgba(255,255,255,.9);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.espace-navbar .user-info a {
    color: rgba(255,255,255,.75);
    font-size: 12px;
}

.espace-navbar .user-info a:hover { color: #fff; }

/* ── Layout principal ──────────────────────────────────────────────────── */
.espace-layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.espace-sidebar {
    width: var(--sidebar-w);
    background: var(--espace-card);
    border-right: 1px solid var(--espace-border);
    padding: 16px 0;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-section {
    padding: 0 12px 8px;
}

.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--espace-muted);
    padding: 8px 12px 4px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-radius: 8px;
    color: var(--espace-text);
    cursor: pointer;
    transition: background .12s;
    font-size: 13.5px;
    margin: 1px 0;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
}

.sidebar-item:hover { background: #f1f5f9; }
.sidebar-item.active { background: #ede9fe; color: var(--espace-primary); font-weight: 600; }
.sidebar-item .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar-item .badge { margin-left: auto; background: var(--espace-primary); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }

/* ── Contenu principal ─────────────────────────────────────────────────── */
.espace-main {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    min-width: 0;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.espace-card {
    background: var(--espace-card);
    border: 1px solid var(--espace-border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    margin-bottom: 20px;
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--espace-text);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

/* ── Boutons ───────────────────────────────────────────────────────────── */
.btn-espace {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn-espace:hover { text-decoration: none; filter: brightness(1.08); }

.btn-primary  { background: var(--espace-primary); color: #fff; }
.btn-success  { background: var(--espace-success); color: #fff; }
.btn-danger   { background: var(--espace-danger);  color: #fff; }
.btn-warning  { background: var(--espace-warning); color: #fff; }
.btn-outline  { background: transparent; border: 1.5px solid var(--espace-border); color: var(--espace-text); }
.btn-outline:hover { background: #f1f5f9; }
.btn-ghost    { background: transparent; color: var(--espace-muted); }
.btn-ghost:hover  { background: #f1f5f9; }
.btn-sm       { padding: 5px 12px; font-size: 12.5px; }

/* ── Templates liste ───────────────────────────────────────────────────── */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.template-card {
    background: var(--espace-card);
    border: 1px solid var(--espace-border);
    border-radius: 10px;
    padding: 16px;
    transition: box-shadow .15s, border-color .15s;
    cursor: pointer;
}

.template-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.10);
    border-color: var(--espace-primary);
}

.template-card .tc-type {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--espace-primary);
    background: #ede9fe;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
    margin-bottom: 8px;
}

.template-card .tc-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--espace-text);
    margin-bottom: 6px;
}

.template-card .tc-meta {
    font-size: 12px;
    color: var(--espace-muted);
}

.template-card .tc-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* ── Diag type pills ───────────────────────────────────────────────────── */
.diag-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
}

.diag-gaz      { background: #fee2e2; color: #ef4444; }
.diag-elec     { background: #fef9c3; color: #b45309; }
.diag-amiante  { background: #d1fae5; color: #059669; }
.diag-crep     { background: #fce7f3; color: #be185d; }
.diag-dpe      { background: #dbeafe; color: #1d4ed8; }
.diag-mesurage { background: #e0e7ff; color: #4338ca; }
.diag-default  { background: #f1f5f9; color: #64748b; }

/* ── Éditeur ───────────────────────────────────────────────────────────── */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    height: calc(100vh - 130px);
    min-height: 500px;
}

.editor-canvas {
    background: var(--espace-card);
    border: 1px solid var(--espace-border);
    border-radius: 10px;
    overflow-y: auto;
    padding: 16px;
}

.editor-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

/* Blocs dans le canvas */
.block-item {
    border: 1px solid var(--espace-border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #fafafa;
    cursor: grab;
    transition: box-shadow .12s, border-color .12s;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.block-item:hover { border-color: var(--espace-primary); box-shadow: 0 2px 8px rgba(102,126,234,.15); }
.block-item.sortable-chosen { opacity: .8; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.block-item.sortable-ghost  { opacity: .4; }

.block-handle {
    cursor: grab;
    color: #cbd5e1;
    font-size: 16px;
    padding-top: 2px;
    flex-shrink: 0;
}

.block-content { flex: 1; min-width: 0; }
.block-type-badge {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--espace-muted);
    letter-spacing: .06em;
    margin-bottom: 4px;
}

.block-text-preview {
    font-size: 13px;
    color: var(--espace-text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.block-remove {
    background: none;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 14px;
    flex-shrink: 0;
}

.block-remove:hover { color: var(--espace-danger); background: #fee2e2; }

/* Éditeur inline */
.block-editor {
    margin-top: 8px;
    border-top: 1px solid var(--espace-border);
    padding-top: 8px;
}

.block-editor textarea {
    width: 100%;
    border: 1px solid var(--espace-border);
    border-radius: 6px;
    padding: 8px;
    font-size: 13px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    box-sizing: border-box;
}

.block-editor textarea:focus { outline: none; border-color: var(--espace-primary); }

/* ── Palette de tags ───────────────────────────────────────────────────── */
.tag-palette {
    background: var(--espace-card);
    border: 1px solid var(--espace-border);
    border-radius: 10px;
    overflow: hidden;
}

.tag-palette-header {
    padding: 12px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--espace-border);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tag-search {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid var(--espace-border);
    font-size: 13px;
    background: #f8fafc;
    box-sizing: border-box;
}

.tag-search:focus { outline: none; background: #fff; }

.tag-cat {
    border-bottom: 1px solid var(--espace-border);
}

.tag-cat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    background: #fafafa;
    font-size: 12.5px;
    font-weight: 600;
    user-select: none;
    transition: background .12s;
}

.tag-cat-header:hover { background: #f1f5f9; }

.tag-cat-header .cat-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--espace-muted);
}

.tag-cat-body { padding: 6px 8px; display: none; }
.tag-cat-body.open { display: block; }

.tag-chip {
    display: inline-block;
    background: #f1f5f9;
    border: 1px solid var(--espace-border);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 11.5px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    margin: 2px 3px;
    transition: all .12s;
    color: #334155;
}

.tag-chip:hover {
    background: var(--espace-primary);
    color: #fff;
    border-color: var(--espace-primary);
}

.tag-chip.loop-tag {
    background: #ede9fe;
    border-color: #c4b5fd;
    color: #5b21b6;
}

.tag-chip.loop-tag:hover { background: #7c3aed; color: #fff; border-color: #7c3aed; }

/* ── Toast notifications ───────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    background: #1e293b;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13.5px;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    animation: toastIn .2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 320px;
}

.toast.success { background: var(--espace-success); }
.toast.error   { background: var(--espace-danger); }
.toast.warning { background: var(--espace-warning); color: #1e293b; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Aperçu iframe ─────────────────────────────────────────────────────── */
.preview-frame {
    width: 100%;
    height: calc(100vh - 140px);
    border: 1px solid var(--espace-border);
    border-radius: 10px;
    background: #fff;
}

/* ── Tokens de sync ────────────────────────────────────────────────────── */
.token-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--espace-border);
    border-radius: 8px;
    background: #fafafa;
    margin-bottom: 8px;
}

.token-code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: #e2e8f0;
    padding: 4px 10px;
    border-radius: 5px;
    flex: 1;
    word-break: break-all;
}

/* ── Tables data ───────────────────────────────────────────────────────── */
.espace-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.espace-table th {
    background: #f1f5f9;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--espace-muted);
    border-bottom: 2px solid var(--espace-border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.espace-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--espace-border);
    vertical-align: middle;
}

.espace-table tr:last-child td { border-bottom: none; }
.espace-table tr:hover td { background: #f8fafc; }

/* ── Stats cards ───────────────────────────────────────────────────────── */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--espace-card);
    border: 1px solid var(--espace-border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}

.stat-card .stat-num {
    font-size: 28px;
    font-weight: 800;
    color: var(--espace-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card .stat-label { font-size: 12px; color: var(--espace-muted); }

/* ── Utilitaires ───────────────────────────────────────────────────────── */
.text-muted  { color: var(--espace-muted) !important; }
.text-sm     { font-size: 12px; }
.fw-bold     { font-weight: 700; }
.d-flex      { display: flex; }
.gap-2       { gap: 8px; }
.align-center{ align-items: center; }
.mb-0        { margin-bottom: 0; }
.mt-2        { margin-top: 8px; }
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--espace-muted);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }
