:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #b3141c;
  --accent-soft: #fdecec;
  --ok: #17803d;
  --warn: #b45309;
  --warn-soft: #fef5e7;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f25;
    --line: #2c313a;
    --text: #e8eaed;
    --muted: #98a0ad;
    --accent: #ef4a52;
    --accent-soft: #3a1c1e;
    --ok: #4ade80;
    --warn: #fbbf24;
    --warn-soft: #362b12;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--accent); font-size: 13px; min-height: 18px; }
.spacer { flex: 1; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; min-height: 140px; line-height: 1.6; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.01em; }
.topbar #search { width: 200px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs .count { opacity: .7; margin-left: 5px; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.list { display: grid; gap: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  gap: 6px;
}
.card:hover { border-color: var(--muted); }
.card.selected { border-left-color: var(--accent); background: var(--accent-soft); }
.card .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card .title { font-weight: 600; font-size: 14px; }
.card .snippet {
  color: var(--muted); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.badge {
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.badge.cat { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.mute { opacity: .8; }

/* ---------- Detail ---------- */
.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 18px;
}
.detail h2 { margin: 0; font-size: 17px; }
.block { display: grid; gap: 8px; }
.block > h3 {
  margin: 0; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); font-weight: 600;
}
.original {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  white-space: pre-wrap;
}
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; font-size: 13px;
}
.meta-grid div span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb { width: 150px; display: grid; gap: 4px; }
.thumb img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumb a { font-size: 12px; color: var(--accent); }
.checklist { margin: 0; padding-left: 18px; font-size: 13px; color: var(--warn); }
.notice {
  background: var(--warn-soft); color: var(--warn);
  border-radius: 8px; padding: 10px 12px; font-size: 13px;
}
.notice.danger { background: var(--accent-soft); color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .right { margin-left: auto; display: flex; gap: 8px; }
.history { font-size: 12px; color: var(--muted); display: grid; gap: 3px; }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius);
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50;
}

/* ---------- Handy ---------- */

.back { display: none; }

@media (max-width: 900px) {
  body { font-size: 16px; }

  .topbar {
    gap: 8px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  /* Zeile 1: Titel und Abmelden. Zeile 2: Tabs. Zeile 3: Suche. */
  .brand { font-size: 15px; flex: 1; }
  .topbar #who { display: none; }
  .topbar .spacer { display: none; }
  .topbar #logout { order: 1; padding: 6px 12px; font-size: 13px; }
  .tabs { order: 5; flex-basis: 100%; }
  .topbar #search { order: 10; flex-basis: 100%; width: 100%; }

  /* Tabs bleiben in einer Zeile und werden gewischt. */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 2px 12px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { padding: 8px 14px; flex: 0 0 auto; }

  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }

  /* Liste und Detail teilen sich den Bildschirm, statt zu stapeln. */
  .detail-pane { display: none; }
  body.detail-open .list-pane { display: none; }
  body.detail-open .detail-pane { display: block; }

  .back {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    margin-bottom: 10px;
    font-weight: 600;
  }

  .card { padding: 14px; gap: 8px; }
  .card .title { font-size: 16px; }
  .card .snippet { font-size: 14px; -webkit-line-clamp: 3; }

  .detail { padding: 16px; gap: 16px; border-radius: 12px; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  textarea { min-height: 200px; font-size: 16px; }
  .thumb { width: calc(50% - 5px); }
  .thumb img { height: 130px; }

  /* Aktionen bleiben am unteren Rand erreichbar. */
  .actions {
    position: sticky;
    bottom: 0;
    z-index: 4;
    margin: 0 -16px -16px;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .actions button { min-height: 48px; padding: 12px; }
  .actions #btn-publish { grid-column: 1 / -1; font-weight: 600; }
  .actions .right { display: contents; }

  .toast { bottom: max(20px, env(safe-area-inset-bottom)); width: max-content; max-width: 90vw; }
}
