/*
 * editor.css — superficie dell'Editor (CodeMirror 6).
 *
 * Riusa i colori e i caratteri già presenti (app.css / main_workspace.css):
 * non introduce un secondo tema. Il motore CodeMirror ha il suo tema in
 * `frontend/editor-src/entry.js`; qui c'è solo la CORNICE (barra, schede,
 * stato, selettore file).
 */

#page-editor.page.active {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 132px);
    min-height: 420px;
    margin: -8px -4px 0;
}

#editor-page-root,
.mw-editor-host {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    display: flex;
}

.ai-editor-root {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
}

.ai-editor {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #0d0d1a;
    border: 1px solid #2a2a3e;
    border-radius: 6px;
    overflow: hidden;
}

.ai-editor [hidden] {
    display: none !important;
}

.ai-editor-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #11111f;
    border-bottom: 1px solid #2a2a3e;
    min-height: 36px;
    flex-wrap: wrap;
}

.ai-editor-context {
    font-size: 12px;
    color: #8a93a6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 46%;
}

.ai-editor-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ai-editor-btn {
    appearance: none;
    border: 1px solid #3a3a52;
    background: #1a1a2e;
    color: #d6d9e0;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-editor-btn:hover:not(:disabled) { background: #24243c; }
.ai-editor-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ai-editor-btn--primary { background: #2f5d8a; border-color: #3d73a8; color: #fff; }
.ai-editor-btn--primary:hover:not(:disabled) { background: #36699b; }
.ai-editor-btn--quiet { background: transparent; border-color: transparent; color: #9aa3b5; }
.ai-editor-btn--quiet:hover:not(:disabled) { background: #1a1a2e; }

.ai-editor-select {
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    max-width: 240px;
}

.ai-editor-status {
    flex: 0 0 auto;
    font-size: 11px;
    color: #8a93a6;
    padding: 3px 10px;
    background: #0b0b16;
    border-bottom: 1px solid #1d1d2e;
    min-height: 22px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-editor-status[data-tone="live"] { color: #63c98a; }
.ai-editor-status[data-tone="warn"] { color: #f0b64a; }
.ai-editor-status[data-tone="dead"] { color: #f27a7a; }

.ai-editor-tabs {
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
    gap: 1px;
    background: #11111f;
    border-bottom: 1px solid #2a2a3e;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.ai-editor-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 12px;
    color: #9aa3b5;
    background: #141424;
    border-right: 1px solid #24243a;
    cursor: pointer;
    white-space: nowrap;
    max-width: 220px;
}

.ai-editor-tab.is-active { color: #e8ebf2; background: #0d0d1a; box-shadow: inset 0 -2px 0 #4f7fbf; }
.ai-editor-tab-name { overflow: hidden; text-overflow: ellipsis; }
.ai-editor-tab-dirty { color: #f0b64a; font-size: 10px; }
.ai-editor-tab-external { color: #f27a7a; font-weight: 700; font-size: 11px; }
.ai-editor-tab-close {
    appearance: none;
    border: 0;
    background: transparent;
    color: #6d7688;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.ai-editor-tab-close:hover { color: #f27a7a; }

.ai-editor-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    position: relative;
}

.ai-editor-pane {
    display: none;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
}

.ai-editor-pane.is-active { display: flex; }
.ai-editor-cm { flex: 1 1 auto; min-width: 0; min-height: 0; }
.ai-editor-cm .cm-editor { height: 100%; }

.ai-editor-empty {
    flex: 1 1 auto;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    text-align: center;
    color: #8a93a6;
}

.ai-editor-empty-title { margin: 0; font-size: 14px; color: #cfd4de; }
.ai-editor-empty-hint { margin: 0 0 8px; font-size: 12px; max-width: 520px; line-height: 1.5; }

/* ── Selettore file (API canonica /workspaces/:id/entries) ─────────────── */
.ai-editor-picker {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: rgba(8, 8, 18, 0.98);
    border-top: 1px solid #2a2a3e;
}

.ai-editor-picker-head { display: flex; align-items: center; gap: 8px; }
.ai-editor-picker-title { font-size: 13px; color: #d6d9e0; flex: 1 1 auto; }
.ai-editor-picker-crumbs { display: flex; align-items: center; gap: 8px; }
.ai-editor-picker-path {
    font-family: Consolas, "Cascadia Mono", monospace;
    font-size: 12px;
    color: #aab3c5;
    background: #11111f;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    padding: 3px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}

.ai-editor-picker-manual { display: flex; gap: 6px; }
.ai-editor-input {
    flex: 1 1 auto;
    background: #0d0d1a;
    color: #e0e0e0;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 12px;
}

.ai-editor-picker-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    background: #0b0b16;
    padding: 4px;
}

.ai-editor-picker-item {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: #d6d9e0;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.ai-editor-picker-item:hover:not(:disabled) { background: #1a1a2e; }
.ai-editor-picker-item:disabled { color: #5a6275; cursor: not-allowed; }
.ai-editor-picker-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-editor-picker-meta { font-size: 11px; color: #6d7688; white-space: nowrap; }

/* ── Mobile: il motore è lo stesso, la cornice si adatta ───────────────── */
@media (max-width: 768px) {
    #page-editor.page.active { height: calc(100vh - 96px); min-height: 320px; margin: 0; }
    .ai-editor { border-radius: 0; border-left: 0; border-right: 0; }
    .ai-editor-bar { gap: 6px; padding: 6px; }
    .ai-editor-context { max-width: 100%; flex-basis: 100%; order: -1; white-space: normal; }
    .ai-editor-actions { margin-left: 0; width: 100%; }
    .ai-editor-select { flex: 1 1 auto; max-width: none; }
    .ai-editor-tab { max-width: 160px; }
    .ai-editor-picker { padding: 8px; }
}
