:root {
  --bg: #0f1115;
  --card: #181b22;
  --line: #272b34;
  --text: #e7e9ee;
  --muted: #8b909c;
  --accent: #7c9cff;
  --yes: #4ade80;
  --no: #f59e0b;
  --forced: #c084fc;
  --danger: #f87171;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}
.token-row { display: flex; align-items: center; gap: 8px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--yes); }
.status.err { color: var(--danger); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%;
  background: #0f1218;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); }

button {
  cursor: pointer;
  background: var(--accent);
  color: #0b0e14;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
}
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
#token { width: 220px; }
#save-token { white-space: nowrap; }

.reply-details { margin-bottom: 12px; }
.reply-details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.reply-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.result { margin-left: 10px; font-size: 13px; }
.result.ok { color: var(--yes); }
.result.err { color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.muted, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.pill.yes { background: rgba(74,222,128,.15); color: var(--yes); }
.pill.no { background: rgba(245,158,11,.15); color: var(--no); }
.pill.forced { background: rgba(192,132,252,.15); color: var(--forced); }
.pill.error { background: rgba(248,113,113,.15); color: var(--danger); }

button.unlock { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 4px 10px; font-size: 12px; }
.msg-cell { max-width: 360px; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------------------
   Mobile bottom tab bar + slide-up settings sheet.
   On desktop these overlays are hidden and every section's controls render
   inline in their cards (unchanged). On mobile (<=768px) each section's
   controls move into a sheet that slides up when its tab is tapped.
   --------------------------------------------------------------------------- */
.tabbar, .sheet, .sheet-backdrop { display: none; }

@media (max-width: 768px) {
  /* Post has no inline output, so it lives only in the sheet. The table
     sections keep their tables in the page; only their Refresh moves. */
  #card-post { display: none; }
  .card-head [data-refresh] { display: none; }

  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  main { padding: 16px; }

  /* --- bottom tab bar (always tappable: highest layer) --- */
  .tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 70;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    gap: 4px;
  }
  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: transparent;
    color: var(--muted);
    border: none;
    border-radius: 10px;
    padding: 8px 4px;
    font-size: 11px;
    font-weight: 600;
  }
  .tab .tab-ic { font-size: 20px; line-height: 1; }
  .tab.active { color: var(--accent); background: rgba(124, 156, 255, 0.12); }

  /* --- dimming backdrop (below the tab bar, above the page) --- */
  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.28s ease;
  }
  .sheet-backdrop.show { opacity: 1; }

  /* --- slide-up sheet: sits above the tab bar so the tab stays tappable --- */
  .sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    z-index: 60;
    max-height: 72vh;
    padding: 0 18px 18px;
    background: var(--card);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
    transform: translateY(calc(100% + 80px));
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
  }
  .sheet.open { transform: translateY(0); }
  /* grab handle */
  .sheet::before {
    content: "";
    position: absolute;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px;
    border-radius: 999px;
    background: var(--line);
  }
  .sheet-head {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 12px;
    margin-bottom: 14px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
  }
  .sheet-head h2 { font-size: 16px; }
  .sheet-close {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2px 14px;
    font-size: 18px;
    line-height: 1.4;
  }
  .sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  /* a lone Refresh button reads better full-width in the sheet */
  .sheet-body > button[data-refresh] { width: 100%; }
}
