:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-hover: #eef1f5;
  --fg: #1b1f24;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --star: #d97706;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --bg-soft: #1a1e23;
    --bg-hover: #22272e;
    --fg: #e6e8eb;
    --muted: #9aa3ad;
    --line: #2a2f36;
    --accent: #7aa2ff;
    --accent-soft: #1d2a44;
    --star: #f0b429;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.brand {
  font-weight: 700;
  letter-spacing: .5px;
  text-decoration: none;
}

.tabs a {
  color: var(--muted);
  text-decoration: none;
  margin-right: 14px;
  padding: 4px 0;
  font-size: 14px;
}

.tabs a.active {
  color: var(--fg);
  border-bottom: 2px solid var(--accent);
}

.counter {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: 240px minmax(320px, 1fr) minmax(400px, 1.15fr);
  height: calc(100vh - 53px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  overflow-y: auto;
  padding: 10px 8px 40px;
}

.side-all,
.folder-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.side-all:hover,
.folder-name:hover,
.feed:hover { background: var(--bg-hover); }

.side-all.active,
.folder-name.active { background: var(--accent-soft); color: var(--accent); }

.folder { margin-top: 10px; }

.folder-name {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.folder-name.static { cursor: default; }

.feed {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 4px 14px;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 14px;
}

.feed.active { background: var(--accent-soft); color: var(--accent); }

.feed-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 7px;
  flex: none;
}

.list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.list-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

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

.row { border-bottom: 1px solid var(--line); }

.row-link {
  display: block;
  padding: 10px 16px 12px;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.row:hover .row-link { background: var(--bg-hover); }

.row.active .row-link {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.row-top {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
}

.row-top time { margin-left: auto; }

.row-feed {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.star { color: var(--star); }

.row h3 {
  margin: 4px 0 2px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.row.is-read h3 { font-weight: 400; color: var(--muted); }

.snippet {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.more {
  margin: 14px;
  width: calc(100% - 28px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.more:hover { background: var(--bg-hover); }

.reader { overflow-y: auto; padding: 0 24px 60px; }

.reader-empty {
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
}

.reader-empty .hint { font-size: 13px; }

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 12px;
  font-family: inherit;
}

.article-head {
  padding: 18px 0 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.article-meta .feed { color: var(--accent); }

.dot { opacity: .6; }

.article h1 {
  margin: 6px 0 12px;
  font-size: 22px;
  line-height: 1.3;
}

.article-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-bottom: 10px;
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  border-radius: var(--radius);
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ghost:hover { background: var(--bg-hover); }

.ghost.small { padding: 3px 8px; font-size: 12px; }

.origin {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  margin-left: auto;
}

.article-content {
  padding-top: 16px;
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: break-word;
}

.article-content p { margin: 0 0 1em; }

.article-content img,
.article-content video {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.article-content figure { margin: 1em 0; }
.article-content figcaption {
  font-size: 13px;
  color: var(--muted);
}

.article-content a { color: var(--accent); }

.article-content pre {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  font-size: 13px;
}

.article-content code {
  background: var(--bg-soft);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: .92em;
}

.article-content pre code { padding: 0; background: none; }

.article-content blockquote {
  margin: 1em 0;
  padding: 0 0 0 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.article-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

.article-content th,
.article-content td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

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

@media (max-width: 1100px) {
  .grid { grid-template-columns: 200px minmax(280px, 1fr) minmax(320px, 1fr); }
}

/* Без JS (класс .m не выставлен) на узком экране — прежняя раскладка в столбик. */
@media (max-width: 860px) {
  html:not(.m) .grid { display: block; height: auto; }
  html:not(.m) .sidebar,
  html:not(.m) .list { border-right: 0; border-bottom: 1px solid var(--line); }
  html:not(.m) .sidebar { max-height: 180px; }
  html:not(.m) .list { max-height: 45vh; }
  html:not(.m) .reader { padding: 0 16px 40px; }
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

.page h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.feed-add,
.feed-edit {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.feed-edit { margin: 0; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-row input,
.form-row select {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 9px;
}

.form-row input:focus,
.form-row select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.hint code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 3px;
}

.feeds {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.feeds th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

.feeds td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.feed-name { font-weight: 600; }

.feed-url {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.feed-error {
  font-size: 12px;
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.err { color: #c0392b; }
.muted { color: var(--muted); }

.actions {
  white-space: nowrap;
  text-align: right;
}

.actions .ghost { margin-left: 4px; }

.ghost.danger { color: #c0392b; border-color: #e6b8b3; }

.flash-slot:empty { display: none; }

.flash {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
}

.flash.ok {
  border-color: #9fd3a8;
  background: #eaf7ec;
  color: #1e6b2f;
}

.flash.err {
  border-color: #e6b8b3;
  background: #fdecea;
  color: #a3271b;
}

@media (prefers-color-scheme: dark) {
  .flash.ok { background: #17301d; color: #8fdca0; border-color: #2f6b3d; }
  .flash.err { background: #34191a; color: #f2a49a; border-color: #6b2f2f; }
  .err, .ghost.danger { color: #f28b82; }
}

form.htmx-request button[type="submit"] {
  opacity: .55;
  pointer-events: none;
}

form.htmx-request::after {
  content: " проверяю фид…";
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .actions { white-space: normal; }
}

.settings { margin-bottom: 12px; }

.settings .inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.inline-flash { display: inline-block; margin: 0; padding: 3px 9px; }

.interval-input { width: 70px; }

.src {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
}

.src.full {
  color: #1e6b2f;
  border-color: #9fd3a8;
  background: #eaf7ec;
}

.extract-box {
  margin-top: 22px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  font-size: 14px;
}

.extract-box p { margin: 0 0 8px; }

.extract-box form { display: inline; }

.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

@media (prefers-color-scheme: dark) {
  .src.full { background: #17301d; color: #8fdca0; border-color: #2f6b3d; }
}

.search { margin-left: auto; }

.search input {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  width: 260px;
}

.search input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--bg);
}

.topbar .counter { margin-left: 12px; }

mark {
  background: #fff3a3;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.small { font-size: 12px; }

.search-hint { padding: 14px 16px; font-size: 14px; line-height: 1.6; }

a.more.link {
  display: block;
  text-align: center;
  text-decoration: none;
  color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  mark { background: #5a4a00; color: #ffe9a3; }
}

@media (max-width: 1100px) {
  .search input { width: 170px; }
}

/* ===== мобильный режим: одна панель + выдвижной список фидов ===== */

.icon-btn { display: none; }
.scrim { display: none; }
.only-mobile { display: none; }

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

html.m .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  margin: -6px 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

html.m .icon-btn:active { background: var(--bg-hover); }
html.m .icon-btn svg { width: 20px; height: 20px; display: block; }

html.m .bars { position: relative; display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; }
html.m .bars::before,
html.m .bars::after { content: ""; position: absolute; left: 0; display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; }
html.m .bars::before { top: -6px; }
html.m .bars::after { top: 6px; }

html.m .topbar {
  flex-wrap: wrap;
  gap: 2px 10px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
}

html.m .menu-btn { order: 1; margin-right: 2px; }
html.m .brand { order: 2; font-size: 16px; }
html.m .counter { order: 3; margin-left: auto; margin-right: 0; font-size: 12px; padding: 2px 8px; }
html.m .search-btn { order: 4; margin-right: -6px; }

html.m .tabs {
  order: 5;
  display: flex;
  flex-basis: 100%;
  gap: 16px;
  margin-top: 2px;
  padding-top: 2px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

html.m .tabs::-webkit-scrollbar { display: none; }
html.m .tabs a { flex: none; margin-right: 0; padding: 8px 0 6px; font-size: 15px; }

html.m .search { order: 6; flex-basis: 100%; display: none; margin: 0; }
html.m .topbar.search-open .tabs { display: none; }
html.m .topbar.search-open .search { display: block; }
html.m .search input { width: 100%; padding: 9px 14px; font-size: 16px; }

/* основная сетка превращается в сцену с одной видимой панелью */
html.m .grid {
  display: block;
  position: relative;
  height: calc(100dvh - var(--topbar-h, 100px));
  min-height: 240px;
  overflow: hidden;
}

html.m .list,
html.m .reader {
  position: absolute;
  inset: 0;
  max-height: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 0;
  overscroll-behavior: contain;
}

html.m body:not(.view-article) .list { display: flex; }
html.m body.view-article .list { display: none; }
html.m body.view-article .reader { display: block; }
html.m body:not(.view-article) .reader { display: none; }

/* выдвижная панель фидов */
html.m .sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: min(86vw, 330px);
  max-height: none;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 8px calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-102%);
  transition: transform .22s ease, box-shadow .22s ease;
  will-change: transform;
}

html.m.drawer-open .sidebar {
  transform: none;
  box-shadow: 0 0 0 1px var(--line), 0 20px 44px rgba(0, 0, 0, .35);
}

html.m .scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

html.m.drawer-open .scrim { opacity: 1; pointer-events: auto; }
html.m.drawer-open .menu-btn { opacity: 0; pointer-events: none; }

html.m .drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

html.m .side-all,
html.m .folder-name { padding: 11px 10px; }
html.m .feed { padding: 10px 10px 10px 14px; font-size: 15px; }
html.m .folder-name { font-size: 11.5px; }

/* удобные тап-таргеты и плотность списка */
html.m .list-head { padding: 10px 14px; }
html.m .row-link { padding: 12px 14px 14px; }
html.m .row h3 { font-size: 16px; }
html.m .row-feed { max-width: 52%; }
html.m .snippet { font-size: 13.5px; }
html.m .more { width: auto; margin: 12px 14px calc(28px + env(safe-area-inset-bottom)); padding: 12px; }
html.m .search-hint { padding: 14px; }

/* читалка */
html.m .reader { padding: 0 14px calc(70px + env(safe-area-inset-bottom)); }
html.m .article-head { padding: 8px 0 8px; }
html.m .article h1 { font-size: 20px; line-height: 1.35; }
html.m .article-meta { font-size: 12.5px; }
html.m .article-actions { gap: 8px; padding-bottom: 8px; }
html.m .ghost { min-height: 38px; padding: 8px 12px; }
html.m .ghost.small { min-height: 34px; padding: 6px 10px; }
html.m .origin { margin-left: 0; }
html.m .article-content { font-size: 17px; line-height: 1.7; padding-top: 12px; }
html.m .article-content pre {
  margin-left: -14px;
  margin-right: -14px;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  padding: 12px 14px;
}
html.m .article-content table { font-size: 14px; display: block; overflow-x: auto; }
html.m .reader-back { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 8px; }
html.m .reader-empty { padding: 24px 0; }
html.m .reader-empty .hint { display: none; }
html.m .extract-box { margin-top: 18px; padding: 12px; }

/* страница фидов */
html.m .page { padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); }
html.m .page h2 { font-size: 16px; }
html.m .feed-add { padding: 12px; }
html.m .form-row { flex-direction: column; align-items: stretch; gap: 10px; }
html.m .form-row input,
html.m .form-row select,
html.m .form-row button { width: 100%; padding: 10px 11px; font-size: 16px; }
html.m .form-row .check { font-size: 14px; }
html.m .interval-input { width: 100%; }
html.m .feeds { font-size: 14px; }
html.m .feeds thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
html.m .feeds,
html.m .feeds tbody,
html.m .feeds tr,
html.m .feeds td { display: block; width: auto; }
html.m .feeds tr {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}
html.m .feeds td { padding: 3px 0; border: 0; }
html.m .feeds td[data-label]::before {
  content: attr(data-label) " · ";
  color: var(--muted);
  font-size: 12px;
}
html.m .feeds td.feed-main { padding-bottom: 6px; }
html.m .feeds td.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  text-align: left;
}
html.m .feeds td.actions .ghost { flex: 1 1 auto; margin: 0; text-align: center; }
html.m .feeds td[colspan] { padding: 0; }
html.m .feed-edit { padding: 0; border: 0; background: none; }
html.m .feed-error { max-width: none; white-space: normal; }
html.m .feeds-wrap { overflow: visible; }

/* на тач-устройствах не подсвечиваем hover */
@media (hover: none) {
  .row:hover .row-link,
  .side-all:hover,
  .folder-name:hover,
  .feed:hover,
  .more:hover,
  .ghost:hover { background: transparent; }
  .row.active .row-link { background: var(--accent-soft); }
  .side-all.active,
  .feed.active { background: var(--accent-soft); }
}
