:root {
  --bg: #ffffff;
  --bg-soft: #f4f6f9;
  --bg-hover: #eaeef4;
  --fg: #1b2230;
  --muted: #667185;
  --border: #dde2ea;
  --accent: #2563c9;
  --accent-fg: #ffffff;
  --accent-soft: #e3ecfb;
  --danger: #c23b3b;
  --ok: #2e7d32;
  --warn: #a15c00;
  --topbar: 52px;
  --nav: 60px;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --bg-soft: #1d2127;
    --bg-hover: #262b33;
    --fg: #e3e6ea;
    --muted: #97a1af;
    --border: #2f353e;
    --accent: #78a4f2;
    --accent-fg: #0d1320;
    --accent-soft: #1f2d45;
    --danger: #ef7070;
    --ok: #79c47c;
    --warn: #e0a54a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  padding-bottom: calc(var(--nav) + env(safe-area-inset-bottom));
}

a { color: var(--accent); }

button, .button {
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  min-height: 36px;
}
button:hover { background: var(--bg-hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger { color: var(--danger); }
button.icon {
  background: none;
  border: none;
  padding: 0.3rem;
  min-width: 40px;
  min-height: 40px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}
button.icon:hover { color: var(--fg); background: var(--bg-hover); }
button:disabled { opacity: 0.5; cursor: default; }

input, select {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  width: 100%;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.areas { flex: 1; display: flex; gap: 0.25rem; }
.areas a {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.areas a.active { background: var(--accent-soft); color: var(--accent); }
.brand { font-size: 1.1rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.online::before { background: var(--ok); }
.status.offline::before { background: var(--warn); }

main { max-width: 760px; margin: 0 auto; padding: 0.75rem 1rem 1.5rem; }

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}
.nav a.active { color: var(--accent); }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.toolbar { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.toolbar input { flex: 1; }
.toolbar select { width: auto; flex: none; }
.toolbar h2 { flex: 1; margin: 0; font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.section { margin-bottom: 1rem; }
.section-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 0.25rem 0;
}
.section-head .count { font-weight: 400; }

.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.35rem 0.35rem 0.75rem;
  border-top: 1px solid var(--border);
  min-height: 56px;
  background: var(--bg);
  transition: transform 0.15s;
  touch-action: pan-y;
}
.row:first-child { border-top: none; }
.row.selected { background: var(--accent-soft); }
.row input[type="checkbox"] { width: 20px; height: 20px; flex: none; }
.row .main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: inherit;
  text-decoration: none;
  padding: 0.2rem 0;
}
.favicon {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-fg);
  background: var(--accent);
  object-fit: contain;
}
img.favicon { background: none; }
.text { min-width: 0; flex: 1; }
.title, .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 0.8rem; color: var(--muted); }
.badge { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }

.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

details.closed { margin-top: 1.5rem; }
details.closed summary { cursor: pointer; color: var(--muted); padding: 0.5rem 0; }

.selectbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav) + env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}
.selectbar .count { flex: 1; font-size: 0.9rem; }

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 1rem);
  z-index: 4;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  font-size: 1.8rem;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.switch { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; }

.card { border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

.reader { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--bg); }
.reader .toolbar { padding: 0.4rem 0.5rem; margin: 0; border-bottom: 1px solid var(--border); }
.reader .toolbar h2 { font-size: 1rem; }
.reader iframe { flex: 1; width: 100%; border: none; background: #fff; }

.login { display: grid; place-items: center; min-height: 80vh; padding: 1rem; }
.login form { width: min(360px, 100%); display: grid; gap: 0.75rem; }
.login label, dialog label { display: grid; gap: 0.25rem; font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  padding: 1rem;
  width: min(420px, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
dialog form { display: grid; gap: 0.75rem; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
dialog .choices { display: grid; gap: 0.4rem; max-height: 50vh; overflow: auto; }
dialog .choices button { text-align: left; }

#toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 0.75rem);
  z-index: 20;
  display: grid;
  gap: 0.5rem;
  width: min(480px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  font-size: 0.9rem;
}
.toast span { flex: 1; }
.toast button { background: none; border: none; color: inherit; font-weight: 600; text-transform: uppercase; }
.toast.error { background: var(--danger); color: #fff; }

input[type="checkbox"] { accent-color: var(--accent); }
.switch .sub { white-space: normal; }

.chips { display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.5rem; margin-bottom: 0.25rem; scrollbar-width: none; }
.chip {
  flex: none;
  display: flex;
  gap: 0.35rem;
  align-items: center;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
}
.chip .count { color: var(--muted); font-size: 0.8rem; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.row.entry { align-items: flex-start; padding-top: 0.5rem; padding-bottom: 0.5rem; }
.row.entry .title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.summary {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.row .actions { display: flex; flex: none; }
.sub.error { color: var(--danger); white-space: normal; }
.center { text-align: center; }
