/* ============================================================
 * Dashboard — Pages Personnalisées
 * Thème dark industriel, cohérent avec EllioDB 3.0
 * ============================================================ */

/* ---------- Layout shell ---------- */
html, body { margin:0; padding:0; height:100%; overflow:hidden; background:var(--bg-main); }

.db-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    background: var(--bg-main);
}

/* ---------- Top bar ---------- */
.db-topbar {
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    z-index: 50;
    overflow: hidden;
}
.db-topbar.db-topbar-hidden { display: none; }

.db-page-tabs { display:flex; gap:4px; flex:1; min-width:0; }

.db-page-tab {
    padding: 4px 14px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}
.db-page-tab:hover { background:var(--bg-hover); color:var(--text-main); }
.db-page-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.db-page-name-input {
    padding: 3px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    width: 140px;
}

.db-btn {
    padding: 4px 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
    transition: background .15s;
}
.db-btn:hover { background: var(--bg-hover); }
.db-btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.db-btn-accent:hover { background: var(--accent-hover); }
.db-btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.db-btn-danger:hover { opacity:.85; }
.db-btn-sm { padding: 3px 8px; font-size: 11px; }

/* ---------- Workspace ---------- */
.db-workspace {
    flex: 1 1 0;
    display: flex;
    min-height: 0;
    position: relative;
}

/* ---------- Left toolbar (edit mode) ---------- */
.db-toolbar {
    flex: 0 0 110px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 6px;
    overflow-y: auto;
    z-index: 10;
}
.db-toolbar-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-dim);
    margin: 4px 0 2px;
    padding-left: 2px;
}
.db-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 10px;
    font-family: inherit;
    text-align: center;
    line-height: 1.2;
    transition: background .15s, color .15s, border-color .15s;
}
.db-tool-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }
.db-tool-btn svg { width:18px; height:18px; }

/* ---------- Canvas wrapper ---------- */
.db-canvas-wrapper {
    flex: 1 1 0;
    position: relative;
    min-width: 0;
    overflow: hidden;
}

.db-canvas {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #0f1117;
}

/* Floating page selector overlay (view mode) */
.db-page-float {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    background: rgba(15,17,23,.85);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 12px;
    z-index: 40;
}
.db-page-float-btn {
    padding: 4px 14px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    transition: all .15s;
}
.db-page-float-btn:hover { color: var(--text-main); }
.db-page-float-btn.active { background: var(--accent); color: #fff; }

/* Edit mode toggle button (top-right overlay in view mode) */
.db-fab-group {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
}
.db-fab-group .eh-help-btn {
    background: rgba(15,17,23,.8);
    backdrop-filter: blur(4px);
}
.db-edit-fab {
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: rgba(15,17,23,.8);
    backdrop-filter: blur(4px);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    transition: color .15s, border-color .15s;
}
.db-edit-fab:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Right property panel (edit mode) ---------- */
.db-props-panel {
    flex: 0 0 240px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}
.db-props-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.db-props-body {
    flex: 1 1 0;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.db-props-empty {
    color: var(--text-dim);
    font-size: 12px;
    text-align: center;
    margin-top: 30px;
}

/* Property form rows */
.db-prop-group { display:flex; flex-direction:column; gap:4px; }
.db-prop-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-dim);
}
.db-prop-input,
.db-prop-select,
.db-prop-textarea {
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}
.db-prop-textarea { resize: vertical; min-height: 54px; }
.db-prop-row { display: flex; gap: 6px; }
.db-prop-row .db-prop-input,
.db-prop-row .db-prop-select { flex: 1; min-width: 0; }

.db-prop-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2px 0;
}
.db-prop-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Color preview swatch */
.db-color-row { display: flex; gap: 6px; align-items: center; }
.db-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    border: 1px solid var(--border);
    flex-shrink: 0;
    cursor: pointer;
}

/* Variable picker trigger */
.db-var-picker-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-main);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.db-var-picker-btn:hover { border-color: var(--accent); }
.db-var-picker-btn span { overflow:hidden; text-overflow:ellipsis; flex:1; }

/* ---------- Element wrappers on canvas ---------- */
.db-el {
    position: absolute;
    box-sizing: border-box;
    overflow: hidden;
}

/* Selection highlight */
.db-el.db-selected {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Resize handles */
.db-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent);
    border: 1px solid #fff;
    border-radius: 2px;
    z-index: 60;
    cursor: nwse-resize;
}
.db-handle[data-h="n"]  { top:-5px; left:50%; transform:translateX(-50%); cursor:ns-resize; }
.db-handle[data-h="s"]  { bottom:-5px; left:50%; transform:translateX(-50%); cursor:ns-resize; }
.db-handle[data-h="w"]  { left:-5px; top:50%; transform:translateY(-50%); cursor:ew-resize; }
.db-handle[data-h="e"]  { right:-5px; top:50%; transform:translateY(-50%); cursor:ew-resize; }
.db-handle[data-h="nw"] { top:-5px; left:-5px; cursor:nwse-resize; }
.db-handle[data-h="ne"] { top:-5px; right:-5px; cursor:nesw-resize; }
.db-handle[data-h="sw"] { bottom:-5px; left:-5px; cursor:nesw-resize; }
.db-handle[data-h="se"] { bottom:-5px; right:-5px; cursor:nwse-resize; }

/* ---------- Widget: bg_photo ---------- */
.db-w-bg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* ---------- Widget: text_static ---------- */
.db-w-text {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    word-break: break-word;
    text-align: center;
    padding: 4px;
    box-sizing: border-box;
}

/* ---------- Widget: value ---------- */
.db-w-value {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
    box-sizing: border-box;
    overflow: hidden;
}
.db-w-value-label {
    font-size: 10px;
    color: var(--text-dim);
    text-align: center;
    line-height: 1.2;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}
.db-w-value-num {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}
.db-w-value-unit {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}
.db-w-value.db-alert-flash { animation: db-flash 1s infinite; }
@keyframes db-flash {
    0%,100% { opacity:1; }
    50%      { opacity:.35; }
}

/* ---------- Widget: value_bool ---------- */
.db-w-bool {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    overflow: hidden;
}
.db-bool-led {
    border-radius: 50%;
    flex-shrink: 0;
}
.db-bool-led.square { border-radius: 4px; }
.db-bool-led.on  { box-shadow: 0 0 10px 4px currentColor; }
.db-bool-led.off { opacity: .35; box-shadow: none; }
.db-bool-text {
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
}
/* Badge / pill */
.db-bool-badge {
    padding: 5px 16px;
    border-radius: 999px;
    color: #fff !important;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: background .25s, box-shadow .25s;
    white-space: nowrap;
}
.db-bool-badge.on  { box-shadow: 0 0 14px 2px currentColor; }
.db-bool-badge.off { opacity: .55; box-shadow: none; }

/* Bouton power */
.db-bool-power {
    border-radius: 50%;
    padding: 14%;
    border: 2.5px solid currentColor;
    box-sizing: border-box;
    transition: color .25s, box-shadow .25s, opacity .25s;
    flex-shrink: 0;
}
.db-bool-power svg { width: 100%; height: 100%; display: block; }
.db-bool-power.on  { box-shadow: 0 0 18px 5px currentColor; }
.db-bool-power.off { opacity: .3; box-shadow: none; }

/* Losange industriel */
.db-bool-diamond {
    transform: rotate(45deg);
    border-radius: 6px;
    flex-shrink: 0;
    transition: background .25s, box-shadow .25s, opacity .25s;
}
.db-bool-diamond.on  { box-shadow: 0 0 14px 4px currentColor; }
.db-bool-diamond.off { opacity: .3; box-shadow: none; }

/* Feu bicolore */
.db-bool-traffic {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: #111;
    padding: 7px 9px;
    border-radius: 12px;
    align-items: center;
    border: 2px solid #2a2a2a;
}
.db-bool-traffic-bulb {
    border-radius: 50%;
    flex-shrink: 0;
    transition: opacity .25s, box-shadow .25s;
}
.db-bool-traffic-bulb.on { box-shadow: 0 0 10px 3px currentColor; }

/* Sous-étiquette partagée */
.db-bool-sublabel {
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    margin-top: 2px;
}

/* ---------- Widget: gauge ---------- */
.db-w-gauge {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.db-w-gauge svg { overflow: visible; }
.db-w-gauge canvas.db-cg-canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ---------- Widget: level_bar ---------- */
.db-w-level {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px;
    box-sizing: border-box;
    overflow: hidden;
}
.db-level-track {
    width: 100%;
    flex: 1;
    background: rgba(255,255,255,.08);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}
.db-level-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    border-radius: 4px;
    transition: height .4s ease;
}
.db-level-track.horizontal .db-level-fill {
    top: 0;
    bottom: auto;
    height: 100%;
    width: 0;
    transition: width .4s ease;
}
.db-level-val {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

/* ---------- Widget: table_multi ---------- */
.db-w-table {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 4px;
    box-sizing: border-box;
}
.db-w-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.db-w-table td, .db-w-table th {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    text-align: left;
    white-space: nowrap;
}
.db-w-table th { color: var(--text-dim); font-weight: 400; }
.db-w-table td.val-cell { font-weight: 700; text-align: right; }
.db-trow-alert { color: var(--danger); }

/* ---------- Widget: chart (evolution + profile2d) ---------- */
.db-w-chart {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}
.db-w-chart canvas { width:100% !important; height:100% !important; }

/* Stats profil */
.db-profile-stats {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,.1);
    background: rgba(0,0,0,.25);
}
.db-ps-cell {
    flex: 1;
    text-align: center;
    padding: 2px 1px;
    border-right: 1px solid rgba(255,255,255,.07);
}
.db-ps-cell:last-child { border-right: none; }
.db-ps-lbl { font-size: 8px; color: rgba(255,255,255,.4); line-height: 1.2; }
.db-ps-val { font-size: 9px; font-weight: 600; color: rgba(255,255,255,.8); line-height: 1.2; }

/* Étiquette externe */
.db-ext-label {
    position: absolute;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    color: var(--text-muted);
    line-height: 1.3;
}

/* ---------- Widget: clock ---------- */
.db-w-clock {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.db-clock-time {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 2px;
    line-height: 1;
}
.db-clock-date {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ---------- Widget: multi_text ---------- */
.db-w-multi-text {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    word-break: break-word;
    padding: 6px;
    box-sizing: border-box;
}
.db-w-multi-text.db-w-multi-left   { justify-content: flex-start; text-align: left; }
.db-w-multi-text.db-w-multi-center { justify-content: center; text-align: center; }
.db-w-multi-text.db-w-multi-right  { justify-content: flex-end; text-align: right; }

/* ---------- Modal base ---------- */
.db-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.db-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: min(560px, 95vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}
.db-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.db-modal-title { font-weight: 600; font-size: 13px; }
.db-modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.db-modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 16px;
}
.db-modal-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

/* Drop zone image de fond */
.db-img-dropzone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    background: var(--bg-card);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
}
.db-img-dropzone:hover { border-color: var(--accent); background: rgba(59,130,246,.05); }
.db-img-dropzone.dragover { border-color: var(--accent); background: rgba(59,130,246,.12); }
.db-img-dropzone-icon { font-size: 38px; line-height: 1; }
.db-img-dropzone-text { font-size: 13px; color: var(--text-muted); line-height: 1.7; }
.db-img-dropzone-link { color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 12px; }

/* Variable picker — grand modal dédié */
.db-modal-var {
    width: min(960px, 96vw);
    height: min(680px, 88vh);
    max-height: none;
}
.db-modal-var .db-modal-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: hidden;
}

/* Barre de recherche */
.db-var-searchbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-panel);
}
.db-var-search {
    flex: 1;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 5px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    outline: none;
    transition: border-color .15s;
}
.db-var-search:focus { border-color: var(--accent); }
.db-var-search-clear {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color .1s;
}
.db-var-search-clear:hover { color: var(--danger); }

/* Onglets type */
.db-var-tabs {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.db-var-tab {
    padding: 5px 14px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
}
.db-var-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Bandeau résultats */
.db-var-count {
    padding: 5px 16px;
    font-size: 11px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    gap: 10px;
}
.db-var-count-num { color: var(--accent); font-weight: 600; }

/* Liste défilante */
.db-var-list-wrap {
    flex: 1 1 0;
    overflow-y: auto;
    padding: 6px 10px;
}
.db-var-list { display: flex; flex-direction: column; gap: 1px; }

/* Item de variable */
.db-var-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 5px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .1s;
}
.db-var-item:hover  { background: var(--bg-hover); }
.db-var-item.selected {
    background: var(--accent-dim, rgba(59,130,246,.15));
    border-color: var(--accent);
}
.db-var-item-label {
    flex: 1;
    font-size: 13px;
    color: var(--text-main);
    line-height: 1.3;
}
.db-var-item-label em {
    font-style: normal;
    background: rgba(59,130,246,.35);
    border-radius: 2px;
    padding: 0 2px;
}
.db-var-item-table {
    font-size: 11px;
    color: var(--text-dim);
    font-family: 'Courier New', monospace;
    white-space: nowrap;
    flex-shrink: 0;
}
.db-var-item-badge {
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 3px;
    background: rgba(245,158,11,.18);
    color: #f59e0b;
    flex-shrink: 0;
}

/* État "chargement" / "vide" */
.db-var-state {
    padding: 30px 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}
.db-var-state-spin {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: db-spin .7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes db-spin { to { transform: rotate(360deg); } }

/* Pied de modal — affiche la sélection courante */
.db-var-footer-sel {
    flex: 1;
    font-size: 12px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.db-var-footer-sel strong { color: var(--text-main); }
