/* soft-links · мини-апп картотеки
   Тот же визуальный язык, что и в локальном дашборде:
   ночь #0D131F · глубина #151D2C · кайма #26324A · сигнал #59B2F6 · янтарь #F2B94B
   Системные шрифты намеренно: в вебвью внешний шрифт — лишняя задержка и точка отказа. */

:root {
  --bg: #0D131F;
  --surface: #151D2C;
  --surface-2: #1B2537;
  --line: #26324A;
  --text: #E9EEF7;
  --muted: #8B99B4;
  --accent: #59B2F6;
  --amber: #F2B94B;

  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

  --pad: 16px;
  --top-inset: env(safe-area-inset-top, 0px);
  --bot-inset: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ------------------------------------------------------------- вьюхи */

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.view[hidden] { display: none; }

/* Экраны второго уровня выезжают справа */
.sheet {
  z-index: 10;
  animation: slide-in .24s cubic-bezier(.32, .72, .28, 1);
  box-shadow: -18px 0 40px rgba(0, 0, 0, .45);
}
#v-note { z-index: 20; }

@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

.body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--pad) calc(28px + var(--bot-inset));
}

/* ------------------------------------------------------------ шапка */

.top { padding: calc(18px + var(--top-inset)) var(--pad) 0; }

.top h1 {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -.02em;
}
.top h1 span { color: var(--accent); }

.top .sub {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}

/* ------------------------------------------------------------ поиск */

.search {
  position: relative;
  margin: 14px var(--pad) 4px;
  flex: none;
}

.search svg {
  position: absolute; left: 13px; top: 50%; translate: 0 -50%;
  width: 17px; height: 17px; stroke: var(--muted); pointer-events: none;
}

.search input {
  width: 100%;
  padding: 12px 40px 12px 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;      /* меньше 16px iOS зумит при фокусе */
  appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(89, 178, 246, .16);
}

.search .clear {
  position: absolute; right: 6px; top: 50%; translate: 0 -50%;
  width: 30px; height: 30px; border-radius: 8px;
  color: var(--muted); font-size: 15px; display: none;
}
.search.on .clear { display: block; }

/* ------------------------------------------------------- сетка папок */

.label {
  margin: 20px 0 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--muted);
  display: flex; align-items: center; gap: 12px;
}
.label::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px 12px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 840px) { .grid { grid-template-columns: repeat(4, 1fr); } }

/* карточка-папка с язычком */
.folder {
  position: relative;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px 13px 13px 13px;
  padding: 14px 13px 12px;
  display: flex; flex-direction: column; gap: 7px;
  transition: transform .12s ease, border-color .12s ease;
}
.folder::before {
  content: '';
  position: absolute; top: -8px; left: -1px;
  width: 58px; height: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 6px 9px 0 0;
}
.folder:active { transform: scale(.975); border-color: var(--accent); }

.folder .head { display: flex; align-items: baseline; gap: 8px; }
.folder .ico { font-size: 18px; line-height: 1; }
.folder .count {
  margin-left: auto;
  font-family: var(--mono); font-weight: 700; font-size: 19px;
  color: var(--amber);
}
.folder .name { font-size: 13px; line-height: 1.3; font-weight: 500; }

/* ------------------------------------------------------------ списки */

.rows { display: flex; flex-direction: column; }

.row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  color: inherit;
}
.row:active { background: var(--surface); }

.row .t { font-size: 14.5px; line-height: 1.35; font-weight: 500; }
.row .t mark { background: none; color: var(--amber); }

.row .m {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px 9px;
  margin-top: 5px;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
}

.chip {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  font-family: var(--mono); font-size: 10px;
  color: var(--muted);
  max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.link { color: var(--accent); border-color: rgba(89, 178, 246, .32); }
.chip.amber { color: var(--amber); border-color: rgba(242, 185, 75, .32); }

.empty {
  padding: 40px 0; text-align: center;
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
}

/* ------------------------------------------- шапка экранов 2-го уровня */

.sheet-head {
  display: flex; align-items: center; gap: 6px;
  padding: calc(12px + var(--top-inset)) var(--pad) 12px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.nav-back {
  width: 34px; height: 34px; flex: none;
  font-size: 26px; line-height: 1;
  color: var(--accent);
  margin-left: -6px;
}

.sheet-title .t { font-size: 15px; font-weight: 600; line-height: 1.25; }
.sheet-title .m { font-family: var(--mono); font-size: 11px; color: var(--amber); margin-top: 1px; }

/* ------------------------------------------------------------ деталка */

.note-cat {
  display: inline-block;
  font-family: var(--mono); font-size: 11px;
  color: var(--accent);
  border: 1px solid rgba(89, 178, 246, .32);
  border-radius: 20px; padding: 2px 10px;
  margin: 18px 0 12px;
}

.note-title {
  font-size: 19px; font-weight: 700; line-height: 1.3;
  letter-spacing: -.01em;
  margin-bottom: 10px;
}

.note-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding-bottom: 16px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.note-html { font-size: 15px; overflow-wrap: break-word; }
.note-html b { color: #fff; }
.note-html a { overflow-wrap: anywhere; }
.note-html code, .note-html pre {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
}
.note-html code { padding: 1px 5px; }
.note-html pre { display: block; padding: 10px 12px; overflow-x: auto; margin: 9px 0; }
.note-html blockquote {
  border-left: 3px solid var(--accent);
  background: var(--surface);
  padding: 7px 12px; border-radius: 0 8px 8px 0; margin: 9px 0;
  color: var(--muted);
}
.tg-tag { color: var(--amber); }
.spoiler { background: var(--line); color: transparent; border-radius: 3px; }
.spoiler:active { color: inherit; background: none; }

.shots { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.shots img {
  width: 100%; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}

.block { margin-top: 24px; }
.block h3 {
  font-family: var(--mono); font-weight: 400;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .16em;
  color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px;
}
.block h3::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.link-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 13px; margin-bottom: 8px;
  color: var(--text);
}
.link-card:active { border-color: var(--accent); }
.link-card .dom { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.link-card .u {
  display: block; margin-top: 2px;
  font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere;
}

.file-row {
  display: flex; gap: 8px; align-items: baseline;
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  padding: 7px 0; border-bottom: 1px dashed var(--line);
  overflow-wrap: anywhere;
}

.note-nav { margin-top: 26px; display: flex; flex-direction: column; gap: 8px; }
.note-nav button {
  text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: 10px 13px; font-size: 12.5px;
}
.note-nav button span {
  display: block; font-family: var(--mono); font-size: 10px;
  color: var(--muted); margin-bottom: 2px;
}

/* --------------------------------------------------------- загрузка */

.boot {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.boot[hidden] { display: none; }
.boot-in { padding: 0 32px; }
.boot p { margin-top: 14px; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

.spin {
  display: inline-block; width: 26px; height: 26px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, .sheet { animation: none !important; transition: none !important; }
}

/* ====================================================================
   Версия 2: вкладки, теги, превью, таймлайн, коллекции
   ==================================================================== */

/* --------------------------------------------------------- вкладки */

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px var(--pad) 0;
  flex: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  flex: none;
}
.tab.on { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 600; }

.pane { display: none; }
.pane.on { display: block; }

/* ------------------------------------------------------ карточки папок */

.folder .meta {
  display: flex; gap: 5px; flex-wrap: wrap;
  margin-top: 2px;
  font-family: var(--mono); font-size: 9.5px; color: var(--muted);
}

/* --------------------------------------------------------- облако тегов */

.cloud { display: flex; flex-wrap: wrap; gap: 8px; }

.tagchip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  font-size: 12.5px;
}
.tagchip b { font-family: var(--mono); font-size: 11px; color: var(--amber); font-weight: 600; }
.tagchip.on { border-color: var(--accent); background: var(--surface-2); }

/* ------------------------------------------------------------ превью */

.row {
  display: flex;
  gap: 11px;
  align-items: flex-start;
}
.row .shot {
  width: 54px; height: 40px; flex: none;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface-2) center/cover no-repeat;
}
.row .shot.ico {
  background-size: 22px;
  background-repeat: no-repeat;
  background-position: center;
}
.row .txt { flex: 1; min-width: 0; }

.badge {
  display: inline-block;
  font-family: var(--mono); font-size: 9.5px;
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid transparent;
}
.badge.dead  { color: #FF8B8B; border-color: rgba(255,139,139,.34); background: rgba(255,139,139,.08); }
.badge.stars { color: var(--amber); border-color: rgba(242,185,75,.3); }
.badge.arch  { color: #FFB765; border-color: rgba(255,183,101,.34); }

/* ------------------------------------------------------------ здоровье */

.health {
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 14px 15px;
}
.health h4 {
  font-family: var(--mono); font-weight: 400; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .14em; color: var(--muted);
  margin-bottom: 10px;
}
.bar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.bar i { display: block; height: 100%; }
.bar i.ok      { background: #4FBF8B; }
.bar i.blocked { background: var(--amber); }
.bar i.slow    { background: #7C8AA5; }
.bar i.gone    { background: #E36A6A; }
.bar i.skipped { background: var(--line); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
.legend span { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ------------------------------------------------------------ таймлайн */

.year { margin-bottom: 16px; }
.year-head {
  display: flex; align-items: baseline; gap: 9px;
  font-family: var(--mono); font-size: 12px;
}
.year-head b { font-size: 15px; color: var(--text); }
.year-head span { color: var(--amber); }
.year-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 6px 0 5px; background: var(--surface-2); }
.year-bar i { height: 100%; }
.year-top { font-size: 11.5px; color: var(--muted); }

.src-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.src-row .nm { flex: 1; font-size: 13.5px; }
.src-row .ct { font-family: var(--mono); font-size: 12px; color: var(--amber); }
.src-row .dd { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

/* --------------------------------------------------------- коллекции */

.new-coll { display: flex; gap: 8px; margin-top: 14px; }
.new-coll input {
  flex: 1; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font-size: 14px;
}
.new-coll input:focus { outline: none; border-color: var(--accent); }
.new-coll button {
  padding: 10px 15px; border-radius: 10px;
  background: var(--accent); color: var(--bg); font-weight: 600; font-size: 13px;
}
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); line-height: 1.45; }

.head-btn {
  margin-left: auto; flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line); color: var(--accent); font-size: 17px;
}

/* ------------------------------------------------------------- модалка */

.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(7,11,19,.7);
  display: flex; align-items: flex-end;
}
.modal[hidden] { display: none; }
.sheet-card {
  width: 100%;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 16px var(--pad) calc(16px + var(--bot-inset));
  max-height: 76vh; overflow-y: auto;
}
.sheet-card-head { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
button.wide {
  width: 100%; margin-top: 12px; padding: 12px;
  border: 1px solid var(--line); border-radius: 11px; color: var(--muted); font-size: 13.5px;
}

.check { margin-left: auto; color: var(--accent); font-size: 15px; }

/* ------------------------------------------------------ деталка: добавки */

.tagline { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
.tagline a {
  font-family: var(--mono); font-size: 10.5px;
  padding: 2px 8px; border: 1px solid var(--line); border-radius: 20px;
  color: var(--muted); background: var(--surface);
}

.gh {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--muted);
}
.gh b { color: var(--amber); }

.dead-note {
  margin-top: 8px; padding: 9px 12px;
  border-radius: 9px;
  background: rgba(227,106,106,.09);
  border: 1px solid rgba(227,106,106,.3);
  font-size: 12.5px; color: #FFB3B3;
}
.dead-note a { color: var(--accent); }

.summary {
  margin-bottom: 14px; padding: 11px 13px;
  background: var(--surface); border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  font-size: 14.5px; line-height: 1.45;
}

/* ====================================================================
   Версия 3: читаемость, фильтры, действия, скачивание
   ==================================================================== */

.top-row { display: flex; align-items: flex-start; gap: 12px; }
.top-row > div:first-child { flex: 1; min-width: 0; }

.icon-btn {
  flex: none;
  width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  color: var(--accent); font-size: 17px; line-height: 1;
}
.icon-btn:active { background: var(--surface-2); }

/* --------------------------------------------------- быстрые входы */

.quick { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0 2px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }

.quick button {
  flex: none;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 104px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface);
  text-align: left;
}
.quick button b { font-family: var(--mono); font-size: 17px; color: var(--amber); }
.quick button span { font-size: 11px; color: var(--muted); line-height: 1.25; }
.quick button:active { border-color: var(--accent); }

/* ------------------------------------------- инструменты над списком */

.list-tools { flex: none; padding: 10px var(--pad) 0; }

.search.inline { margin: 0; }
.search.inline input { padding: 10px 36px 10px 13px; font-size: 13.5px; }
.search.inline .clear { display: none; }
.search.inline.on .clear { display: block; }

.chips-row {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 9px 0 2px; scrollbar-width: none;
}
.chips-row::-webkit-scrollbar { display: none; }

.fchip {
  flex: none;
  padding: 5px 11px;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface);
  font-size: 11.5px; color: var(--muted);
  white-space: nowrap;
}
.fchip.on { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ------------------------------------------------ разделители по датам */

.daysep {
  position: sticky; top: 0; z-index: 2;
  margin: 14px 0 2px;
  padding: 5px 0 5px;
  background: linear-gradient(var(--bg) 70%, transparent);
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.daysep:first-child { margin-top: 4px; }

/* ------------------------------------------------------------ строки */

.row .t { display: block; }
.row .sum {
  display: block; margin-top: 3px;
  font-size: 12.5px; line-height: 1.4; color: var(--muted);
}

/* скелетоны загрузки */
.skel { padding: 12px 2px; border-bottom: 1px solid var(--line); display: flex; gap: 11px; }
.skel i, .skel u {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.skel i { width: 54px; height: 40px; flex: none; }
.skel u { height: 12px; text-decoration: none; }
.skel .lines { flex: 1; display: flex; flex-direction: column; gap: 7px; padding-top: 3px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* --------------------------------------------------- оригинал поста */

.orig-toggle {
  width: 100%; text-align: left;
  margin-top: 14px; padding: 10px 12px;
  border: 1px dashed var(--line); border-radius: 10px;
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
}
.orig-toggle:active { border-color: var(--accent); }
.orig-body { margin-top: 10px; }
.orig-body[hidden] { display: none; }

/* --------------------------------------------------------- вложения */

.file-card {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface);
}
.file-card .fi { font-size: 19px; flex: none; }
.file-card .fn { flex: 1; min-width: 0; }
.file-card .fn b { display: block; font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.file-card .fn span { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.file-card a.dl, .file-card button.dl {
  flex: none; padding: 7px 12px;
  border: 1px solid rgba(89,178,246,.4); border-radius: 9px;
  color: var(--accent); font-size: 12px; white-space: nowrap;
}
.file-card a.dl:active, .file-card button.dl:active { background: var(--surface-2); }

.tg-open {
  display: block; width: 100%; text-align: center;
  margin-top: 10px; padding: 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--accent); font-size: 13.5px;
}

/* ------------------------------------------------------------- тосты */

.toast {
  position: fixed; left: 50%; translate: -50% 0;
  bottom: calc(24px + var(--bot-inset));
  z-index: 60;
  padding: 11px 18px;
  border-radius: 22px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: 0 8px 26px rgba(0,0,0,.45);
  animation: rise .2s ease;
}
.toast[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ------------------------------------------------ строки в шторке */

.sheet-card .row { border-bottom: 1px solid var(--line); }
.sheet-card .row:last-of-type { border-bottom: none; }
.sheet-card .row .t { font-size: 14px; }
.sheet-card .row .ic { margin-right: 10px; }

@media (min-width: 760px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
  .body { padding-left: max(var(--pad), calc((100vw - 900px) / 2));
          padding-right: max(var(--pad), calc((100vw - 900px) / 2)); }
  .top, .search, .tabs, .list-tools, .sheet-head {
    padding-left: max(var(--pad), calc((100vw - 900px) / 2));
    padding-right: max(var(--pad), calc((100vw - 900px) / 2));
  }
}
