:root {
    --bg: #ffffff;
    --bg-sidebar: #f7f7f8;
    --border: #e3e3e6;
    --text: #1c1c1e;
    --text-muted: #6b6b70;
    --accent: #2b5fd9;
    --danger: #e0473c;
    --hover: #eef0f5;
    --radius: 6px;
    --sticky-shadow: rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17181a;
        --bg-sidebar: #101113;
        --border: #2c2d30;
        --text: #ececed;
        --text-muted: #8f8f94;
        --accent: #7aa0ff;
        --hover: #232427;
        --sticky-shadow: rgba(0, 0, 0, 0.55);
    }
}

:root[data-theme="dark"] {
    --bg: #17181a;
    --bg-sidebar: #101113;
    --border: #2c2d30;
    --text: #ececed;
    --text-muted: #8f8f94;
    --accent: #7aa0ff;
    --hover: #232427;
    --sticky-shadow: rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--accent);
    text-decoration: none;
}

button {
    font: inherit;
    cursor: pointer;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px 10px;
}

.sidebar-user {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px 16px;
    color: var(--text-muted);
    font-size: 13px;
}

.sidebar-user a {
    color: var(--text-muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--text);
}

.nav-item:hover {
    background: var(--hover);
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
}

.nav-item-child {
    padding-left: 24px;
    font-size: 14px;
}

.nav-label {
    margin: 14px 10px 4px;
    font-size: 11px;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.nav-row {
    display: flex;
    align-items: center;
    gap: 2px;
}

.nav-row .nav-item {
    flex: 1;
    min-width: 0;
}

.nav-row.dragging {
    opacity: 0.4;
}

.nav-menu-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 4px 6px;
    opacity: 0;
    font-size: 15px;
}

.nav-row:hover .nav-menu-toggle,
.nav-menu-toggle:focus-visible {
    opacity: 1;
}

@media (hover: none), (pointer: coarse) {
    .nav-menu-toggle {
        opacity: 1;
        min-width: 32px;
    }
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 8px 8px;
}

.tag-chip {
    font-size: 12px;
    color: var(--accent);
    background: var(--hover);
    padding: 3px 8px;
    border-radius: 999px;
}

.tag-chip.active {
    background: var(--accent);
    color: #fff;
}

.tag-chip-clear {
    color: var(--text-muted);
    background: none;
}

.nav-add-section {
    margin: 10px 8px 0;
    padding: 6px 10px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: left;
}

.nav-add-section:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.nav-divider {
    border-top: 1px dashed var(--border);
    margin: 12px 8px;
}

/* Content */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 24px 32px;
    max-width: 720px;
}

.content-full {
    max-width: 720px;
    margin: 0 auto;
}

.content-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.content-header h1 {
    font-size: 22px;
    margin: 0;
    flex: 1;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    padding: 4px 8px;
    display: none;
}

.btn-icon-back {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    padding: 4px 8px;
    display: inline-flex;
}

.search-form {
    display: flex;
}

.search-input {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    background: var(--bg);
    color: var(--text);
    width: 180px;
}

.search-form-full .search-input {
    width: 320px;
}

/* Item list */
.item-list {
    display: flex;
    flex-direction: column;
}

.item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 7px 4px;
    border-radius: var(--radius);
    position: relative;
    /* запас под закреплённое поле ввода, чтобы scrollIntoView
       не подводил строку вплотную под него */
    scroll-margin-bottom: 72px;
}

.item:hover {
    background: var(--hover);
}

.item.dragging {
    opacity: 0.4;
}

.item.item-focused {
    box-shadow: 0 0 0 2px var(--accent);
}

.item:hover .item-actions {
    opacity: 1;
}

.item-check {
    background: none;
    border: none;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 1px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--text-muted);
    border-radius: 4px;
    color: var(--accent);
    font-size: 13px;
    line-height: 1;
}

.item-check-note {
    border: none;
    color: var(--text-muted);
}

.item-done .item-check {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.item-done .item-text {
    color: var(--text-muted);
    text-decoration: line-through;
}

.item-content {
    flex: 1;
    min-width: 0;
}

.item-text {
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 1px 2px;
    border-radius: 4px;
}

.item-text[contenteditable="true"] {
    background: var(--bg);
    box-shadow: 0 0 0 2px var(--accent);
}

.item-note .item-text {
    color: var(--text-muted);
}

.item-meta {
    font-size: 12px;
    color: var(--accent);
    margin-top: 2px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.due-badge {
    color: var(--text-muted);
}

.due-badge.due-overdue {
    color: var(--danger);
    font-weight: 600;
}

.archived-badge {
    font-size: 11px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 6px;
    margin-left: 6px;
}

.active-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.item-actions {
    background: none;
    border: none;
    color: var(--text-muted);
    opacity: 0;
    padding: 2px 6px;
    font-size: 16px;
}

.item-actions:focus,
.item.menu-open .item-actions {
    opacity: 1;
}

@media (hover: none), (pointer: coarse) {
    .item-actions {
        opacity: 1;
        min-width: 40px;
        min-height: 40px;
        font-size: 20px;
    }
}

/* Done separator */
.done-separator {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 14px 0 4px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    padding: 0;
}

/* Add form */
/*
 * Поле ввода закреплено внизу: при длинном списке оно не уезжает вниз
 * вместе со строками, а остаётся в поле зрения. Фон непрозрачный —
 * строки прокручиваются под ним.
 */
.add-form {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    padding: 10px 4px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    box-shadow: 0 -8px 12px -8px var(--sticky-shadow);
}

.add-icon {
    color: var(--text-muted);
    width: 20px;
    text-align: center;
}

.add-input {
    flex: 1;
    border: none;
    background: none;
    color: var(--text);
    font-size: 15px;
    outline: none;
}

.add-input::placeholder {
    color: var(--text-muted);
}

.add-input:focus-visible,
.item-text:focus-visible,
.nav-item:focus-visible,
.item-check:focus-visible,
.item-actions:focus-visible,
.link-btn:focus-visible,
.search-input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent);
}

/* Context menu */
.item-menu {
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    min-width: 180px;
    z-index: 50;
    padding: 4px;
}

.item-menu button {
    background: none;
    border: none;
    text-align: left;
    padding: 8px 10px;
    border-radius: 4px;
    color: var(--text);
}

.item-menu button:hover {
    background: var(--hover);
}

.item-menu button.danger {
    color: var(--danger);
}

.item-menu[hidden] {
    display: none;
}

.section-menu,
.due-menu {
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    min-width: 180px;
    z-index: 55;
    padding: 4px;
}

.section-menu button,
.due-menu button {
    background: none;
    border: none;
    text-align: left;
    padding: 8px 10px;
    border-radius: 4px;
    color: var(--text);
}

.section-menu button:hover,
.due-menu button:hover {
    background: var(--hover);
}

.section-menu button.danger {
    color: var(--danger);
}

.section-menu[hidden],
.due-menu[hidden] {
    display: none;
}

/* Settings page */
.settings-block {
    margin-top: 16px;
}

.settings-title {
    font-size: 15px;
    margin: 0 0 10px;
}

.settings-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

/* Move dialog */
.move-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
}

.move-dialog[hidden] {
    display: none;
}

.move-dialog-box {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 20px;
    width: 320px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.move-dialog-box h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.move-dialog-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 10px;
}

.move-dialog-list button {
    background: none;
    border: none;
    text-align: left;
    padding: 8px 10px;
    border-radius: 4px;
    color: var(--text);
}

.move-dialog-list button:hover {
    background: var(--hover);
}

/* Search page */
.search-results {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.search-result-section {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.empty-state {
    color: var(--text-muted);
}

/* Error page */
.error-page {
    margin: 80px auto;
    text-align: center;
}

.error-page h1 {
    font-size: 64px;
    margin: 0;
}

.btn-primary {
    display: inline-block;
    margin-top: 16px;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius);
}

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 12px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 100;
    max-width: 90vw;
}

.toast-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* App overlay for mobile sidebar */
.app-overlay {
    display: none;
}

/* Auth pages (login, register, password) */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 360px;
}

.auth-brand {
    text-align: center;
    font-weight: 600;
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--text);
}

.auth-panel {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
}

.auth-title {
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    margin: 0 0 18px;
}

.auth-field {
    margin-bottom: 14px;
}

.auth-field label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.auth-input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

.auth-input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-field.has-error .auth-input {
    border-color: var(--danger);
}

.auth-error {
    display: block;
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

.auth-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.auth-checkbox input {
    margin-top: 2px;
}

.auth-submit {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
}

.auth-submit:hover {
    opacity: 0.92;
}

.auth-link-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    background: none;
    box-sizing: border-box;
}

.auth-link-btn:hover {
    background: var(--hover);
}

.auth-row-link {
    text-align: right;
    margin: -8px 0 14px;
}

.auth-row-link a {
    font-size: 13px;
}

.auth-sep {
    border: none;
    border-top: 1px dashed var(--border);
    margin: 16px 0;
}

.auth-hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 8px;
}

.auth-alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
}

.auth-alert-error {
    background: rgba(224, 71, 60, 0.12);
    color: var(--danger);
}

.auth-alert-success {
    background: rgba(59, 110, 246, 0.12);
    color: var(--accent);
}

.auth-alert-info,
.auth-alert-warning {
    background: var(--hover);
    color: var(--text-muted);
}

.auth-text {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

.auth-list {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
    padding-left: 20px;
    margin: 0 0 14px;
}

/* Mobile */
@media (max-width: 991px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -280px;
        width: 260px;
        z-index: 40;
        transition: left 0.2s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .app-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 35;
    }

    .app-overlay[hidden] {
        display: none;
    }

    .btn-icon {
        display: inline-flex;
    }

    .content {
        padding: 16px;
        max-width: 100%;
    }

    .search-input {
        width: 120px;
    }
}
