:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #10213d;
  --muted: #5f708d;
  --primary: #2f6bff;
  --primary-2: #4e7bff;
  --danger: #e5484d;
  --border: #dce5f4;
  --shadow: 0 14px 30px rgba(23, 45, 84, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    linear-gradient(rgba(12, 24, 50, 0.58), rgba(12, 24, 50, 0.58)),
    url("https://www.berkeley.edu/wp-content/uploads/2022/10/Sather-Tower-and-Bay-Bridge-at-sunset.jpg") center/cover fixed no-repeat;
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.topbar h1 {
  margin: 0 0 2px;
  font-size: 1.05rem;
  font-weight: 600;
}

.topbar .subtitle {
  margin: 0;
  font-size: 0.79rem;
}

.topbar-actions { display: flex; gap: 8px; }

.topbar .btn {
  padding: 7px 12px;
  font-size: 0.8rem;
}


.login-popover {
  position: absolute;
  right: 24px;
  top: calc(100% + 10px);
  width: min(360px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.hidden { display: none; }

.actions.compact { margin: 10px 0 2px; }

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

h1, h2 { margin: 0 0 10px; }
.subtitle, .meta { color: var(--muted); margin: 0 0 14px; }

main { padding: 22px; max-width: 1200px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.notice { margin: 12px 0; background: #eef4ff; border: 1px solid #d2e0ff; padding: 10px; border-radius: 10px; }
.grid-2, .grid-3 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

label { display: block; margin: 10px 0 6px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fbfcff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
}
textarea { resize: vertical; }

th, td { border-bottom: 1px solid var(--border); text-align: left; padding: 10px; }
table { width: 100%; border-collapse: collapse; }

.actions, .mode-actions, .hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }

.hero-actions { margin-bottom: 18px; }

.research-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.research-card {
  border: 1px solid #c9d8ef;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  padding: 14px;
}

.research-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.research-head h3 {
  margin: 0;
  font-size: 1rem;
}

.research-body { color: #243a5c; margin-bottom: 10px; }
.research-links { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border: 1px solid transparent;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.btn:hover { filter: brightness(1.03); }
.btn-outline { background: rgba(255, 255, 255, 0.88); color: #003262; border: 1px solid #89a7ca; }
.btn-ghost { background: #fff5f5; color: var(--danger); border: 1px solid #ffd0d3; }
.btn-danger { background: var(--danger); }

.btn-prominent {
  min-width: 200px;
  background: #003262;
  color: #f8fafc;
  border-color: #003262;
  font-weight: 700;
}

.btn-prominent:hover {
  background: #0b457d;
  color: #f8fafc;
}

.btn-hero-primary {
  min-width: 200px;
  background: #003262;
  color: #f8fafc;
  font-weight: 700;
}
.btn-hero-primary:hover { background: #0b457d; }

.btn-hero-secondary {
  min-width: 200px;
  background: rgba(13, 31, 62, 0.4);
  color: #f8fafc;
  border-color: rgba(248, 250, 252, 0.75);
  font-weight: 700;
}
.btn-hero-secondary:hover { background: rgba(248, 250, 252, 0.22); }

.btn-research-expand {
  background: rgba(0, 50, 98, 0.05);
  color: #003262;
  border-color: #003262;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 7px 14px;
}
.btn-research-expand:hover {
  background: #003262;
  color: #fff;
}

.btn-overview {
  background: transparent;
  color: #003262;
  border-color: #003262;
  font-size: 0.86rem;
  font-weight: 600;
}
.btn-overview:hover { background: #003262; color: #fff; }

.btn-overview.btn-prominent { color: #f8fafc; }

.btn-portal {
  background: #fdb515;
  color: #402d00;
  border-color: #e3a316;
  font-size: 0.86rem;
  font-weight: 600;
}
.btn-portal:hover { background: #ffc20f; }

.log { background: #f7faff; border: 1px solid var(--border); padding: 10px; border-radius: 10px; min-height: 140px; }
.metric { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #fbfdff; }
.metric span { display: block; color: var(--muted); }
.metric strong { font-size: 1.6rem; }

.forum-controls {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.forum-control-action {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 2px;
  gap: 8px;
}

.forum-home-panel { margin-top: 0; }
.task-panel { margin-top: 16px; }
.notice.small { font-size: 0.88rem; }
.meta.small { font-size: 0.84rem; }
.source-btn { margin-right: 8px; }

.source-popover {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 28px));
  max-height: 78vh;
  overflow: auto;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 20;
}

.forum-layout { display: grid; grid-template-columns: 320px 1fr; gap: 14px; }
.forum-list, .thread-meta, .cell-card, .review-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
}

.forum-list { padding: 10px; max-height: 760px; overflow: auto; }
.thread-item {
  width: 100%;
  text-align: left;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fbff;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}
.thread-item small { display: block; color: var(--muted); margin-top: 5px; }
.thread-item.active { border-color: #8aadff; background: #edf4ff; }

.thread-meta { padding: 12px; margin-bottom: 12px; }
.cell-container { display: flex; flex-direction: column; gap: 10px; }
.cell-card { padding: 10px; }
.cell-card.highlight { outline: 2px solid #7db1ff; box-shadow: 0 0 0 2px rgba(77, 141, 255, 0.2); }
.cell-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.chip { padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }
.chip.ok { color: #17a34a; }
.chip.warn { color: #af7a0d; }
.cell-body { margin: 0; background: #f8fbff; border: 1px solid var(--border); padding: 10px; border-radius: 8px; white-space: pre-wrap; }
.cell-body.collapsed { max-height: 0; overflow: hidden; padding: 0; border: none; }
.review-list { margin-top: 6px; }
.review-item { padding: 10px; margin-top: 8px; }

@media (max-width: 980px) {
  .forum-layout,
  .grid-2,
  .grid-3,
  .research-grid,
  .forum-controls { grid-template-columns: 1fr; }

  .topbar { flex-direction: column; align-items: flex-start; }
}

.source-btn.hidden { display: none; }


.api-panel { margin: 14px 0; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: rgba(247, 250, 255, 0.94); }
.api-grid { display: grid; grid-template-columns: 240px 1fr; gap: 12px; align-items: start; }
.api-card { border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.api-feed { max-height: 180px; overflow: auto; }
.instruction-item { border: 1px solid var(--border); border-radius: 10px; background: #f8fbff; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.instruction-item small { color: var(--muted); }
