/* ===== Plex Lumin - shared styles ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #08080a;
  --panel: #121216;
  --panel2: #191921;
  --border: #26262e;
  --text: #e8e6e0;
  --muted: #8b8a93;
  --gold: #d4af37;
  --gold-dim: #9c8228;
  --good: #4caf7d;
  --bad: #d05555;
  --warn: #d09b3c;
}
@font-face {
  font-family: "Julius Sans One";
  src: url("/static/fonts/JuliusSansOne-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; }

/* ---------- landing spotlight ---------- */
.stage {
  position: fixed; inset: 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 120%, #0c0c10 0%, #050506 60%);
  display: flex; align-items: center; justify-content: center;
}
.beam {
  position: absolute; top: -12vh; left: 50%;
  width: 52vmin; height: 72vh;
  transform: translateX(-50%);
  background: linear-gradient(to bottom,
    rgba(255, 244, 214, 0.55) 0%,
    rgba(255, 244, 214, 0.18) 55%,
    rgba(255, 244, 214, 0.00) 100%);
  clip-path: polygon(46% 0, 54% 0, 100% 100%, 0 100%);
  filter: blur(12px);
  animation: flicker 8s ease-in-out infinite;
  pointer-events: none;
}
.beam-source {
  position: absolute; top: -6vh; left: 50%;
  width: 18vmin; height: 10vmin; transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255,248,224,0.9), transparent 70%);
  filter: blur(10px); pointer-events: none;
}
.pool {
  position: absolute; top: 60vh; left: 50%;
  width: 72vmin; height: 22vmin;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, rgba(255,244,214,0.16), transparent 68%);
  filter: blur(8px);
  animation: flicker 8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  42% { opacity: 0.92; }
  44% { opacity: 0.98; }
  70% { opacity: 0.88; }
  72% { opacity: 1; }
}
/* WebGL light-rays spotlight (lightrays.js); the CSS beam above stays as fallback */
.light-rays {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.stage.has-rays .beam,
.stage.has-rays .beam-source,
.stage.has-rays .pool { display: none; }
.hero { position: relative; z-index: 2; text-align: center; }
.hero h1 {
  font-family: "Julius Sans One", "Segoe UI", system-ui, sans-serif;
  font-size: clamp(2.4rem, 9vmin, 5.2rem);
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  font-weight: 400; /* Julius Sans One ships a single 400 weight */
  color: #f7f0dd;
  text-shadow: 0 0 24px rgba(255,244,214,0.55), 0 0 80px rgba(255,244,214,0.25);
}
.hero .tag {
  margin-top: 1rem;
  color: rgba(240, 233, 214, 0.66);
  letter-spacing: 0.14em;
  font-size: 0.9rem;
  text-transform: uppercase;
}
.hero .actions { margin-top: 2.6rem; display: flex; gap: 1rem; justify-content: center; }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-block;
  padding: 0.55rem 1.4rem;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  background: transparent;
  color: var(--gold);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: rgba(212, 175, 55, 0.12); box-shadow: 0 0 14px rgba(212,175,55,0.25); text-decoration: none; }
.btn.solid { background: var(--gold); color: #17130a; font-weight: 600; }
.btn.solid:hover { background: #e2c052; }
.btn.danger { border-color: #7d3434; color: var(--bad); }
.btn.danger:hover { background: rgba(208, 85, 85, 0.12); box-shadow: 0 0 12px rgba(208,85,85,0.2); }
.btn.small { padding: 0.22rem 0.7rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.icon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.34rem; line-height: 0;
}
.btn.icon svg { display: block; }

input, select, textarea {
  background: #0d0d11;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--border); box-shadow: none; }
input[type="checkbox"] { width: auto; accent-color: var(--gold); }
textarea { resize: vertical; min-height: 70px; }
label { font-size: 0.82rem; color: var(--muted); display: block; margin-bottom: 0.2rem; }
.field { margin-bottom: 0.9rem; }
.field input, .field select, .field textarea { width: 100%; }

/* ---------- toggle switch (boolean rows in the account popups) ---------- */
label.switch {
  display: flex; align-items: center; gap: 0.7rem;
  margin: 0 0 0.45rem;
  padding: 0.5rem 0.75rem;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
label.switch:hover { border-color: var(--gold-dim); background: rgba(212,175,55,0.05); }
label.switch:last-child { margin-bottom: 0; }
/* the real checkbox stays in the DOM for forms and a11y, just not visible */
.switch input[type="checkbox"] {
  position: absolute; opacity: 0; width: 0; height: 0; margin: 0; padding: 0;
}
.switch .track {
  position: relative; flex: 0 0 auto;
  width: 38px; height: 21px; border-radius: 999px;
  background: #24242c; border: 1px solid var(--border);
  transition: background 0.18s, border-color 0.18s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s, background 0.18s;
}
.switch input:checked + .track { background: rgba(212,175,55,0.22); border-color: var(--gold-dim); }
.switch input:checked + .track::after { transform: translateX(17px); background: var(--gold); box-shadow: 0 0 8px rgba(212,175,55,0.5); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 2px rgba(212,175,55,0.4); }
.switch input:disabled + .track { opacity: 0.4; }
.switch .sw-text { display: flex; flex-direction: column; line-height: 1.25; }
.switch .sw-text .hint { color: var(--muted); font-size: 0.75rem; }

/* ---------- auth card ---------- */
.center-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.card h1 {
  font-family: "Julius Sans One", "Segoe UI", system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: #f7f0dd;
  text-shadow: 0 0 16px rgba(255,244,214,0.5), 0 0 44px rgba(255,244,214,0.22);
  text-align: center;
  margin-bottom: 1.4rem;
}
.card .sub { text-align: center; color: var(--muted); font-size: 0.72rem; margin-top: 1.1rem; }
.card .sub a { color: var(--muted); }
.card .btn.solid {
  background: #fff;
  color: #17130a;
  border-color: #fff;
}
.card .btn.solid:hover {
  background: #fff;
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(212,175,55,0.55), 0 0 40px rgba(212,175,55,0.28);
}

/* ---------- app layout ---------- */
.topbar {
  position: relative;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.7rem 1.2rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
/* same treatment as the landing hero, scaled down to header size:
   text-indent cancels the trailing letter-space so it centres true */
.topbar .brand {
  font-family: "Julius Sans One", "Segoe UI", system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: #f7f0dd;
  text-shadow: 0 0 12px rgba(255,244,214,0.5), 0 0 34px rgba(255,244,214,0.22);
  white-space: nowrap;
  /* dead center of the header, independent of what sits left/right */
  position: absolute; left: 50%; transform: translateX(-50%);
}
.topbar .spacer { flex: 1; }
.topbar .btn { color: #fff; }
.topbar .btn:hover { color: #fff; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }

/* ---------- right side menu (admin) ---------- */
.side-menu {
  position: fixed; right: 1rem; top: 50%; transform: translateY(-50%);
  z-index: 60;
  display: flex; flex-direction: column; gap: 0.5rem;
  width: 118px;
}
.side-menu .btn {
  width: 100%; text-align: center;
  padding: 0.5rem 0.4rem;
  font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--panel);
  color: #fff;
}
.side-menu .btn:hover { background: rgba(212,175,55,0.12); color: #fff; }
/* keep page content clear of the rail */
body.has-side-menu .wrap { padding-right: 9rem; }

.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.4rem;
}
.section > h2,
details.section > summary {
  font-size: 0.95rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.9rem; font-weight: 500;
  display: flex; align-items: center; gap: 0.6rem;
}
.section > h2 .count,
details.section > summary .count { color: var(--muted); font-size: 0.8rem; letter-spacing: 0; text-transform: none; }

.req-quota {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem;
  margin: -0.35rem 0 0.95rem;
  padding: 0.55rem 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-left: 2px solid var(--gold-dim);
  border-radius: 4px;
}
.req-quota[hidden] { display: none; }
.req-quota-label {
  font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 500;
}
.req-quota-value {
  font-size: 0.88rem; color: var(--text); font-variant-numeric: tabular-nums;
  text-align: right;
}
.req-quota.is-empty {
  border-left-color: var(--bad);
  background: rgba(208,85,85,0.06);
}
.req-quota.is-empty .req-quota-value { color: #e8a0a0; }
.req-quota.is-ok { border-left-color: var(--good); }

/* collapsible sections: the header stays put, the body folds away */
details.section > summary {
  cursor: pointer; list-style: none; user-select: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: "›";
  display: inline-block;
  font-size: 1.1rem; line-height: 1;
  transition: transform 0.15s ease;
}
details.section[open] > summary::before { transform: rotate(90deg); }
details.section > summary:hover { color: #e2c052; }
/* no gap under the header while collapsed */
details.section:not([open]) > summary { margin-bottom: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }

/* ---------- tables ---------- */
/* tables size themselves to the section; long free text truncates instead of
   stretching the row, so sections do not grow a horizontal scrollbar */
.tbl-wrap { max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 0.87rem; table-layout: auto; }
th, td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
td { overflow-wrap: anywhere; }
td.trunc {
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
tr:hover td { background: rgba(255,255,255,0.02); }
tbody tr.rowlink { cursor: pointer; }
td .btn { margin-right: 0.3rem; }

.badge {
  display: inline-block; padding: 0.08rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; letter-spacing: 0.04em; border: 1px solid;
}
.badge.on { color: var(--good); border-color: var(--good); }
.badge.off { color: var(--muted); border-color: var(--border); }
.badge.gold { color: var(--gold); border-color: var(--gold-dim); }
.badge.red { color: var(--bad); border-color: #7d3434; }
.badge.amber { color: var(--warn); border-color: #7d612c; }

/* ---------- progress bars (torrents) ---------- */
.prog { background: #0c0c10; border: 1px solid var(--border); border-radius: 4px; height: 14px; min-width: 120px; overflow: hidden; }
.col-prog { min-width: 140px; }
.prog > div { height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); transition: width 0.6s ease; }
.prog.seeding > div { background: linear-gradient(90deg, #2e7d55, var(--good)); }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.82rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 0.45rem; max-height: 380px; overflow-y: auto; padding: 0.4rem 0.2rem; }
.msg { max-width: 78%; padding: 0.45rem 0.8rem; border-radius: 10px; font-size: 0.88rem; }
.msg.me   { align-self: flex-end; background: rgba(212,175,55,0.16); border: 1px solid var(--gold-dim); }
.msg.them { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); }
.msg .t { display: block; font-size: 0.68rem; color: var(--muted); margin-top: 0.15rem; }
.chat-send { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.chat-send textarea { flex: 1; min-height: 44px; }

.thread-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 380px; overflow-y: auto; }
.thread-item {
  text-align: left; background: var(--panel2); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.5rem 0.8rem; cursor: pointer; color: var(--text); font: inherit;
}
.thread-item:hover, .thread-item.active { border-color: var(--gold-dim); }
.thread-item .preview { color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,0.72);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 1.6rem; width: 100%; max-width: 420px;
  max-height: 92vh; overflow-y: auto;
}
.modal.wide { max-width: 560px; }
.modal.xwide { max-width: 940px; }
.modal h3 { color: var(--gold); font-weight: 500; letter-spacing: 0.08em; margin-bottom: 1rem; }

/* ---------- misc ---------- */
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 160px; }
.notice { padding: 0.6rem 0.9rem; border-radius: 6px; font-size: 0.85rem; margin: 0.6rem 0; display: none; }
.notice.ok { display: block; background: rgba(76,175,125,0.1); border: 1px solid #2e5c45; color: var(--good); }
.notice.err { display: block; background: rgba(208,85,85,0.1); border: 1px solid #6c3030; color: var(--bad); }
/* blocks stacked inside a section, e.g. inside Application */
.sub-block, .danger-zone { margin-top: 1.6rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.sub-block h3, .danger-zone h3 {
  font-size: 0.8rem; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 0.7rem;
}
.sub-block h3 { color: var(--gold); }
.danger-zone h3 { color: var(--bad); margin-bottom: 0.5rem; }

/* ---------- built-in browser ---------- */
.poster { border-radius: 4px; display: block; background: var(--panel2); object-fit: cover; }
.poster.ph { aspect-ratio: 2 / 3; border: 1px solid var(--border); }
.hit {
  display: flex; align-items: center; gap: 0.8rem; width: 100%; text-align: left;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem 0.7rem; margin-bottom: 0.45rem; cursor: pointer;
  color: var(--text); font: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.hit:hover { border-color: var(--gold-dim); background: rgba(212,175,55,0.06); }
.hit-body { flex: 1; display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.hit-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-card { display: flex; gap: 1.2rem; align-items: flex-start; flex-wrap: wrap; }
.title-body { flex: 1; min-width: 260px; }
.ai-text {
  margin-top: 0.9rem; padding: 0.8rem;
  background: #0d0d11; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.78rem;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

footer.foot { text-align: center; color: #55545c; font-size: 0.75rem; padding: 1rem 0 2rem; }

/* ---------- kebab (three-dot) action menu ---------- */
.kb-menu {
  position: fixed; z-index: 120;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  min-width: 180px; padding: 0.3rem;
  display: flex; flex-direction: column;
}
.kb-menu button {
  background: none; border: none; text-align: left; color: var(--text);
  font: inherit; font-size: 0.85rem; padding: 0.4rem 0.7rem;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.kb-menu button:hover { background: rgba(212,175,55,0.1); color: var(--gold); }
.kb-menu button.danger { color: var(--bad); }
.kb-menu button.danger:hover { background: rgba(208,85,85,0.1); color: var(--bad); }
.kb-menu .kb-sep { height: 1px; background: var(--border); margin: 0.25rem 0.4rem; }

/* ---------- floating live chat ---------- */
.chat-fab {
  position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 90;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--gold); color: #17130a; border: none; cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.chat-fab:hover { background: #e2c052; transform: translateY(-2px); }
.chat-fab .fab-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 0.72rem; font-weight: 600;
  display: none; align-items: center; justify-content: center;
}
.chat-fab .fab-badge.show { display: flex; }
.chat-panel {
  position: fixed; right: 1.4rem; bottom: 5.6rem; z-index: 90;
  width: min(360px, calc(100vw - 2rem));
  height: min(480px, calc(100vh - 8rem));
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.65);
  display: none; flex-direction: column; overflow: hidden;
}
.chat-panel.open { display: flex; }
.cp-head {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); background: var(--panel2);
}
.cp-head .cp-title {
  flex: 1; color: var(--gold); letter-spacing: 0.08em; font-size: 0.85rem; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cp-head button { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 1.05rem; line-height: 1; padding: 0.1rem 0.3rem; }
.cp-head button:hover { color: var(--text); }
.cp-body { flex: 1; overflow-y: auto; padding: 0.7rem; display: flex; flex-direction: column; gap: 0.45rem; }
.cp-body .thread-list { max-height: none; }
.cp-send { display: flex; gap: 0.5rem; padding: 0.6rem; border-top: 1px solid var(--border); }
.cp-send textarea { flex: 1; min-height: 42px; max-height: 100px; }

/* ---------- AI log terminal ---------- */
.ai-term {
  background: #0a0a0c;
  border: 1px solid var(--border);
  border-radius: 6px;
  height: min(52vh, 420px);
  overflow-y: auto;
  padding: 0.7rem 0.85rem;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #c8c6c0;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-term .l-time { color: #6a6972; margin-right: 0.45rem; }
.ai-term .l-req { color: #8b8a93; margin-right: 0.45rem; }
.ai-term .l-info { color: #c8c6c0; }
.ai-term .l-ok { color: #4caf7d; }
.ai-term .l-warn { color: #d09b3c; }
.ai-term .l-error { color: #d05555; }
.ai-term .empty { color: #6a6972; }

/* ---------- expandable media requests ---------- */
.req-list { display: flex; flex-direction: column; gap: 0.35rem; }
.req-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel2);
  overflow: hidden;
}
.req-item.open { border-color: #3a3a45; }
.req-row {
  width: 100%;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: transparent; border: none; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
}
.req-row:hover { background: rgba(255,255,255,0.03); }
.req-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.req-title {
  font-size: 0.95rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.req-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; flex-shrink: 0; }
.req-chevron {
  color: var(--muted); font-size: 1.1rem; line-height: 1;
  transition: transform 0.15s ease; flex-shrink: 0;
}
.req-item.open .req-chevron { transform: rotate(90deg); }
.req-panel {
  padding: 0 0.85rem 0.9rem;
  border-top: 1px solid var(--border);
}
.req-panel[hidden] { display: none; }
.req-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem 1rem;
  padding-top: 0.85rem;
  font-size: 0.88rem;
}

/* ========== tablet + mobile ========== */

/* tablet */
@media (max-width: 1100px) {
  .side-menu {
    position: static; transform: none; width: auto;
    flex-direction: row; flex-wrap: wrap;
    max-width: 1200px; margin: 1rem auto 0; padding: 0 1.2rem;
    gap: 0.4rem;
  }
  .side-menu .btn { width: auto; }
  body.has-side-menu .wrap { padding-right: 1.2rem; }

  .wrap { padding: 1.1rem 1rem 3.5rem; }
  .section { padding: 1rem 1.05rem; }
  .modal.xwide { max-width: min(940px, calc(100vw - 1.5rem)); }
  .prog { min-width: 80px; }
}

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .req-grid { grid-template-columns: 1fr 1fr; }
  .req-badges { max-width: 42%; }
  .title-body { min-width: 0; }
  .hero .actions { flex-wrap: wrap; }
  .chat-panel {
    right: 0.75rem; left: 0.75rem; bottom: 5.2rem;
    width: auto; height: min(70vh, 520px);
  }
  .chat-fab { right: 0.9rem; bottom: 0.9rem; }
}

/* phone */
@media (max-width: 640px) {
  body { font-size: 14px; }

  .topbar {
    padding: 0.65rem 0.75rem;
    gap: 0.5rem;
  }
  .topbar .brand {
    font-size: 0.82rem;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
  }
  .topbar .badge { display: none; }

  .wrap { padding: 0.85rem 0.75rem 5.5rem; max-width: 100%; }
  body.has-side-menu .wrap { padding-right: 0.75rem; padding-bottom: 7.2rem; }

  html, body { overflow-x: hidden; max-width: 100%; }

  /* admin side menu → sticky bottom bar (wrap, never scroll sideways) */
  .side-menu {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    transform: none; width: 100%;
    margin: 0; padding: 0.4rem 0.45rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
    max-width: none;
    flex-direction: row; flex-wrap: wrap;
    gap: 0.3rem;
    background: rgba(18, 18, 22, 0.96);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(10px);
    z-index: 80;
    overflow: hidden;
  }
  .side-menu .btn {
    flex: 1 1 calc(33.33% - 0.3rem);
    min-width: 0;
    max-width: 100%;
    padding: 0.5rem 0.25rem;
    font-size: 0.65rem;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .section { padding: 0.85rem 0.8rem; margin-bottom: 1rem; border-radius: 6px; }
  .section > h2,
  details.section > summary {
    font-size: 0.82rem; letter-spacing: 0.08em; flex-wrap: wrap;
  }

  .card { padding: 1.35rem 1.1rem; max-width: 100%; }
  .card h1 {
    font-size: 1.15rem;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
  }
  .center-wrap { padding: 0.75rem; }

  .hero h1 {
    font-size: clamp(1.7rem, 11vw, 2.6rem);
    letter-spacing: 0.2em;
    text-indent: 0.2em;
  }
  .hero .tag { font-size: 0.75rem; letter-spacing: 0.1em; padding: 0 0.8rem; }
  .hero .actions {
    margin-top: 1.8rem;
    flex-direction: column;
    align-items: stretch;
    padding: 0 1.4rem;
  }
  .hero .actions .btn { text-align: center; }

  .btn { padding: 0.5rem 1rem; font-size: 0.85rem; }
  .row { gap: 0.45rem; }
  .row > input { min-width: 0; width: 100%; flex: 1 1 100%; }
  .row > .btn, .row > label.btn { flex: 1 1 auto; }

  /* drop less-important columns; never scroll sideways */
  .m-hide { display: none !important; }
  .tbl-wrap {
    overflow: hidden;
    max-width: 100%;
  }
  table {
    font-size: 0.8rem;
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }
  th, td {
    padding: 0.45rem 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  td.trunc { max-width: none; }
  td .btn { white-space: nowrap; }

  .req-row {
    flex-wrap: wrap;
    gap: 0.45rem 0.6rem;
    padding: 0.65rem 0.7rem;
  }
  .req-main { flex: 1 1 100%; }
  .req-badges { max-width: none; justify-content: flex-start; }
  .req-chevron { margin-left: auto; }
  .req-grid { grid-template-columns: 1fr; gap: 0.55rem; }
  .req-panel { padding: 0 0.7rem 0.8rem; }

  .modal-back { padding: 0.5rem; align-items: flex-end; }
  .modal, .modal.wide, .modal.xwide {
    max-width: 100%;
    max-height: min(92vh, 100%);
    padding: 1.15rem 1rem;
    border-radius: 10px 10px 0 0;
  }
  .ai-term { height: min(48vh, 340px); font-size: 0.72rem; }

  .chat-fab {
    right: 0.75rem;
    bottom: calc(4.4rem + env(safe-area-inset-bottom, 0px));
    width: 50px; height: 50px;
  }
  body:not(.has-side-menu) .chat-fab { bottom: 0.9rem; }
  .chat-panel {
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: min(85vh, 100%);
    border-radius: 12px 12px 0 0;
    max-width: none;
  }
  body.has-side-menu .chat-panel {
    bottom: calc(3.6rem + env(safe-area-inset-bottom, 0px));
    height: min(78vh, calc(100% - 4rem));
  }

  .title-card { flex-direction: column; gap: 0.8rem; }
  .hit { padding: 0.55rem; }
  .prog { min-width: 0; width: 100%; height: 12px; }
  .col-prog { min-width: 0; width: 22%; }
  .row { flex-wrap: wrap; max-width: 100%; }
  .row > * { max-width: 100%; }
  .ai-term { overflow-x: hidden; word-break: break-word; white-space: pre-wrap; }

  footer.foot { padding: 0.6rem 0 1.2rem; }
  body.has-side-menu footer.foot { padding-bottom: 6.2rem; }
}

/* very small phones */
@media (max-width: 380px) {
  .topbar .brand {
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-indent: 0.16em;
  }
  .side-menu .btn {
    font-size: 0.6rem;
    padding: 0.45rem 0.2rem;
  }
}
