:root {
    --bg: #0b1020;
    --panel: #0f172a;
    --border: #1f2937;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --primary: #2563eb;
    --danger: #ef4444;
    --accent: #6366f1;
    --ok: #10b981;

    /* Variabili usate dall'editor (personalizza qui i colori) */
    --editor-bg: var(--panel); /* sfondo area testo */
    --editor-fg: var(--text); /* testo + caret */
    --editor-muted: var(--muted); /* testo gutter */
    --editor-gutter-bg: var(--panel); /* sfondo gutter */
    --editor-selection: rgba(37, 99, 235, 0.25);
    --editor-active-line: rgba(255, 255, 255, 0.04);

    /* editor font vars (JS sets from config) */
    --editor-font-family:
        ui-monospace, SFMono-Regular, Menlo, "Roboto Mono", "JetBrains Mono",
        monospace;
    --editor-font-size: 14px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        ui-sans-serif,
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        Ubuntu,
        Cantarell,
        Noto Sans,
        "Helvetica Neue",
        Arial,
        "Apple Color Emoji",
        "Segoe UI Emoji";
}

/* App shell */
.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.toolbar {
    height: 48px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.toolbar__left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    white-space: nowrap;
}
.brand {
    font-weight: 600;
    font-size: 16px;
}
.ws {
    color: var(--muted);
    font-size: 12px;
}
.ws__name {
    color: var(--text);
}
.filters {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow-x: auto;
    padding: 4px 0;
    justify-content: center;
}
.toolbar__right {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    white-space: nowrap;
}

/* User */
.user {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    margin-right: 6px;
}
.user [data-lucide] {
    width: 16px;
    height: 16px;
    color: var(--muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 13px;
    white-space: nowrap;
}
.btn span[data-lucide] {
    width: 18px;
    height: 18px;
}
.btn:hover {
    background: rgba(255, 255, 255, 0.06);
}
.btn.primary {
    border-color: var(--primary);
    color: #bfdbfe;
}
.btn.primary:hover {
    background: rgba(37, 99, 235, 0.15);
}
.btn.danger {
    border-color: var(--danger);
    color: #fecaca;
}
.btn.danger:hover {
    background: rgba(239, 68, 68, 0.15);
}
.btn--xs {
    padding: 2px 6px;
    font-size: 12px;
}
.chk {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* Link-ish text */
.link {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Root layout */
#layout-root {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 48px);
    min-height: 0;
}

/* Sidebar */
#sidebar {
    display: flex;
    flex-direction: column;
    min-width: 180px;
    width: 260px;
    max-width: 45vw;
    background: #0d1428;
    border-right: 1px solid var(--border);
    height: 100%;
    overflow: hidden;
}
.sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.sidebar__title {
    color: var(--muted);
    font-size: 12px;
}
.sidebar__tools {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tree {
    padding: 6px;
    overflow: auto;
    height: auto;
    flex: 1 1 auto;
    font-size: 14px;
}
.tree .dir,
.tree .file {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}
.tree .dir:hover,
.tree .file:hover {
    background: rgba(255, 255, 255, 0.06);
}
.tree .file.active {
    background: rgba(37, 99, 235, 0.15);
    border: 1px solid rgba(37, 99, 235, 0.4);
}

/* Sidebar filters (bottom, vertical) */
.sidebar__filters {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 8px;
    background: #0c152b;
}
.sidebar__filters__title {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}
.filters--sidebar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    overflow-x: hidden;
}
.flt {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
}
.flt input {
    margin: 0;
}
.flt__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: monospace;
    /*font-size: 13px;*/
}
.flt__chip [data-lucide] {
    width: 16px;
    height: 16px;
}
.flt__chip .emoji {
    display: inline-block;
    font-size: 14px;
    line-height: 1;
    vertical-align: middle;
}

/* Main column */
#main {
    display: flex;
    flex-direction: column;
    min-width: 280px;
    height: 100%;
    overflow: hidden;
}
.filemeta {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    font-size: 12px;
}
.muted {
    color: var(--muted);
}

/* Split area */
#split-root {
    display: flex;
    flex-direction: row;
    height: 100%;
    min-height: 0;
}
.pane {
    height: 100%;
    overflow: hidden;
    min-width: 0;
}

/* Editor: force correct metrics and scrolling */
#editor {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#editor .cm-editor {
    height: 100%;
    font-family: var(--editor-font-family);
    font-size: var(--editor-font-size);
    line-height: 1.4;
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeSpeed;
}
/* ensure the caret math uses content-box */
#editor .cm-editor,
#editor .cm-scroller,
#editor .cm-content,
#editor .cm-gutters {
    box-sizing: content-box;
}
#editor .cm-content {
    font-family: inherit;
    font-size: inherit;
    font-variant-ligatures: none; /* disable ligatures (caret stays exact) */
}
#editor .cm-scroller {
    overflow: auto;
    scrollbar-gutter: stable;
}

/* Split.js gutters */
.gutter {
    background: rgba(255, 255, 255, 0.06);
    flex: 0 0 auto;
    background-position: 50%;
    background-repeat: no-repeat;
}
.gutter.gutter-horizontal {
    cursor: col-resize;
    width: 6px;
}
.gutter.gutter-vertical {
    cursor: row-resize;
    height: 6px;
}

/* Preview */
.render {
    padding: 16px;
    overflow: auto;
    height: 100%;
}
/* Hide vertical guides if requested */
.render.no-guides .ec-item,
.render.no-guides .ec-text {
    border-left-width: 0;
    padding-left: 0;
}

/* Forms */
.in {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 6px;
}
.form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.w-full {
    width: 100%;
}
.err {
    color: #fca5a5;
    font-size: 12px;
}

/* Overlays */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.9);
    display: grid;
    place-items: center;
    z-index: 100;
}
.overlay.hidden {
    display: none;
}
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 18px;
    border-radius: 10px;
    width: 420px;
    max-width: calc(100vw - 24px);
}
.card h2 {
    margin: 0 0 6px 0;
}

/* History panel */
.history-card {
    width: 560px;
}
.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}
.history-list {
    max-height: 60vh;
    overflow: auto;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    font-size: 13px;
}
.history-list .row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.history-list .ts {
    color: var(--muted);
}
.history-list .msg {
    color: var(--text);
}

/* Context menu */
.ctx-menu {
    position: fixed;
    z-index: 200;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    padding: 6px;
    min-width: 160px;
}
.ctx-menu.hidden {
    display: none;
}
.ctx-item {
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: var(--text);
    border: none;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.ctx-item:hover {
    background: rgba(255, 255, 255, 0.06);
}
.ctx-item.danger {
    color: #fecaca;
}

/* Checklist */
.ec-list {
    list-style: none;
    padding-left: 0;
    margin-left: 0;
}
.ec-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    border-left: 2px solid var(--ec-color, #374151);
    padding-left: 10px;
    margin: 6px 0;
}
.ec-item .ec-icon,
.ec-item .ec-code,
.ec-item .ec-title {
    display: inline-flex;
    align-items: center;
}
.ec-item .ec-icon {
    width: 18px;
    height: 18px;
    margin-right: 6px;
    color: var(--ec-color, #9ca3af);
}
.ec-item .ec-emoji {
    font-size: 14px;
    line-height: 1;
}
.ec-item .ec-code {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    margin-right: 8px;
    color: #d1d5db;
    line-height: 1;
}
.ec-item .ec-code.ec-unknown {
    background: rgba(239, 68, 68, 0.15);
    color: #fecaca;
}
.ec-item .ec-title {
    margin-right: 8px;
}

/* Effects */
.ec-eff-dim {
    opacity: 0.65;
}
.ec-eff-strike .ec-title {
    text-decoration: line-through;
    text-decoration-color: rgba(255, 255, 255, 0.8);
}
.ec-eff-colored .ec-title {
    color: var(--ec-color, var(--text));
}
/* forced color effects */
.ec-eff-force-red .ec-title {
    color: var(--danger);
}
.ec-eff-force-blue .ec-title {
    color: var(--primary);
}

/* Info + comments */
.ec-item .ec-info {
    margin-left: 6px;
    opacity: 0.9;
    background: transparent;
    border: none;
    color: #93c5fd;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
.ec-item .ec-info [data-lucide] {
    width: 14px;
    height: 14px;
}
.ec-item .ec-comment {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 6px 8px;
    font-size: 12px;
    color: #a7f3d0;
    background: rgba(16, 185, 129, 0.08);
    border-radius: 6px;
}
.ec-item .ec-comment[data-visible="false"] {
    display: none;
}
.ec-item:hover .ec-comment[data-visible="false"] {
    display: block;
}

/* Children below */
.ec-item > .ec-list {
    flex: 1 1 100%;
    width: 100%;
    margin-top: 6px;
}

/* Plain text blocks */
.ec-text {
    border-left: 2px solid var(--ec-color, #374151);
    padding-left: 10px;
    margin: 6px 0;
}
.ec-text .ec-txt {
    color: var(--text);
}

/* Info icon toggled by comments visibility */
.render[data-comments="on"] .ec-info {
    display: none;
}
.render[data-comments="off"] .ec-info {
    display: inline-flex;
}
