/* память — тёмная мобильная витрина личной базы знаний.
   Палитра и типографика — от ramble, но структура своя: вкладки + нижняя панель записи. */
:root {
  --bg: #0b0e14;
  --bg-soft: #121722;
  --panel: #151b28;
  --panel-2: #1b2231;
  --border: #263144;
  --border-2: #313d54;
  --text: #e6ecf7;
  --muted: #8b97ad;
  --accent: #7c8cff;
  --accent-2: #a855f7;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --rec: #ff4d6d;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Служебный [hidden] должен побеждать любой авторский display: ниже,
   иначе заблокированный элемент остаётся на экране (в ramble это был реальный баг). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 620px at 10% -12%, rgba(124, 140, 255, .16), transparent 60%),
    radial-gradient(900px 520px at 108% -4%, rgba(168, 85, 247, .12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
/* пока открыта шторка результата, фон не должен скроллиться под ней */
body.no-scroll { overflow: hidden; }

/* Кнопка записи прижата к низу, поэтому контенту нужен запас снизу */
.app {
  width: min(100% - 28px, 960px);
  margin-inline: auto;
  padding-block: clamp(16px, 3vw, 26px) calc(140px + env(safe-area-inset-bottom));
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── шапка ── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.logo {
  width: 11px; height: 11px; border-radius: 50%; align-self: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(124, 140, 255, .8);
}
.name { font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.sub { color: var(--muted); font-size: 12.5px; min-width: 0; }

.counters { margin-left: auto; display: flex; flex-wrap: wrap; gap: 5px; }
.counter {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.counter.who { color: var(--text); }
.counter.own { color: #c3caff; border-color: rgba(124, 140, 255, .4); }
.counter.dim { opacity: .8; }

/* ── отказ в доступе: постоянная плашка, а не тост на пять секунд ── */
.accessbar {
  display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap;
  margin-top: 14px; padding: 10px 13px; border-radius: 12px;
  background: rgba(248, 113, 113, .07); border: 1px solid rgba(248, 113, 113, .45);
  color: var(--err); font-size: 12.5px;
}
.accessbar span { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.accessbar .ab-hint { flex-basis: 100%; font-size: 11.5px; opacity: .85; }

/* ── вкладки ── */
.tabs {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  margin: 14px 0 18px; padding: 4px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 14px;
}
.tab {
  font: inherit; font-size: 13px; padding: 9px 6px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--panel-2); color: var(--text); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border-2);
}

.content { min-height: 46vh; }
.panel { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }

.panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.panel-sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── пустые состояния, ошибки, скелетоны ── */
.emptybox {
  background: var(--bg-soft); border: 1px dashed var(--border-2); border-radius: 14px;
  padding: 16px; display: grid; gap: 4px;
}
.emptybox p { margin: 0; font-size: 13.5px; }
.emptybox span { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.emptybox.soft { border-style: solid; border-color: rgba(124, 140, 255, .28); }

.errbox {
  background: rgba(248, 113, 113, .06); border: 1px solid rgba(248, 113, 113, .4);
  border-radius: 14px; padding: 14px; display: grid; gap: 10px; justify-items: start;
}
.errbox p { margin: 0; color: var(--err); font-size: 13px; overflow-wrap: anywhere; }

.skel {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px; display: grid; gap: 8px;
}
.skel span {
  height: 10px; border-radius: 6px;
  background: linear-gradient(90deg, var(--panel-2), var(--border-2), var(--panel-2));
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite;
}
.skel span:nth-child(1) { width: 38%; }
.skel span:nth-child(2) { width: 88%; }
.skel span:nth-child(3) { width: 62%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── карточки знаний ── */
.items { display: grid; gap: 8px; min-width: 0; }
.item {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; min-width: 0;
}
.item.stale { opacity: .65; }
.item.stale .item-text { text-decoration: line-through; text-decoration-color: rgba(248, 113, 113, .45); }
.item.gone { opacity: .5; }
.item.vetoed { opacity: .6; }

.item-top { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--muted); background: var(--panel);
}
.chip.kind { color: #c3caff; border-color: rgba(124, 140, 255, .35); }
.chip.st-active { color: var(--ok); border-color: rgba(52, 211, 153, .4); }
.chip.st-superseded { color: var(--warn); border-color: rgba(251, 191, 36, .4); }
.chip.st-retracted { color: var(--err); border-color: rgba(248, 113, 113, .4); }

.item-text { margin: 8px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.quote {
  margin: 6px 0 0; color: var(--muted); font-size: 12px; font-style: italic;
  overflow-wrap: anywhere; border-left: 2px solid var(--border-2); padding-left: 8px;
}
.item-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px;
  margin-top: 9px; font-size: 11px; color: var(--muted);
}
.slot {
  font-family: var(--mono); font-size: 10.5px; color: #c3caff;
  background: rgba(124, 140, 255, .1); border-radius: 6px; padding: 1px 6px;
  overflow-wrap: anywhere; max-width: 100%;
}
.conf { border: 1px solid var(--border-2); border-radius: 999px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.item-foot .when { margin-left: auto; text-align: right; }
.outcome { margin: 9px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.outcome.ok { color: var(--ok); }

.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ── «Сейчас»: темы и слоты ── */
.topics { display: grid; gap: 14px; min-width: 0; }
.topic {
  background: linear-gradient(180deg, rgba(21, 27, 40, .72), rgba(18, 23, 34, .32));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0;
}
.topic-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topic-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.topic-meta { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; margin-left: auto; text-align: right; }
.topic-body { margin-top: 10px; display: grid; gap: 12px; }

/* .slotblock — группа одного слота; .slot — моно-подпись имени слота внутри карточки */
.slotblock { display: grid; gap: 8px; }
.slot-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.slot-head h4 {
  margin: 0; font-family: var(--mono); font-size: 11.5px; color: #c3caff;
  text-transform: lowercase; overflow-wrap: anywhere;
}
.slotblock.loose .slot-head h4 { font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--text); }
.slotblock > .items, .slotblock > .empty, .slotblock > .errbox { min-width: 0; }

.empty { color: var(--muted); font-size: 13px; padding: 4px 2px; margin: 0; }

/* стрелка-раскрывашка у кнопки истории слота */
.chainbtn { display: inline-flex; align-items: center; gap: 5px; }
.chainbtn::after { content: "▸"; font-size: 9px; transition: transform .15s; }
.chainbtn[aria-expanded="true"]::after { transform: rotate(90deg); }

.chain { margin-top: 8px; display: grid; gap: 6px; min-width: 0; }
.chainbox { min-width: 0; display: grid; gap: 8px; }
.chain-row {
  display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border); min-width: 0;
}
.chain-row.old { opacity: .7; }
.chain-row .chain-mark {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.chain-row.cur .chain-mark { color: var(--ok); }
.chain-text { font-size: 13px; overflow-wrap: anywhere; }
.chain-row.old .chain-text { text-decoration: line-through; text-decoration-color: rgba(248, 113, 113, .35); }
.chain-when { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ── «Лента» ── */
.notes { display: grid; gap: 12px; min-width: 0; }
.note { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px; min-width: 0; }
.note-head { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; margin-bottom: 8px; }
.note-when { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.note-tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); background: var(--bg-soft);
}
.note-text { margin: 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-items { margin-top: 10px; display: grid; gap: 8px; }
.note-none { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.more-wrap { margin-top: 14px; display: flex; justify-content: center; }

/* ── изменения «было → стало» ── */
.changes { display: grid; gap: 10px; min-width: 0; }
.change {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; min-width: 0;
}
.change-slot {
  font-family: var(--mono); font-size: 10.5px; color: #c3caff; margin-bottom: 8px;
  overflow-wrap: anywhere;
}
.change-line { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 8px; align-items: start; }
.change-line .lbl { font-size: 11px; color: var(--muted); padding-top: 2px; }
.change-line p { margin: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.change-line.old p { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(248, 113, 113, .4); }
.change-arrow { color: var(--muted); font-size: 12px; padding: 2px 0 2px 54px; }
.change.vetoed .change-line.new p { text-decoration: line-through; opacity: .6; }
.change .actions { margin-top: 11px; }

/* ── кнопки ── */
.btn {
  font: inherit; font-size: 13.5px; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  white-space: nowrap; transition: border-color .15s, background .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; font-weight: 600; color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.tiny { padding: 4px 10px; font-size: 12px; border-radius: 9px; }
.btn.danger { background: transparent; color: var(--err); border-color: rgba(248, 113, 113, .45); }
.btn.danger:hover:not(:disabled) { border-color: var(--err); background: rgba(248, 113, 113, .08); }

kbd {
  font: inherit; font-size: 11px; padding: 1px 6px; border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 6px; background: var(--bg-soft); color: var(--text);
  white-space: nowrap;
}

/* ── поиск ── */
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; min-width: 0; }
.search-input {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 13px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.search-input:focus { border-color: var(--accent); }
.searchout { display: grid; gap: 8px; min-width: 0; }
.found { margin: 0 0 2px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
mark { background: rgba(124, 140, 255, .28); color: var(--text); border-radius: 3px; padding: 0 2px; }

/* ── нижняя панель записи ── */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(11, 14, 20, .74), rgba(11, 14, 20, .97) 40%);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.dock-inner { width: min(100%, 960px); margin-inline: auto; }
.dock-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dock-status { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; }
.dock-label { font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.dock-hint { color: var(--muted); font-size: 11.5px; }
.dock-timer {
  font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; letter-spacing: .5px;
}
.dock-timer.warn { color: var(--warn); }

.rec {
  position: relative; flex: none; width: 58px; height: 58px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border); color: var(--text);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  display: grid; place-content: center; box-shadow: var(--shadow);
  transition: transform .12s, border-color .2s, opacity .2s;
  -webkit-tap-highlight-color: transparent;
}
.rec:hover:not(:disabled) { transform: translateY(-1px); }
.rec:active:not(:disabled) { transform: scale(.97); }
.rec:disabled { opacity: .5; cursor: not-allowed; }
.rec .ring { position: absolute; inset: -6px; border-radius: 50%; border: 2px solid transparent; }
.mic {
  width: 22px; height: 22px; justify-self: center; position: relative;
  border-radius: 50% 50% 46% 46%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: background .2s;
}
.mic::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  width: 2px; height: 6px; border-radius: 2px; background: currentColor; opacity: .5;
}
.rec.recording { border-color: rgba(255, 77, 109, .6); }
.rec.recording .mic { background: linear-gradient(135deg, var(--rec), #ff8fa3); }
.rec.recording .ring { border-color: rgba(255, 77, 109, .5); animation: pulse 1.5s ease-out infinite; }
.rec.busy .mic { background: linear-gradient(135deg, #4b5570, #39415a); }
.rec.busy .ring {
  border-color: transparent;
  background: conic-gradient(from 0deg, transparent 0 70%, var(--accent) 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  animation: spin .9s linear infinite;
}
/* пульсация на transform, а не на inset: анимация не создаёт переполнения */
@keyframes pulse { 0% { transform: scale(1); opacity: .85; } 100% { transform: scale(1.16); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

.meter { display: flex; align-items: flex-end; gap: 3px; height: 22px; margin: 8px 2px 0; }
.meter span {
  width: 4px; height: 3px; border-radius: 3px; background: var(--border);
  transition: height .08s linear, background .2s;
}
.meter.on span { background: linear-gradient(180deg, var(--accent), var(--accent-2)); }

.progress { display: flex; align-items: center; gap: 9px; margin-top: 8px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.progress .p-text { overflow-wrap: anywhere; }
.p-time { margin-left: auto; flex: none; font-variant-numeric: tabular-nums; }
.spin {
  flex: none; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

/* ── шторка результата ── */
.sheet {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5, 7, 12, .72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  overflow: hidden;
}
.sheet-box {
  width: min(100%, 760px); max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px 20px 0 0;
  padding: 15px 15px calc(22px + env(safe-area-inset-bottom));
  animation: rise .24s ease;
  min-width: 0;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 700; flex: 1 1 auto; min-width: 0; }
.sheet-head .btn { flex: none; }
.sheet-meta { margin: 6px 0 0; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.sheet-body { margin-top: 12px; display: grid; gap: 10px; min-width: 0; }
.note-full { margin: 0; padding: 12px; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px; }
.sect { margin: 6px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ── подвал ── */
.foot { margin-top: 26px; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.foot a { color: #c3caff; }

/* ── тост ── */
.toast {
  position: fixed; left: 50%; bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  max-width: min(92vw, 460px); text-align: center; z-index: 90; overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(248, 113, 113, .5); }

/* ── шире экран: те же карточки, но в две колонки ── */
@media (min-width: 900px) {
  .topics { grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }
  .sheet { align-items: center; padding: 24px; }
  .sheet-box { border-radius: 20px; max-height: 86dvh; }
}
@media (min-width: 1200px) {
  .notes { grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
}
@media (max-width: 460px) {
  .sub { display: none; }
  .counters { margin-left: 0; width: 100%; }
  .tab { font-size: 12.5px; padding: 9px 4px; }
  .topic-meta { margin-left: 0; text-align: left; flex-basis: 100%; }
  .toast { bottom: calc(132px + env(safe-area-inset-bottom)); }
}
