:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f1f5f9;
  color: var(--text);
  line-height: 1.5;
}

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

/* ---- Header ---- */
.topbar {
  background: linear-gradient(135deg, #1e3a8a, #0f172a);
  color: #fff;
  padding: 18px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
}
.topbar .sub { color: #cbd5e1; font-size: 0.82rem; margin: 2px 0 0; }
.topbar .spacer { flex: 1; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* ---- Name bar / controls ---- */
.namebar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.namebar label { font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="search"] {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 1rem;
  min-width: 160px;
  flex: 1;
}
input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }

button {
  cursor: pointer;
  border: none;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
  transition: filter 0.15s, opacity 0.15s;
}
button:hover { filter: brightness(1.07); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: #eef2f7; color: var(--text); }
button.danger { background: var(--red); }
button.small { padding: 6px 12px; font-size: 0.85rem; }

.me-banner {
  background: var(--green-soft);
  border: 1px solid #86efac;
  color: #14532d;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.me-banner strong { font-weight: 700; }
.me-banner .spacer { flex: 1; }
.hidden { display: none !important; }

/* ---- Summary stats ---- */
.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  min-width: 110px;
}
.stat .num { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat.green .num { color: var(--green); }
.stat.red .num { color: var(--red); }

/* ---- Filter toolbar ---- */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.chip {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---- Category ---- */
.category { margin-bottom: 26px; }
.category-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--line);
}
.category-head .badge {
  background: var(--bg-soft);
  color: #fff;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: none;
}
.category-head h2 { font-size: 1.02rem; margin: 0; letter-spacing: 0.01em; }
.category-head .count { color: var(--muted); font-size: 0.8rem; margin-left: auto; }

/* ---- Topic grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.taken { border-left-color: var(--red); background: #fafbfc; }
.card.mine { border-left-color: var(--blue); background: var(--blue-soft); }

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.card-num {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.85rem;
  flex: none;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 2px 7px;
}
.card-title { font-weight: 700; font-size: 0.98rem; margin: 0; }
.card-desc {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-desc.expanded { -webkit-line-clamp: unset; }
.read-more {
  background: none;
  color: var(--blue);
  padding: 0;
  font-size: 0.8rem;
  font-weight: 600;
  align-self: flex-start;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}
.status {
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status.avail { color: var(--green); }
.status.taken { color: var(--red); }
.status .who { color: var(--muted); font-weight: 500; }
.card-foot .spacer { flex: 1; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

/* ---- Modal (login) ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal h2 { margin: 0 0 6px; }
.modal p { color: var(--muted); margin: 0 0 16px; font-size: 0.9rem; }
.modal input { width: 100%; margin-bottom: 12px; }
.modal button { width: 100%; }

/* ---- Admin table ---- */
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.admin-table th, .admin-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 0.9rem; vertical-align: top; }
.admin-table th { background: #f8fafc; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: none; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.pill.avail { background: var(--green-soft); color: #14532d; }
.pill.taken { background: var(--red-soft); color: #7f1d1d; }
.dim { color: var(--muted); }

@media (max-width: 560px) {
  .topbar h1 { font-size: 1rem; }
  .grid { grid-template-columns: 1fr; }
  .admin-table th:nth-child(3), .admin-table td:nth-child(3) { display: none; }
}
