/* ===== RESET ===== */
*,
*::before,
*::after {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
}

/* ===== THEMES ===== */
:root {
        --bg: #1F1F1F;
        --card: #232323;
        --card-h: #2C2C2C;
        --border: #333;
        --text: #E8E8E8;
        --text-muted: #888;
        --accent: #5B8DEF;
        --accent-h: #4A7ADE;
        --accent-dim: rgba(91, 141, 239, 0.10);
        --danger: #E05252;
        --warn: #E09252;
        --header-h: 52px;
        --radius: 10px;
        --font: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
        --editor-fs: 14px;
}

:root.light {
        --bg: #F4F4F4;
        --card: #FFFFFF;
        --card-h: #EBEBEB;
        --border: #DEDEDE;
        --text: #1A1A1A;
        --text-muted: #777;
        --accent: #1A73E8;
        --accent-h: #1558B0;
        --accent-dim: rgba(26, 115, 232, 0.09);
}

:root.black {
        --bg: #000000;
        --card: #0D0D0D;
        --card-h: #161616;
        --border: #222;
        --text: #EDEEEF;
        --text-muted: #666;
        --accent: #7BAAF7;
        --accent-h: #5E96F5;
        --accent-dim: rgba(123, 170, 247, 0.09);
}

html,
body {
        height: 100%;
        background: var(--bg);
        color: var(--text);
        font-family: var(--font);
        font-size: 13px;
        -webkit-font-smoothing: antialiased;
        overflow: hidden;
}

/* ===== APP ===== */
#app {
        display: flex;
        height: calc(var(--vh, 1vh) * 100);
        width: 100%;
}

/* ===== BLOCKS (mobile) ===== */
.block {
        display: none;
        flex-direction: column;
        width: 100%;
        height: calc(var(--vh, 1vh) * 100);
        overflow: hidden;
}

.block.active {
        display: flex;
}

/* ===== DESKTOP ===== */
@media (min-width: 700px) {
        #block1 {
                display: flex;
                width: 280px;
                min-width: 260px;
                flex-shrink: 0;
                border-right: 1px solid var(--border);
        }

        #block2 {
                display: flex;
                flex: 1;
                min-height: 0;
        }

        #block2-inner {
                display: flex;
                flex-direction: column;
                width: 100%;
                max-width: 750px;
                margin: 0 auto;
                height: 100%;
                min-height: 0;
        }
}

@media (max-width: 699px) {
        #block2-inner {
                display: flex;
                flex-direction: column;
                width: 100%;
                height: 100%;
                min-height: 0;
        }
}

/* ===== HEADER ===== */
.block-header {
        display: flex;
        align-items: center;
        gap: 4px;
        height: var(--header-h);
        padding: 0 10px;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
}

.header-editor {
        margin: 0 10px;
        border-right: 1px solid var(--border);
        border-left: 1px solid var(--border);
        border-bottom-left-radius: var(--radius);
        border-bottom-right-radius: var(--radius);
}

.header-logo {
        font-size: 17px;
        font-weight: 700;
        letter-spacing: -0.5px;
        color: var(--text);
}

.header-logo span {
        color: var(--accent);
}

.header-left {
        display: flex;
        align-items: center;
        gap: 2px;
        flex: 1;
}

.header-title {
        flex: 1;
        font-size: 13px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
}

/* ===== ICON BUTTONS ===== */
.btn-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        border: none;
        background: transparent;
        color: var(--text-muted);
        border-radius: 8px;
        cursor: pointer;
        transition: background .15s, color .15s;
        flex-shrink: 0;
}

.btn-icon:hover {
        background: var(--card-h);
        color: var(--text);
}

.btn-icon:active {
        opacity: .7;
}

.btn-icon svg {
        display: block;
}

/* ===== LIST ===== */
.block-list {
        flex: 1;
        overflow-y: auto;
        padding: 8px;
        display: flex;
        flex-direction: column;
        gap: 4px;
}

.block-list::-webkit-scrollbar {
        width: 3px;
}

.block-list::-webkit-scrollbar-track {
        background: transparent;
}

.block-list::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 2px;
}

/* ===== FOLDER CARD ===== */
.folder-card {
        display: flex;
        align-items: center;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 0 6px 0 12px;
        height: 44px;
        gap: 8px;
        cursor: pointer;
        transition: background .15s;
        user-select: none;
}

.folder-card:hover,
.folder-card.active {
        background: var(--card-h);
}

.folder-card.active .folder-name,
.folder-card:hover .folder-name {
        color: var(--accent);
}

.folder-icon {
        font-size: 13px;
        flex-shrink: 0;
        color: var(--accent);
}

.folder-name {
        flex: 1;
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        transition: color .15s;
}

/* ===== EDITOR ===== */
.editor-wrap {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 12px;
        display: flex;
        flex-direction: column;
        background: var(--bg);
}

.editor-wrap::-webkit-scrollbar {
        width: 3px;
}

.editor-wrap::-webkit-scrollbar-track {
        background: transparent;
}

.editor-wrap::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 2px;
}

pre#editor {
        flex: 1;
        min-height: calc(100% - 24px);
        font-family: var(--font);
        font-size: var(--editor-fs);
        line-height: 1.7;
        color: var(--text);
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 14px 16px;
        outline: none;
        white-space: pre-wrap;
        word-break: break-word;
        caret-color: var(--accent);
        transition: border-color .15s;
}

pre#editor:focus {
        /* border-color: var(--accent); */
        box-shadow: 0px 0px 2px 0px #5b8def;
}

pre#editor:empty::before {
        content: attr(placeholder);
        color: var(--text-muted);
        pointer-events: none;
}

/* ===== EMPTY STATE ===== */
.empty-state {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        color: var(--text-muted);
        font-size: 12px;
        gap: 10px;
        padding: 32px;
        text-align: center;
        opacity: .45;
}

.empty-icon {
        font-size: 28px;
}

/* ===== DIRTY DOT ===== */
.dirty-dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #4CAF50;
        opacity: 0;
        transition: opacity .2s, background .2s;
        flex-shrink: 0;
}

.dirty-dot.show {
        opacity: 1;
        background: #4CAF50;
}

/* сохранено — зелёный */
.dirty-dot.show.dirty {
        background: #FFC107;
}

/* редактируется — жёлтый */

/* ===== OVERLAY ===== */
.overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .6);
        backdrop-filter: blur(3px);
        z-index: 100;
        align-items: flex-end;
        justify-content: center;
}

.overlay.open {
        display: flex;
}

/* ===== POPUP (bottom sheet) ===== */
.popup {
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 14px 14px 0 0;
        width: 100%;
        max-width: 480px;
        overflow: hidden;
        padding-bottom: env(safe-area-inset-bottom, 6px);
}

.popup-handle {
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--border);
        margin: 10px auto 0;
}

.popup-title {
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .1em;
        text-transform: uppercase;
        color: var(--text-muted);
        padding: 12px 16px 10px;
}

.popup-input {
        width: 100%;
        background: var(--card-h);
        border: none;
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        padding: 12px 16px;
        font-family: var(--font);
        font-size: 13px;
        color: var(--text);
        outline: none;
        transition: border-bottom-color .15s;
}

.popup-input:focus {
        border-bottom-color: var(--accent);
}

.popup-actions {
        display: flex;
}

.popup-btn {
        flex: 1;
        height: 46px;
        border: none;
        background: transparent;
        color: var(--text-muted);
        font-family: var(--font);
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: background .15s, color .15s;
        border-top: 1px solid var(--border);
}

.popup-btn:not(:last-child) {
        border-right: 1px solid var(--border);
}

.popup-btn:hover:not(:disabled) {
        background: var(--card-h);
        color: var(--text);
}

.popup-btn:disabled {
        opacity: .3;
        cursor: not-allowed;
}

.popup-btn.primary {
        color: var(--accent);
}

.popup-btn.primary:hover:not(:disabled) {
        color: var(--accent-h);
}

.popup-btn.danger {
        color: var(--danger);
}

.popup-btn.danger-active {
        background: var(--danger) !important;
        color: #fff !important;
}

.popup-btn.warn-text {
        color: var(--warn) !important;
}

/* ===== SETTINGS ===== */
.settings-section {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
        border-bottom: none;
}

.settings-label {
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .1em;
        text-transform: uppercase;
        color: var(--text-muted);
        margin-bottom: 10px;
}

.theme-switcher {
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 8px;
        display: flex;
        padding: 3px;
        position: relative;
        overflow: hidden;
}

.theme-switcher input {
        display: none;
}

.t-slider {
        position: absolute;
        z-index: 1;
        width: calc((100% - 6px) / 3);
        top: 3px;
        bottom: 3px;
        left: 3px;
        border-radius: 5px;
        background: var(--card-h);
        border: 1px solid var(--border);
        transition: transform .2s cubic-bezier(.4, 0, .2, 1);
        pointer-events: none;
}

.theme-switcher input:nth-of-type(1):checked~.t-slider {
        transform: translateX(0);
}

.theme-switcher input:nth-of-type(2):checked~.t-slider {
        transform: translateX(100%);
}

.theme-switcher input:nth-of-type(3):checked~.t-slider {
        transform: translateX(200%);
}

.theme-switcher label {
        position: relative;
        z-index: 2;
        width: calc(100% / 3);
        cursor: pointer;
}

.theme-switcher label span {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 7px 0;
        font-size: 11px;
        font-weight: 700;
        color: var(--text-muted);
        letter-spacing: .04em;
        transition: color .15s;
}

.theme-switcher input:checked+label span {
        color: var(--text);
}

.slider-row {
        display: flex;
        align-items: center;
        gap: 10px;
}

.slider-val {
        font-size: 11px;
        color: var(--accent);
        width: 30px;
        text-align: right;
        flex-shrink: 0;
}

input[type=range] {
        flex: 1;
        -webkit-appearance: none;
        height: 3px;
        border-radius: 2px;
        background: var(--border);
        outline: none;
        cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 15px;
        height: 15px;
        border-radius: 50%;
        background: var(--accent);
        box-shadow: 0 0 0 3px var(--accent-dim);
        transition: box-shadow .15s;
}

input[type=range]::-webkit-slider-thumb:hover {
        box-shadow: 0 0 0 5px var(--accent-dim);
}

.slider-ends {
        display: flex;
        justify-content: space-between;
        font-size: 10px;
        color: var(--text-muted);
        margin-top: 4px;
}

/* ===== TOAST ===== */
#toast {
        position: fixed;
        bottom: 28px;
        left: 50%;
        transform: translateX(-50%) translateY(10px);
        background: var(--card);
        border: 1px solid var(--border);
        color: var(--text);
        padding: 9px 18px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        box-shadow: 0 4px 20px rgba(0, 0, 0, .4);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s, transform .2s;
        z-index: 300;
        white-space: nowrap;
}

#toast.show {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
}

#toast.ok {
        border-color: var(--accent);
        color: var(--accent);
}

#toast.err {
        border-color: var(--danger);
        color: var(--danger);
}