/* Alerts v2 — mobile first. Light/dark via prefers-color-scheme or [data-theme]. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --text-2: #4b5563;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-soft: #e7eefc;
  --danger: #c2410c;
  --ok: #15803d;
  --ok-soft: #e3f4e8;
  --unread: #2563eb;
  --topbar: #1e293b;
  --topbar-text: #f8fafc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --tap: 44px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --text: #e8eaed; --text-2: #b6bcc6;
    --muted: #8b93a0; --border: #2a2f38; --accent: #6ea0ff; --accent-soft: #1f2a40; --danger: #f08a5d;
    --ok: #5fd08a; --ok-soft: #173024; --unread: #6ea0ff; --topbar: #0b0d11; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --text: #e8eaed; --text-2: #b6bcc6;
  --muted: #8b93a0; --border: #2a2f38; --accent: #6ea0ff; --accent-soft: #1f2a40; --danger: #f08a5d;
  --ok: #5fd08a; --ok-soft: #173024; --unread: #6ea0ff; --topbar: #0b0d11; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .25rem .5rem .25rem 1rem;
  padding-top: max(.25rem, env(safe-area-inset-top));
  background: var(--topbar); color: var(--topbar-text);
}
.brand { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.brand-logo { display: flex; flex: none; border-radius: 6px; }
.brand-logo img { display: block; width: 32px; height: 32px; border-radius: 6px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-home { font-size: .75rem; color: inherit; opacity: .75; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-home:hover { opacity: 1; text-decoration: underline; }
.brand-logo:focus-visible, .brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.topbar h1 { margin: 0; font-size: 1.125rem; font-weight: 700; letter-spacing: .01em; }
.topbar h1 a { color: inherit; text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: .125rem; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: inherit;
}
.icon-btn:hover { background: rgba(127, 127, 127, .15); }
.icon-btn:focus-visible, .btn:focus-visible, .pill input:focus-visible + span, .chip:focus-visible,
.more:focus-visible, .dot:focus-visible, .headline:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#fetch-btn.spinning svg { animation: spin 1s linear infinite; }
.signin {
  color: var(--topbar-text); text-decoration: none; font-weight: 600;
  padding: 0 .75rem; min-height: var(--tap); display: inline-flex; align-items: center;
}
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 34px; height: 34px; margin: 5px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: .9rem;
  background: var(--accent); color: #fff;
}
.menu-panel {
  position: absolute; right: .25rem; top: calc(100% + .25rem); min-width: 220px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: .5rem;
}
.menu-panel p { margin: .25rem .5rem .5rem; overflow-wrap: anywhere; }
.menu-panel a {
  display: flex; align-items: center; min-height: var(--tap); padding: 0 .5rem;
  border-radius: 8px; color: var(--text); text-decoration: none;
}
.menu-panel a:hover { background: var(--surface-2); }

.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50;
  background: var(--accent); transform: scaleX(0); transform-origin: left; opacity: 0;
}
.progress.htmx-request { opacity: 1; animation: load 1.2s ease-out infinite; }

/* ---------- search + filters ---------- */
.searchbar {
  position: sticky; top: calc(var(--tap) + .5rem + env(safe-area-inset-top)); z-index: 15;
  background: var(--bg); padding: .5rem .75rem;
}
.search-row { display: flex; gap: .5rem; max-width: 760px; margin: 0 auto; }
.search-field {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 0 .875rem; min-height: var(--tap); color: var(--muted);
}
.search-field:focus-within { border-color: var(--accent); }
.search-field input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font-size: 1rem; /* 16px stops iOS zooming on focus */
  outline: none; height: 42px;
}
.filter-btn {
  display: inline-flex; align-items: center; gap: .375rem; flex-shrink: 0;
  min-height: var(--tap); padding: 0 .875rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer;
}
.badge {
  min-width: 1.35rem; height: 1.35rem; padding: 0 .35rem; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: .75rem; display: inline-grid; place-items: center;
}

/* Filter sheet: slides up from the bottom on phones, centered panel on larger screens */
.sheet {
  width: 100%; max-width: 100%; max-height: 88vh; height: auto;
  margin: auto 0 0; padding: 0; border: 0;
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
  display: flex; flex-direction: column;
}
.sheet:not([open]) { display: none; }
.sheet[open] { animation: slide-up .2s ease-out; }
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem .5rem .25rem 1.25rem; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 1.125rem; }
.sheet-body { overflow-y: auto; padding: .5rem 1.25rem 1rem; overscroll-behavior: contain; }
.sheet-foot {
  display: flex; gap: .75rem; padding: .75rem 1.25rem;
  padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sheet-foot .btn { flex: 1; }
fieldset { border: 0; margin: 1rem 0 0; padding: 0; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: .5rem; display: flex; gap: .5rem; align-items: baseline; }
.pills { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 .875rem;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: .9375rem;
  background: var(--surface); user-select: none;
}
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill-hide input:checked + span { background: var(--danger); border-color: var(--danger); }
.alert-rows { display: flex; flex-direction: column; }
.alert-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center;
  padding: .25rem 0; border-bottom: 1px solid var(--border);
}
.alert-row:last-child { border-bottom: 0; }
.alert-row.mine .alert-name { font-weight: 600; }
.alert-row .pill span { min-height: 36px; padding: 0 .75rem; font-size: .875rem; }
.alert-name { overflow-wrap: anywhere; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 52px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.switch {
  appearance: none; flex-shrink: 0; width: 46px; height: 28px; border-radius: 999px; margin: 0;
  background: var(--surface-2); border: 1px solid var(--border); position: relative; cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem;
  min-height: var(--tap); padding: 0 1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; font-size: .9375rem;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn .when-busy, .btn.htmx-request .when-idle { display: none; }
.btn.htmx-request .when-busy { display: inline; }
.linkish { border: 0; background: none; color: var(--accent); padding: .5rem 0; cursor: pointer; font-weight: 600; }

/* ---------- list ---------- */
main { padding: 0 .75rem 2rem; }
#view { max-width: 760px; margin: 0 auto; }
.summary { margin: .25rem .25rem .5rem; color: var(--text-2); font-size: .9375rem; }
.notice {
  margin: 0 0 .75rem; padding: .75rem 1rem; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); font-size: .9375rem;
}
.chips {
  display: flex; gap: .5rem; overflow-x: auto; padding: .125rem .125rem .625rem;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: .375rem;
  min-height: 36px; padding: 0 .75rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); text-decoration: none; font-size: .875rem; white-space: nowrap;
}
.chip span { color: var(--muted); font-size: 1.1em; }
.chip-clear { background: transparent; color: var(--accent); font-weight: 600; }

.card {
  display: grid; grid-template-columns: 28px 1fr 40px; column-gap: .25rem; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .75rem .25rem .75rem .25rem; margin-bottom: .5rem;
}
.card.htmx-swapping { opacity: 0; transition: opacity .2s; }
.dot {
  width: 28px; height: 28px; margin-top: .05rem; border: 0; background: none; padding: 0; cursor: pointer;
  display: grid; place-items: center;
}
.dot::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent;
}
.card.unread .dot::before { background: var(--unread); border-color: var(--unread); }
button.dot { width: 40px; height: 40px; margin: -.375rem -.375rem 0 -.375rem; }
.card-main { min-width: 0; }
.headline {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 1rem; line-height: 1.35;
  overflow-wrap: anywhere;
}
.card:not(.unread) .headline { font-weight: 500; color: var(--text-2); }
.headline:visited { color: var(--text-2); }
.headline:hover { text-decoration: underline; }
.meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; margin-top: .375rem;
  color: var(--muted); font-size: .8125rem;
}
.meta .source { color: var(--text-2); max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta time { white-space: nowrap; }
.tag {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); font-size: .75rem; white-space: nowrap;
}
.tag-muted { background: var(--surface-2); color: var(--muted); }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.card.blocked .headline { color: var(--muted); }
.more {
  width: 40px; height: 40px; margin: -.375rem 0 0; border: 0; border-radius: 50%;
  background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.more:hover { background: var(--surface-2); }
.more[aria-expanded="true"] svg { transform: rotate(180deg); }
.detail { grid-column: 2 / 4; padding: .5rem .75rem .25rem 0; }
.detail .desc { margin: 0 0 .5rem; color: var(--text-2); }
.detail-msg { margin: 0 0 .5rem; padding: .5rem .75rem; border-radius: 8px; background: var(--accent-soft); font-size: .875rem; }
.facts { margin: 0 0 .5rem; display: grid; gap: .25rem; font-size: .8125rem; }
.facts div { display: grid; grid-template-columns: 6.5rem 1fr; gap: .5rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.fulltext { font-size: .9375rem; line-height: 1.6; }
.fulltext p { margin: 0 0 .75rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 .25rem; }

.more-sentinel, .end, .empty {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 1.25rem; color: var(--muted); font-size: .9375rem; text-align: center;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.error { padding: 1rem; color: var(--danger); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 150%); opacity: 0; visibility: hidden;
  transition: transform .25s, opacity .25s, visibility .25s;
  max-width: calc(100vw - 2rem); padding: .75rem 1.125rem; border-radius: 10px;
  background: #111827; color: #f9fafb; font-size: .9375rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes load { 0% { transform: scaleX(0); } 60% { transform: scaleX(.7); } 100% { transform: scaleX(.95); } }

/* Search matches (same yellow as the classic dashboard) */
mark.hl { background: #fff59d; color: #333; padding: 0 1px; border-radius: 2px; }
:root[data-theme="dark"] mark.hl { background: #f9a825; color: #1a1a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark.hl { background: #f9a825; color: #1a1a2e; } }
.snippet {
  margin: .25rem 0 0; color: var(--text-2); font-size: .875rem; line-height: 1.4;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.card.local-hidden { display: none; }
.local-note { text-align: center; color: var(--muted); padding: 1rem; font-size: .9375rem; }

.footer { text-align: center; padding: 0 1rem 2rem; font-size: .875rem; color: var(--muted); }
.footer a { color: var(--muted); display: inline-block; padding: .5rem; }

/* ---------- larger screens ---------- */
@media (min-width: 720px) {
  .topbar { padding-left: 1.5rem; padding-right: 1rem; }
  .card { grid-template-columns: 32px 1fr 44px; padding: .875rem .5rem; }
  .meta .source { max-width: 22rem; }
  .sheet {
    max-width: 560px; margin: auto; border-radius: 18px; max-height: 85vh;
  }
  .sheet[open] { animation: none; }
}
@media (min-width: 1100px) {
  #view, .search-row { max-width: 860px; }
  .headline { font-size: 1.0625rem; }
}

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