/* SnagStash v2 - dark, mobile-first */
:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1e242e;
  --border: #262c36;
  --text: #e6e9ef;
  --muted: #9099a8;
  --accent: #f0a840;
  --accent-text: #14181f;
  --danger: #e5534b;
  --ok: #4cc38a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-mark { color: var(--accent); }

.search { flex: 1; min-width: 0; }
.search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }

/* ---- Nav ---- */
.mainnav {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  padding: 6px 12px;
  border-radius: 16px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
.mainnav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.mainnav a .count {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
}
.nav-logout { margin-left: auto; }

/* ---- Layout ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 16px 14px 60px; }

.empty { color: var(--muted); text-align: center; padding: 60px 0; font-size: 16px; }

/* ---- Category chips ---- */
.cat-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.chip span { opacity: .6; font-size: 11px; }
.chip.active { border-color: var(--accent); color: var(--accent); }

/* ---- Card grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .12s ease, opacity .25s ease, border-color .12s ease;
}
.card:hover { border-color: #38404e; }
.card.is-read { opacity: .72; }
.card.removing { opacity: 0; transform: scale(.96); }

.card-thumb { display: block; aspect-ratio: 16/9; background: var(--surface-2); overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 42px;
  font-weight: 700;
  color: var(--border);
  text-transform: uppercase;
}

.card-body { padding: 10px 12px 6px; flex: 1; }
.card-title { margin: 0 0 6px; font-size: 15px; line-height: 1.35; }
.card-excerpt {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-meta time { color: var(--muted); font-size: 12px; margin-left: auto; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge-cat { color: var(--accent); background: rgba(240, 168, 64, .12); }
.badge-wait { color: #d9a03f; background: rgba(217, 160, 63, .1); font-style: italic; }

.card-actions {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.act-fav.on { color: var(--accent); }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-accent[disabled] { opacity: .6; cursor: wait; }
.btn-danger { background: none; border-color: var(--danger); color: var(--danger); }

/* ---- Pager ---- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
  color: var(--muted);
  font-size: 14px;
}

/* ---- Detail ---- */
.detail { max-width: 760px; margin: 0 auto; }
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.detail-head-actions { display: flex; gap: 4px; }
.detail-hero { width: 100%; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid var(--border); }

.detail-form label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.detail-form input,
.detail-form textarea,
.detail-form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.detail-form input:focus,
.detail-form textarea:focus,
.detail-form select:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: space-between; margin-top: 8px; }

.detail-links { display: flex; flex-direction: column; gap: 6px; margin: 18px 0; }
.detail-links a { color: var(--accent); font-size: 14px; word-break: break-all; }

.detail-attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.detail-attachments img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }

.detail-meta { color: var(--muted); font-size: 12px; margin-top: 24px; }

/* ---- Digest ---- */
.digest-head { margin-bottom: 20px; }
.digest-head h1 { margin: 0 0 4px; font-size: 22px; }
.digest-head p { margin: 0; color: var(--muted); font-size: 14px; }
.digest-section { margin: 26px 0 12px; font-size: 16px; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 8px; }

/* ---- Login ---- */
.login-box {
  max-width: 340px;
  margin: 14vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
}
.login-brand { font-size: 22px; font-weight: 700; }
.login-tagline { color: var(--muted); margin: 4px 0 20px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 14px; }
.login-box label { display: block; text-align: left; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.login-box input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.login-box .btn { width: 100%; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 50;
}
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .card-excerpt { -webkit-line-clamp: 2; }
  .form-row { grid-template-columns: 1fr; }
}
