* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --layout-left-width: 320px;
    --layout-divider-color: #2a2b30;
    --bg-page: #0c0d0f;
    --bg-sidebar: #18191d;
    --border-sidebar: #2a2b30;
    --text-primary: #e4e4e7;
    --text-muted: #8b8c92;
    --text-section: #6a6b71;
    --hover-bg: #222327;
    --active-bg: #34353c;
    --icon-default: #9a9ba1;
    --icon-active: #f2f2f3;
    --logo-blue: #2f8dfb;
    --pin-color: #B04542;
    --pin-color: #cc6944;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: var(--app-vh-100, 100vh);
    overflow-x: hidden;
    padding-top: env(safe-area-inset-top, 0px);
}

.layout-two-col {
    flex: 1;
}

@media (min-width: 768px) {
    .layout-col-left {
        height: var(--app-vh-100, 100vh);
        overflow-y: auto;
    }

    .layout-col-right {
        height: var(--app-vh-100, 100vh);
    }
}

.right-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-section);
    font-size: 14px;
    text-align: center;
    padding: 24px;
}

@media (min-width: 768px) {
    .layout-col-right {
        flex-direction: row;
    }
}

.app-middle {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.app-right-panel {
    width: 320px;
    flex-shrink: 0;
    border-left: 1px solid var(--border-sidebar);
}

.notebook-card {
    width: 100%;
    max-width: 750px;
    margin: 5px auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-sidebar);
    border-radius: 12px 12px 0 0;
    overflow: hidden;
}

.card-header {
    height: 48px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    padding: 0 8px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-sidebar);
}

.card-elems {
    flex: 1;
    overflow-y: auto;
    overflow-x: clip;
    display: flex;
    flex-direction: column;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-sidebar) transparent;
}

.card-elems::-webkit-scrollbar {
    width: 6px;
}

.card-elems::-webkit-scrollbar-track {
    background: transparent;
}

.card-elems::-webkit-scrollbar-thumb {
    background: var(--border-sidebar);
    border-radius: 3px;
}

.card-elems::-webkit-scrollbar-thumb:hover {
    background: var(--active-bg);
}

.card-field-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
}

.card-elems .card-field-wrap:last-child {
    flex: 1;
    min-height: 0;
}

.card-field-wrap .card-field {
    flex: 1;
    min-height: 0;
}

.card-field {
    background: transparent;
    color: var(--text-primary);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 40px 8px 10px;
    border: none;
    border-bottom: 1px solid var(--border-sidebar);
    border-radius: 0;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    caret-color: var(--logo-blue);
    position: relative;
}

.card-field:empty::after {
    content: "Начните печатать…";
    color: var(--text-section);
    position: absolute;
    top: 8px;
    left: 10px;
    white-space: nowrap;
    pointer-events: none;
}

.card-field::before {
    content: "";
    float: right;
    width: 30px;
    height: 21px;
    shape-outside: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

.card-field:focus {
    border-bottom-color: var(--logo-blue);
    box-shadow: none;
}

.card-field-wrap:last-child .card-field {
    border-bottom: none;
}

/* ─── Inline-меню в уголке поля ─── */
.card-field-menu-btn {
    position: absolute;
    top: 3px;
    right: 6px;
    z-index: 2;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--icon-default);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

@media (hover: hover) {
    .card-field-menu-btn:hover {
        border-color: var(--border-sidebar);
    }
}

.card-field-menu-btn:active {
    background-color: var(--hover-bg);
}

.card-field-menu-btn.hiding {
    opacity: 0;
    pointer-events: none;
}

.field-inline-menu {
    position: absolute;
    top: 4.5px;
    right: 6px;
    z-index: 3;
    display: flex;
    flex-direction: row;
    gap: 4px;
    transform: translateX(calc(100% + 10px));
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.field-inline-menu.visible {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.inline-menu-btn {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.15s ease;
}

@media (hover: hover) {
    .inline-menu-btn:hover {
        background-color: var(--hover-bg);
    }

    .inline-menu-btn[data-action="close"]:hover {
        border: 1px solid #5d2f33;
    }

    .inline-menu-btn[data-action="close"]:hover .icon-inline-close {
        background-color: #ff5d56;
    }

}

.inline-menu-btn.highlighted {
    background-color: var(--active-bg);
}

.inline-menu-icon {
    width: 16px;
    height: 16px;
    background-color: var(--icon-default);
    mask-size: cover;
    transition: background-color 0.15s ease;
}

@media (hover: hover) {
    .inline-menu-btn:hover .inline-menu-icon {
        background-color: var(--icon-active);
    }
}

.inline-menu-btn:active .inline-menu-icon {
    background-color: #ff5d56;
}

.icon-inline-pin {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg fill='white' stroke='white' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='5'/%3E%3Cline x1='11' y1='11' x2='16' y2='16'/%3E%3C/g%3E%3C/svg%3E");
    background-color: #cc6944;
}

.icon-inline-download {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E");
    background-color: #1ae75b;
}

.icon-inline-copy {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
    background-color: #00faff;
}

.icon-inline-close {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
    background-color: #ffffff;
}

.card-footer {
    height: 32px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border-sidebar);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
}

.card-status-dot {
    display: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.card-status-dot.editing {
    display: block;
    background-color: #fbbc04;
}

.card-status-dot.saved {
    display: block;
    background-color: #34a853;
}

.card-status-text {
    font-size: 12.5px;
    color: var(--text-section);
}

.mobile-notebook-screen {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--bg-page);
    z-index: 15;
}

@media (min-width: 768px) {
    .mobile-notebook-screen {
        display: none !important;
    }
}

.swipe-viewport {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
}

.swipe-track {
    display: flex;
    width: 200%;
    height: 100%;
}

.swipe-page {
    width: 50%;
    height: 100%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--bg-sidebar);
    padding: 5px 8px;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border-sidebar);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: padding 0.2s ease;
}

#mobileNotebookScreen:focus-within header {
    padding-top: 6px;
    padding-bottom: 6px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: 0.25px;
}

.logo-accent {
    color: var(--logo-blue);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--icon-default);
    font-size: 18px;
    cursor: pointer;
}

.icon-btn.accent {
    color: var(--logo-blue);
    font-weight: 500;
}

@media (hover: hover) {
    .icon-btn:hover {
        background-color: var(--hover-bg);
    }
}

.icon-btn:active {
    background-color: var(--active-bg);
}

.icon-arrow-left {
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: var(--icon-default);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 10H5M9 6L5 10L9 14'/%3E%3C/g%3E%3C/svg%3E");
    mask-size: cover;
    transition: background-color 0.15s ease;
}

@media (hover: hover) {
    .icon-btn:hover .icon-arrow-left {
        background-color: var(--icon-active);
    }
}

.icon-btn:active .icon-arrow-left {
    background-color: #ff5d56;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0 16px;
}

.settings-row-label {
    font-size: 14px;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.toggle-track {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--border-sidebar);
    border-radius: 999px;
    transition: background-color 0.2s ease;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-input:checked+.toggle-track {
    background: var(--logo-blue);
}

.toggle-input:checked+.toggle-track .toggle-thumb {
    transform: translateX(18px);
    background: var(--bg-page);
}

main {
    flex: 1;
    padding: 8px 0;
}

.folder-list {
    list-style: none;
}

.folder-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-sidebar);
    cursor: pointer;
    transition: background-color 0.2s;
}

.folder-item:active {
    background-color: var(--hover-bg);
}

.folder-item.active {
    background-color: var(--active-bg);
}

.folder-item.active .folder-name {
    color: var(--logo-blue);
}

@media (hover: hover) {

    .folder-item:hover .folder-icon,
    .folder-item:hover .notebook-icon {
        background-color: var(--icon-active);
    }
}

.folder-item:active .folder-icon,
.folder-item:active .notebook-icon {
    background-color: #ff5d56;
}

.folder-item.active .folder-icon,
.folder-item.active .notebook-icon {
    background-color: var(--logo-blue);
}

.folder-number {
    font-size: 14px;
    color: var(--text-section);
    min-width: 28px;
    font-variant-numeric: tabular-nums;
}

.folder-icon {
    width: 24px;
    height: 24px;
    margin-right: 16px;
    flex-shrink: 0;
    background-color: var(--icon-default);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z'/%3E%3C/svg%3E");
    mask-size: cover;
    transition: background-color 0.15s ease;
}

.notebook-icon {
    width: 24px;
    height: 24px;
    margin-right: 16px;
    flex-shrink: 0;
    background-color: var(--icon-default);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M5,3H19V21H5Z M17,8H7V9.6H17Z M17,12H7V13.6H17Z M14,16H7V17.6H14Z'/%3E%3C/svg%3E");
    mask-size: cover;
    transition: background-color 0.15s ease;
}

.icon-sm {
    width: 36px !important;
    height: 36px !important;
    margin-left: 8px !important;
    margin-right: 8px !important;
}

.folder-name {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-menu-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.3s ease;
}

.item-menu-icon-dots {
    width: 18px;
    height: 18px;
    background-color: var(--icon-default);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg fill='white'%3E%3Ccircle cx='10' cy='5' r='1.8'/%3E%3Ccircle cx='10' cy='10' r='1.8'/%3E%3Ccircle cx='10' cy='15' r='1.8'/%3E%3C/g%3E%3C/svg%3E");
    mask-size: cover;
    opacity: 1;
}

@media (hover: hover) {

    .item-menu-btn:hover .item-menu-icon-dots,
    .card-field-menu-btn:hover .item-menu-icon-dots {
        background-color: var(--icon-active);
    }
}

.item-menu-btn:active .item-menu-icon-dots,
.card-field-menu-btn:active .item-menu-icon-dots {
    background-color: #ff5d56;
}

.item-menu-icon-pin {
    width: 14px;
    height: 14px;
    background-color: var(--pin-color);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg fill='white' stroke='white' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='5'/%3E%3Cline x1='11' y1='11' x2='16' y2='16'/%3E%3C/g%3E%3C/svg%3E");
    mask-size: cover;
    opacity: 0;
}

.folder-item[data-pinned="1"] .item-menu-icon-pin {
    opacity: 1;
}

.folder-item[data-pinned="1"] .item-menu-icon-dots {
    opacity: 0;
}

.card-field-wrap.is-pinned .item-menu-icon-pin {
    opacity: 1;
}

.card-field-wrap.is-pinned .item-menu-icon-dots {
    opacity: 0;
}

@media (hover: hover) {

    .folder-item[data-pinned="1"] .item-menu-btn:hover .item-menu-icon-pin,
    .card-field-wrap.is-pinned .card-field-menu-btn:hover .item-menu-icon-pin {
        opacity: 0;
    }

    .folder-item[data-pinned="1"] .item-menu-btn:hover .item-menu-icon-dots,
    .card-field-wrap.is-pinned .card-field-menu-btn:hover .item-menu-icon-dots {
        opacity: 1;
    }
}

.item-menu-btn {
    position: relative;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-left: 8px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--icon-default);
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

@media (hover: hover) {
    .item-menu-btn:hover {
        border-color: var(--border-sidebar);
    }
}

.item-menu-btn:active {
    background-color: var(--hover-bg);
}

.header-title {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.list-empty-placeholder {
    color: var(--text-section);
    font-size: 14px;
    text-align: center;
    padding: 32px 16px;
}

.hidden {
    display: none !important;
}
