/* =====================================================================
   Память — дизайн-система и стили приложения
   ===================================================================== */

/* ---------- Токены ---------- */
:root {
    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-serif: "Literata", Georgia, "Times New Roman", serif;

    --bg: #F7F6F3;
    --bg-elev: #FFFFFF;
    --bg-side: #F1EFEA;
    --bg-hover: rgba(31, 29, 26, .05);
    --bg-active: rgba(31, 29, 26, .08);
    --bg-input: #FFFFFF;
    --border: #E6E3DC;
    --border-strong: #D6D2C8;
    --text: #1F1D1A;
    --text-2: #4A463F;
    --muted: #8A857C;
    --accent: #6D5EF5;
    --accent-hover: #5B4BE0;
    --accent-soft: rgba(109, 94, 245, .12);
    --accent-text: #5B4BE0;
    --on-accent: #FFFFFF;
    --danger: #E5484D;
    --danger-hover: #CE3A3F;
    --danger-soft: rgba(229, 72, 77, .1);
    --success: #12A150;
    --warning: #D97706;

    --shadow-sm: 0 1px 2px rgba(20, 18, 14, .06);
    --shadow-md: 0 4px 16px rgba(20, 18, 14, .08), 0 1px 3px rgba(20, 18, 14, .06);
    --shadow-lg: 0 24px 64px rgba(20, 18, 14, .18), 0 4px 12px rgba(20, 18, 14, .08);

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --ease: cubic-bezier(.2, .8, .2, 1);
    --t: 160ms var(--ease);

    --side-w: 268px;
    --list-w: 380px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #121214;
    --bg-elev: #1A1A1D;
    --bg-side: #161618;
    --bg-hover: rgba(255, 255, 255, .05);
    --bg-active: rgba(255, 255, 255, .08);
    --bg-input: #1E1E22;
    --border: #2A2A2F;
    --border-strong: #3A3A41;
    --text: #ECEBE8;
    --text-2: #C9C7C1;
    --muted: #8E8B85;
    --accent: #8B7FFF;
    --accent-hover: #9D93FF;
    --accent-soft: rgba(139, 127, 255, .16);
    --accent-text: #A89FFF;
    --on-accent: #FFFFFF;
    --danger: #F2555A;
    --danger-hover: #FF6B70;
    --danger-soft: rgba(242, 85, 90, .14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, .55), 0 4px 12px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font: 400 14px/1.5 var(--font-ui);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow: hidden;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent-text); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.ico {
    width: 18px; height: 18px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}
.logo { width: 28px; height: 28px; flex: none; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 16px;
    border-radius: var(--r-md);
    font-weight: 600; font-size: 14px; letter-spacing: -.005em;
    border: 1px solid transparent;
    transition: background var(--t), border-color var(--t), color var(--t), transform var(--t), box-shadow var(--t);
    white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn .ico { width: 16px; height: 16px; stroke-width: 2.2; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 46px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 2px rgba(91, 75, 224, .3), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elev); border-color: var(--border); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: var(--danger-soft); color: var(--danger); }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
    content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-secondary.loading::after { border-color: var(--border-strong); border-top-color: var(--text); }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 8px; color: var(--text-2);
    transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-soft); }
.icon-btn.danger-hover:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn.recording { color: #fff; background: var(--danger); }
.icon-btn-sm { width: 26px; height: 26px; border-radius: 6px; }
.icon-btn-sm .ico { width: 16px; height: 16px; }
.link-btn { color: var(--accent-text); font-weight: 500; font-size: 12px; }
.link-btn:hover { text-decoration: underline; }

.kbd {
    display: inline-flex; align-items: center; height: 20px; padding: 0 6px;
    font: 500 11px/1 var(--font-ui); color: var(--muted);
    border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--bg-elev);
}

.chip {
    height: 28px; padding: 0 10px; border-radius: 999px;
    border: 1px solid var(--border); color: var(--text-2); font-size: 12px; font-weight: 500;
    background: var(--bg-elev); transition: all var(--t);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }

/* ---------- Поля ---------- */
.input {
    width: 100%; height: 40px; padding: 0 12px;
    background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--r-md);
    color: var(--text); transition: border-color var(--t), box-shadow var(--t);
    -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: var(--muted); }
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input-sm { height: 34px; font-size: 13px; border-radius: 8px; padding: 0 10px; }
input[type="date"].input, input[type="datetime-local"] { font-variant-numeric: tabular-nums; }
::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }
:root[data-theme="dark"] ::-webkit-calendar-picker-indicator { filter: invert(1); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.input-wrap { position: relative; display: block; }
.input-wrap .input { padding-right: 44px; }
.input-icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); border-radius: 8px; }
.input-icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.form-error {
    display: flex; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 14px;
    background: var(--danger-soft); color: var(--danger); border-radius: var(--r-md); font-size: 13px; font-weight: 500;
}

.segmented { display: flex; padding: 3px; gap: 2px; background: var(--bg-hover); border-radius: 10px; }
.seg-btn { flex: 1; height: 34px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; transition: all var(--t); }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented-sm .seg-btn { height: 30px; }

/* ---------- Бренд ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 600 18px/1 var(--font-serif); letter-spacing: -.01em; }
.brand-lg { font-size: 22px; }
.brand-lg .logo { width: 34px; height: 34px; }

/* ---------- Загрузка ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; transition: opacity .3s; }
.boot.done { opacity: 0; pointer-events: none; }
.boot-logo { width: 48px; height: 48px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .7; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }

/* =====================================================================
   Экран входа
   ===================================================================== */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; height: 100dvh; overflow: auto; }
.auth-hero {
    position: relative; display: flex; flex-direction: column; padding: 40px 56px; overflow: hidden;
    background:
        radial-gradient(900px 500px at 0% 0%, rgba(139, 127, 255, .22), transparent 60%),
        radial-gradient(700px 500px at 100% 100%, rgba(245, 158, 11, .14), transparent 60%),
        var(--bg-side);
    border-right: 1px solid var(--border);
}
.auth-hero-body { margin: auto 0; max-width: 520px; animation: fadeUp .6s var(--ease) both; }
.auth-hero h1 { font: 600 clamp(32px, 4vw, 48px)/1.08 var(--font-serif); letter-spacing: -.025em; margin-bottom: 18px; }
.lead { font-size: 17px; line-height: 1.6; color: var(--text-2); margin-bottom: 32px; max-width: 460px; }
.feature-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.feature-list li { display: flex; gap: 14px; align-items: flex-start; }
.feature-list b { display: block; font-weight: 600; margin-bottom: 2px; }
.feature-list span:not(.feature-ico) { color: var(--muted); font-size: 13px; }
.feature-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--bg-elev); box-shadow: var(--shadow-sm); color: var(--accent-text); flex: none; }
.feature-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.auth-preview { position: absolute; right: -40px; bottom: 48px; width: 300px; transform: rotate(-4deg); opacity: .95; animation: fadeUp .8s .15s var(--ease) both; }
.preview-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-lg); }
.preview-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.preview-meta .dot { width: 8px; height: 8px; border-radius: 50%; }
.preview-title { font: 600 18px/1.3 var(--font-serif); margin-bottom: 6px; }
.preview-text { font: 400 14px/1.55 var(--font-serif); color: var(--text-2); margin-bottom: 14px; }
.preview-audio { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600; }
.preview-audio svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.preview-audio .wave { flex: 1; height: 16px; background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); mask: linear-gradient(transparent 30%, #000 30% 70%, transparent 70%); -webkit-mask: radial-gradient(ellipse at center, #000 40%, transparent 75%); opacity: .7; }

.auth-panel { display: grid; place-items: center; padding: 32px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; animation: fadeUp .5s var(--ease) both; }
.auth-card .segmented { margin-bottom: 28px; }
.auth-card h2 { font: 600 26px/1.2 var(--font-serif); letter-spacing: -.02em; margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 24px; }
.auth-card .btn-lg { margin-top: 6px; }
.auth-foot { margin-top: 20px; font-size: 12px; text-align: center; }
.brand-mobile { display: none; margin-bottom: 28px; justify-content: center; }

/* =====================================================================
   Каркас приложения
   ===================================================================== */
.app { display: grid; grid-template-columns: var(--side-w) var(--list-w) minmax(0, 1fr); height: 100dvh; }

/* ---------- Сайдбар ---------- */
.sidebar {
    display: flex; flex-direction: column; gap: 6px; min-height: 0;
    background: var(--bg-side); border-right: 1px solid var(--border);
    padding: 16px 12px 12px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 12px; }
.search {
    display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; margin-bottom: 8px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--muted);
    transition: border-color var(--t), box-shadow var(--t);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); height: 100%; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search:focus-within .kbd { display: none; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px;
    color: var(--text-2); font-weight: 500; text-align: left; transition: background var(--t), color var(--t);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.nav-item span:nth-child(2) { flex: 1; }
.nav-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; }

.side-section { padding: 10px 4px 4px; border-top: 1px solid var(--border); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 8px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); min-height: 30px; }
.side-head .link-btn { text-transform: none; letter-spacing: 0; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.date-range { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 8px; padding: 0 4px 6px; }
.date-range .muted { font-size: 12px; }
.date-range .input { min-width: 0; padding: 0 8px; font-size: 12.5px; }

.side-tags { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tag-list { overflow-y: auto; min-height: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; margin: 0 -4px; padding: 0 4px; }
.tag-row {
    display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 6px 0 10px; border-radius: 8px;
    color: var(--text-2); cursor: pointer; transition: background var(--t), color var(--t); user-select: none;
}
.tag-row:hover { background: var(--bg-hover); color: var(--text); }
.tag-row.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.tag-row .tag-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.tag-row .tag-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-row .tag-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag-row .icon-btn { display: none; }
.tag-row:hover .icon-btn, .tag-row:focus-within .icon-btn { display: inline-grid; }
.tag-row:hover .tag-count { display: none; }
.tag-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); line-height: 1.5; }

.sidebar-foot { padding-top: 8px; border-top: 1px solid var(--border); }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: var(--r-md); text-align: left; transition: background var(--t); }
.user-btn:hover { background: var(--bg-hover); }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-meta b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--muted); font-size: 12px; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
    background: linear-gradient(135deg, #8B7FFF, #5B4BE0); color: #fff; font-weight: 700; font-size: 13px; text-transform: uppercase;
}
.avatar-lg { width: 48px; height: 48px; font-size: 18px; }

/* ---------- Список ---------- */
.list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--bg); position: relative; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px 20px; min-height: 64px; }
.pane-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.pane-title h2 { font: 600 20px/1.2 var(--font-serif); letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-title .muted { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 12px; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 10px; border-radius: 999px;
    background: var(--bg-elev); border: 1px solid var(--border); font-size: 12px; font-weight: 500; color: var(--text-2);
}
.filter-chip .tag-dot { width: 8px; height: 8px; border-radius: 50%; }
.filter-chip button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.filter-chip button:hover { background: var(--bg-hover); color: var(--text); }
.filter-chip button .ico { width: 12px; height: 12px; stroke-width: 2.4; }

.notes-scroll { flex: 1; overflow-y: auto; padding: 0 10px 24px; overscroll-behavior: contain; }
.group-label { padding: 14px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.note-card {
    position: relative; display: block; width: 100%; text-align: left;
    padding: 12px 12px 12px 14px; border-radius: var(--r-md); margin-bottom: 2px;
    transition: background var(--t); animation: fadeUp .25s var(--ease) both;
}
.note-card:hover { background: var(--bg-hover); }
.note-card.active { background: var(--bg-elev); box-shadow: var(--shadow-md), inset 0 0 0 1px var(--border); }
.note-card.active::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent); }
.note-card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.note-card h4 { flex: 1; min-width: 0; font: 600 15px/1.35 var(--font-ui); letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-card .pin-mark { width: 14px; height: 14px; color: var(--accent-text); }
.note-card p { font-size: 13px; line-height: 1.5; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; min-height: 0; }
.note-card p:empty { display: none; }
.note-card-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.note-card-foot .date { font-variant-numeric: tabular-nums; white-space: nowrap; }
.note-card-foot .att { display: inline-flex; align-items: center; gap: 3px; }
.note-card-foot .att .ico { width: 13px; height: 13px; }
.note-card-foot .tags { display: flex; gap: 4px; margin-left: auto; min-width: 0; overflow: hidden; justify-content: flex-end; }
.mini-tag { display: inline-flex; align-items: center; gap: 4px; max-width: 110px; padding: 1px 7px 1px 6px; border-radius: 999px; background: var(--bg-hover); font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-tag i { width: 6px; height: 6px; border-radius: 50%; flex: none; }

.list-sentinel { height: 1px; }
.list-loader { display: flex; justify-content: center; padding: 16px; color: var(--muted); }
.list-loader .ico { animation: spin .8s linear infinite; }
.skeleton { padding: 14px; margin-bottom: 2px; }
.sk-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-active) 50%, var(--bg-hover) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin-bottom: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.list-empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.list-empty .empty-art { margin: 0 auto 16px; }
.list-empty h3 { color: var(--text); font: 600 17px/1.3 var(--font-serif); margin-bottom: 6px; }
.list-empty .btn { margin-top: 16px; }

/* ---------- Редактор ---------- */
.editor-pane { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg-elev); }
.editor-empty { margin: auto; text-align: center; padding: 32px; max-width: 420px; animation: fadeUp .4s var(--ease) both; }
.empty-art { width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center; margin: 0 auto 20px; background: var(--accent-soft); color: var(--accent-text); }
.empty-art svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.editor-empty h3 { font: 600 22px/1.3 var(--font-serif); margin-bottom: 6px; }
.editor-empty .btn { margin-top: 20px; }
.shortcuts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 28px; font-size: 12px; color: var(--muted); }
.shortcuts .kbd { margin-right: 4px; }

.editor { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.editor-top { display: flex; align-items: center; gap: 4px; padding: 12px 16px; min-height: 58px; border-bottom: 1px solid transparent; transition: border-color var(--t); }
.editor-top.scrolled { border-bottom-color: var(--border); }
.save-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding-left: 8px; white-space: nowrap; }
.save-status .ico { width: 14px; height: 14px; }
.save-status.saving .ico { animation: spin .8s linear infinite; }
.save-status.saved .ico { color: var(--success); }
.save-status.error { color: var(--danger); }
.save-status button { color: inherit; font-weight: 600; text-decoration: underline; }

.editor-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.editor-inner { max-width: 760px; margin: 0 auto; padding: 16px 48px 120px; }

.title-input {
    display: block; width: 100%; border: 0; background: none; resize: none; outline: none; overflow: hidden;
    font: 600 34px/1.2 var(--font-serif); letter-spacing: -.02em; color: var(--text); padding: 0; margin-bottom: 14px;
}
.title-input::placeholder { color: var(--border-strong); }

.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 18px; }
.meta-chip {
    display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 8px;
    color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; transition: background var(--t), color var(--t);
}
.meta-chip:hover { background: var(--bg-hover); color: var(--text); }
.meta-chip .ico { width: 15px; height: 15px; color: var(--muted); }
.meta-chip input::-webkit-calendar-picker-indicator { display: none; }
.meta-chip input { border: 0; background: none; outline: none; color: inherit; font: inherit; font-variant-numeric: tabular-nums; padding: 0; cursor: pointer; }
.meta-add { color: var(--muted); }
.note-tags { display: contents; }
.tag-pill {
    display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600; background: color-mix(in srgb, var(--c) 14%, transparent); color: color-mix(in srgb, var(--c) 75%, var(--text));
    border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
}
.tag-pill button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; opacity: .6; }
.tag-pill button:hover { opacity: 1; background: color-mix(in srgb, var(--c) 20%, transparent); }
.tag-pill .ico { width: 12px; height: 12px; stroke-width: 2.4; }

.toolbar {
    position: sticky; top: 0; z-index: 3; display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
    padding: 6px; margin: 0 -6px 12px; border-radius: var(--r-md);
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
}
.toolbar button { width: 32px; height: 30px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); transition: background var(--t), color var(--t); }
.toolbar button:hover { background: var(--bg-hover); color: var(--text); }
.toolbar button.active { background: var(--accent-soft); color: var(--accent-text); }
.toolbar .ico { width: 16px; height: 16px; stroke-width: 2; }
.toolbar .tb-text { font-weight: 700; font-size: 12px; }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

.note-body {
    min-height: 280px; outline: none; font: 400 17px/1.75 var(--font-serif); color: var(--text); word-wrap: break-word; caret-color: var(--accent);
}
.note-body:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.note-body > * { margin: 0 0 .75em; }
.note-body h2 { font: 600 26px/1.3 var(--font-serif); margin: 1.2em 0 .5em; letter-spacing: -.015em; }
.note-body h3 { font: 600 20px/1.35 var(--font-serif); margin: 1.1em 0 .4em; }
.note-body h1 { font: 600 30px/1.25 var(--font-serif); margin: 1.2em 0 .5em; }
.note-body blockquote { margin-left: 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--accent); color: var(--text-2); font-style: italic; }
.note-body ul, .note-body ol { padding-left: 1.4em; }
.note-body li { margin: .2em 0; }
.note-body a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
.note-body pre, .note-body code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; background: var(--bg-hover); border-radius: 6px; }
.note-body code { padding: 1px 5px; }
.note-body pre { padding: 12px 14px; overflow-x: auto; }
.note-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }

.recorder {
    display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; margin-bottom: 14px;
    border-radius: var(--r-md); background: var(--danger-soft); color: var(--danger); font-weight: 600; font-size: 13px; animation: pop .2s var(--ease);
}
.recorder b { font-variant-numeric: tabular-nums; color: var(--text); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.recorder .btn-ghost { color: var(--text-2); }

/* ---------- Вложения ---------- */
.attachments { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.att-head { display: flex; gap: 8px; align-items: baseline; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.att-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.att-images:empty { display: none; }
.att-thumb { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-md); overflow: hidden; background: var(--bg-hover); cursor: zoom-in; border: 1px solid var(--border); }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s var(--ease); }
.att-thumb:hover img { transform: scale(1.04); }
.att-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.att-list:empty { display: none; }
.att-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--bg); }
.att-ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-text); }
.att-ico.audio { background: rgba(16, 185, 129, .14); color: #10B981; }
.att-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att-info b { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-info small { color: var(--muted); font-size: 12px; }
.att-info audio { display: block; width: 100%; min-width: 0; height: 36px; margin-top: 6px; }
.att-del {
    position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
    background: rgba(0,0,0,.55); color: #fff; opacity: 0; transition: opacity var(--t), background var(--t);
}
.att-del .ico { width: 15px; height: 15px; }
.att-thumb:hover .att-del, .att-del:focus-visible { opacity: 1; }
.att-del:hover { background: var(--danger); }
.att-row .att-del { position: static; opacity: 1; background: none; color: var(--muted); }
.att-row .att-del:hover { background: var(--danger-soft); color: var(--danger); }
.att-row .icon-btn { flex: none; }
.att-uploading { opacity: .6; pointer-events: none; }
.att-uploading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent); background-size: 200% 100%; animation: shimmer 1s infinite; }

.dropzone {
    display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
    margin-top: 24px; padding: 20px; border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--text-2); font-size: 13px;
    transition: border-color var(--t), background var(--t);
}
.dropzone .ico { color: var(--muted); margin-bottom: 4px; }
.dropzone .link-btn { font-size: 13px; }
.dropzone small { font-size: 11.5px; }
.drop-overlay {
    position: absolute; inset: 8px; z-index: 10; display: grid; place-items: center; pointer-events: none; opacity: 0;
    border: 2px dashed var(--accent); border-radius: var(--r-lg); background: color-mix(in srgb, var(--accent) 8%, var(--bg-elev));
    color: var(--accent-text); font-weight: 600; transition: opacity var(--t);
}
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-overlay .ico { width: 28px; height: 28px; }
.editor.dragging .drop-overlay { opacity: 1; }

/* ---------- Поповеры ---------- */
.popover {
    position: fixed; z-index: 60; min-width: 240px; padding: 6px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
    animation: pop .14s var(--ease);
}
.menu-label { padding: 6px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.popover .segmented { margin: 0 4px 4px; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; color: var(--text); font-weight: 500; text-align: left; }
.menu-item:hover { background: var(--bg-hover); }
.menu-item .ico { color: var(--muted); width: 17px; height: 17px; }

.tag-picker { width: 280px; padding: 8px; }
.tag-picker-list { max-height: 260px; overflow-y: auto; margin-top: 6px; }
.picker-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 8px; border-radius: 8px; text-align: left; font-weight: 500; }
.picker-item:hover, .picker-item.focused { background: var(--bg-hover); }
.picker-item .tag-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.picker-item span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .check { width: 16px; height: 16px; color: var(--accent-text); stroke-width: 2.4; opacity: 0; }
.picker-item.selected .check { opacity: 1; }
.picker-create { color: var(--accent-text); }
.picker-empty { padding: 10px 8px; font-size: 13px; color: var(--muted); }

/* ---------- Модальные окна ---------- */
.modal {
    position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px;
    background: rgba(15, 13, 10, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fadeUp .15s;
}
.modal-card {
    width: 100%; max-width: 460px; max-height: calc(100dvh - 40px); overflow-y: auto;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
    padding: 22px 24px 20px; animation: pop .2s var(--ease);
}
.modal-sm { max-width: 400px; text-align: center; }
.modal-sm .modal-actions { justify-content: center; }
.modal-sm .modal-actions .spacer { display: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3, .modal-sm h3 { font: 600 20px/1.3 var(--font-serif); letter-spacing: -.01em; }
.modal-sm h3 { margin-bottom: 8px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.confirm-ico { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; margin: 4px auto 14px; background: var(--danger-soft); color: var(--danger); }
.confirm-ico .ico { width: 24px; height: 24px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; background: var(--c); position: relative; transition: transform var(--t); box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.swatch:hover { transform: scale(1.1); }
.swatch.active { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px var(--c); }
.swatch-custom { display: grid; place-items: center; background: conic-gradient(from 0deg, #F43F5E, #F59E0B, #10B981, #06B6D4, #6366F1, #D946EF, #F43F5E); overflow: hidden; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.account-summary { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: var(--r-md); background: var(--bg); margin-bottom: 8px; }
.account-summary b { font-size: 16px; }
.account-block { padding: 18px 0 4px; border-top: 1px solid var(--border); margin-top: 14px; }
.account-block h4 { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.account-block > p { font-size: 13px; margin-bottom: 14px; }
.danger-zone h4 { color: var(--danger); }

/* ---------- Лайтбокс ---------- */
.lightbox { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(0,0,0,.88); padding: 24px; animation: fadeUp .15s; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.lightbox-close { position: absolute; top: 16px; right: 16px; color: #fff; background: rgba(255,255,255,.12); }
.lightbox-close:hover { background: rgba(255,255,255,.22); color: #fff; }

/* ---------- Тосты ---------- */
.toasts { position: fixed; z-index: 90; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; pointer-events: auto;
    background: #1F1D1A; color: #F5F4F1; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); animation: pop .2s var(--ease);
}
:root[data-theme="dark"] .toast { background: #2A2A30; border: 1px solid #3A3A41; }
.toast .ico { width: 17px; height: 17px; }
.toast.success .ico { color: #34D399; }
.toast.error .ico { color: #FF7A7E; }
.toast.hide { opacity: 0; transform: translateY(6px); transition: all .2s; }
.toast button { color: #A89FFF; font-weight: 700; margin-left: 4px; }

/* ---------- Мобильные элементы ---------- */
.fab {
    position: absolute; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 5;
    width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
    background: var(--accent); color: #fff; box-shadow: 0 10px 30px rgba(91, 75, 224, .45);
    transition: transform var(--t);
}
.fab:active { transform: scale(.94); }
.fab .ico { width: 24px; height: 24px; stroke-width: 2.4; }
.drawer-backdrop { display: none; }
.only-mobile, .only-tablet, .only-drawer { display: none !important; }

/* =====================================================================
   Адаптив
   ===================================================================== */
@media (max-width: 1280px) {
    :root { --list-w: 340px; --side-w: 248px; }
    .editor-inner { padding: 12px 32px 120px; }
}

/* Планшет: сайдбар — выезжающая панель */
@media (max-width: 1100px) {
    .app { grid-template-columns: var(--list-w) minmax(0, 1fr); }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 50;
        transform: translateX(-100%); transition: transform .25s var(--ease), box-shadow .25s; box-shadow: none;
        padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    .app.drawer-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(15, 13, 10, .4); opacity: 0; pointer-events: none; transition: opacity .25s; }
    .app.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
    .only-tablet, .only-drawer { display: inline-grid !important; }
    .pane-head { padding-left: 10px; }
    .tag-row .icon-btn { display: inline-grid; }
    .tag-row .tag-count { display: none; }
}

/* Телефон: одна панель на экране */
@media (max-width: 760px) {
    body { font-size: 15px; }
    .auth { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .brand-mobile { display: flex; }
    .auth-panel { align-items: start; padding-top: max(48px, env(safe-area-inset-top)); }

    .app { grid-template-columns: 1fr; position: relative; overflow: hidden; }
    .list-pane, .editor-pane { grid-area: 1 / 1; border: 0; transition: transform .28s var(--ease), opacity .28s; }
    .app[data-view="list"] .editor-pane { transform: translateX(100%); pointer-events: none; visibility: hidden; }
    .app[data-view="editor"] .list-pane { transform: translateX(-25%); opacity: 0; pointer-events: none; visibility: hidden; }
    .list-pane { padding-top: env(safe-area-inset-top); }
    .editor-pane { padding-top: env(safe-area-inset-top); }

    .hide-mobile { display: none !important; }
    .only-mobile { display: inline-grid !important; }
    .pane-head { min-height: 56px; padding: 8px 12px 8px 8px; }
    .pane-title h2 { font-size: 22px; }
    .active-filters { padding: 0 14px 10px; }
    .notes-scroll { padding: 0 6px calc(96px + env(safe-area-inset-bottom)); }
    .note-card { padding: 14px 12px; }
    .note-card.active { box-shadow: none; background: transparent; }
    .note-card.active::before { display: none; }

    .editor-top { padding: 6px 8px; min-height: 52px; gap: 2px; }
    .editor-top .icon-btn { width: 40px; height: 40px; }
    .save-status { padding-left: 2px; }
    .editor-inner { padding: 8px 18px calc(120px + env(safe-area-inset-bottom)); }
    .title-input { font-size: 26px; }
    .note-body { font-size: 17px; min-height: 200px; }
    .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 12px; border-radius: 0; border-left: 0; border-right: 0; padding: 6px 12px; }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar button { flex: none; width: 38px; height: 36px; }
    .att-images { grid-template-columns: repeat(2, 1fr); }
    .att-del { opacity: 1; }
    .dropzone small { display: none; }

    .input, .search input { font-size: 16px; } /* iOS не зумит поля от 16px */
    .modal { align-items: end; padding: 0; }
    .modal-card { max-width: none; border-radius: 22px 22px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 92dvh; }
    .modal-sm { text-align: left; }
    .modal-sm .confirm-ico { margin-left: 0; }
    .modal-actions .btn { flex: 1; height: 44px; }
    .modal-actions .spacer { display: none; }
    .popover { left: 8px !important; right: 8px !important; width: auto !important; }
    .toasts { bottom: calc(90px + env(safe-area-inset-bottom)); }
    .kbd { display: none; }
}

@media (hover: none) {
    .tag-row .icon-btn { display: inline-grid; }
    .tag-row .tag-count { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
    .sidebar, .list-pane, .editor-top, .toolbar, .dropzone, .fab { display: none !important; }
    .app { display: block; }
    body { overflow: visible; }
}
