:root {
  /* Палитра A: нейтральный тёплый фон, жёлтый — только акцент.
     На светлом фоне #ffc900 нечитаем как текст (контраст ~1.5:1), поэтому
     ссылки там тёмно-янтарные, а текст на жёлтых кнопках — почти чёрный. */
  --bg: #f5f4ef;
  --card: #ffffff;
  --text: #1f1d17;
  --muted: #6b6758;
  --border: #e4e1d6;
  --accent: #ffc900;
  --accent-text: #1f1a00;
  --accent-soft: rgba(255, 201, 0, 0.22);
  --link: #8f6800;
  --code-bg: #efede5;
  --danger: #dc2626;
  --ok: #16a34a;
}
/* Тёмная тема: принудительно (data-theme="dark") или по системе,
   если пользователь явно не выбрал светлую (data-theme="light"). */
:root[data-theme="dark"] {
  --bg: #131210; --card: #1c1b18; --text: #ecebe6; --muted: #9c988b;
  --border: #2d2b26; --link: #ffc900; --code-bg: #26241f;
  --accent-soft: rgba(255, 201, 0, 0.16);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #131210; --card: #1c1b18; --text: #ecebe6; --muted: #9c988b;
    --border: #2d2b26; --link: #ffc900; --code-bg: #26241f;
    --accent-soft: rgba(255, 201, 0, 0.16);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { height: 100dvh; display: flex; flex-direction: column; }

#splash-screen.splash { align-items: center; justify-content: center; gap: 14px; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(128, 128, 128, 0.3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth ── */
#auth-screen { align-items: center; justify-content: center; padding: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.step { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
label { font-size: 13px; color: var(--muted); }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#code { letter-spacing: 6px; font-size: 20px; text-align: center; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--accent);
  color: var(--accent-text);
}
button { font-weight: 600; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 11px;
}
button.link {
  background: transparent;
  color: var(--link);
  padding: 4px;
  text-align: left;
}
.msg { min-height: 18px; font-size: 13px; margin: 12px 0 0; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ── App header ── */
.app-header {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.header-actions { display: flex; gap: 6px; flex-shrink: 0; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px;
  background: var(--accent); color: var(--accent-text);
  border-radius: 9px; font-size: 12px; text-align: center;
}

.app-title { margin-right: auto; font-weight: 600; }

/* ── Footer ── */
.app-footer {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 6px 14px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--card);
}
.app-footer .footer-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 4px 9px; font-size: 13px; line-height: 1; border-radius: 8px;
  white-space: nowrap;
}
.app-footer .footer-net {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted);
}
.app-footer .net-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.app-footer .footer-net.online .net-dot { background: var(--ok); }
.app-footer .footer-net.offline .net-dot { background: var(--danger); }
.app-footer .footer-version {
  margin-left: auto;          /* версия справа; кнопки — слева */
  font-size: 12px; color: var(--muted);
}

/* ── Модалка ── */
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45); padding: 20px;
}
.modal-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: 100%; max-width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-card h2 { margin: 0 0 6px; }
.modal-card p { margin: 8px 0; line-height: 1.45; word-break: break-word; }
.modal-card button { margin-top: 14px; width: 100%; }

/* ── Слайдер подтверждения выхода ── */
.confirm-slider {
  position: relative; margin-top: 16px; height: 52px; border-radius: 26px;
  background: var(--bg); border: 1px solid var(--border); overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.confirm-slider-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--muted); pointer-events: none; padding: 0 56px;
}
.confirm-slider-thumb {
  position: absolute; top: 3px; left: 3px; width: 46px; height: 46px; border-radius: 50%;
  background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; cursor: grab; touch-action: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.confirm-slider-thumb:active { cursor: grabbing; }
.confirm-slider.confirmed { background: var(--danger); border-color: var(--danger); }
.confirm-slider.confirmed .confirm-slider-label { color: #fff; }


/* ── Devices panel ── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 9;
}
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 10;
  width: min(360px, 86vw);
  background: var(--card); border-left: 1px solid var(--border);
  padding: 14px; padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: -8px 0 24px rgba(0,0,0,0.12);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.devices-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.device {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border);
}
.device .d-name { font-weight: 600; }
.device .d-sub { font-size: 12px; color: var(--muted); }
.device.current .d-name::after {
  content: " (это устройство)"; font-weight: 400; color: var(--muted); font-size: 12px;
}
.device .d-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
.device .d-rename {
  background: transparent; border: 1px solid var(--border);
  padding: 5px 9px; font-size: 13px;
}
.device .revoke {
  background: transparent; color: var(--danger);
  border: 1px solid var(--border); padding: 5px 10px; font-size: 13px;
}

/* ── Рабочая область: список заметок слева, заметка справа ── */
.workspace { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 150px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 6px;
  background: var(--card); border-right: 1px solid var(--border);
  min-height: 0;
}
.sidebar .add-btn { padding: 4px 0; font-size: 22px; line-height: 1.2; }
.sidebar input[type="search"] { padding: 6px 7px; font-size: 13px; border-radius: 8px; min-width: 0; }
.show-hidden {
  display: flex; align-items: flex-start; gap: 4px;
  font-size: 11px; line-height: 1.25; cursor: pointer;
}
.show-hidden input { margin: 1px 0 0; flex-shrink: 0; accent-color: var(--accent); }

.notes-list {
  list-style: none; margin: 2px 0 0; padding: 0;
  flex: 1; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.notes-list button {
  width: 100%; text-align: left;
  background: transparent; color: var(--text);
  font-size: 13px; font-weight: 400; line-height: 1.25;
  padding: 6px 6px; border-radius: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.notes-list button:hover { background: var(--bg); }
.notes-list button.active {
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.notes-list button.is-hidden { color: var(--muted); font-style: italic; }
.notes-list button.is-hidden.active { color: var(--accent-text); }
.notes-list .empty { font-size: 12px; color: var(--muted); padding: 4px 2px; }

/* ── Заметка ── */
.note-view { flex: 1; min-width: 0; overflow-y: auto; padding: 14px 16px 24px; }
.note-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); padding: 16px;
}
.note-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; margin-bottom: 12px; }
.note-head h2 { margin: 0; font-size: 20px; min-width: 0; overflow-wrap: anywhere; margin-right: auto; }
.note-actions { display: flex; gap: 6px; }
.note-actions button { font-size: 13px; }
.pill {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
}

.note-frames { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 900px) {
  .note-frames { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.frame {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  min-width: 0; display: flex; flex-direction: column;
}
.frame-head {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.frame-body { padding: 4px 14px 12px; min-width: 0; }
.frame-empty { background: transparent; color: var(--link); padding: 10px 0 4px; font-weight: 400; }

/* ── Markdown ── */
.md { line-height: 1.55; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 16px 0 6px; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 8px 0; }
.md ul, .md ol { padding-left: 22px; }
.md a { color: var(--link); }
.md code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em;
  background: var(--code-bg); border-radius: 5px; padding: 1px 5px;
}
.md pre { background: var(--code-bg); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.md img { max-width: 100%; }
.md input[type="checkbox"] { accent-color: var(--accent); margin-right: 4px; }
/* Чек-лист (- [ ] …): маркер списка рядом с чекбоксом лишний. */
.md li:has(> input[type="checkbox"]) { list-style: none; margin-left: -18px; }

/* ── Модалка заметки ── */
.modal-card.note-modal {
  max-width: 760px; max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column; gap: 10px;
}
.note-modal h2 { margin: 0; }
.note-modal button { margin-top: 0; width: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs .tab {
  background: transparent; color: var(--muted); border-radius: 8px 8px 0 0;
  padding: 8px 14px; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs .tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs .tab.filled::after { content: " •"; color: var(--link); }
.note-modal textarea {
  flex: 1; min-height: 260px; resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; line-height: 1.45;
}
.note-modal .hint { font-size: 12px; color: var(--muted); margin: 0; }
.note-modal .msg { margin: 0; min-height: 0; }
.modal-buttons { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
