/* Trapola CHAT — Phase 0 UI. Theme-aware via CSS variables; html[data-theme]
   is set pre-paint by the inline script in base.html (no flash, no flip). */
:root, html[data-theme="light"] {
  --bg: #f6f7f9; --surface: #ffffff; --surface2: #eef1f5; --text: #17202b;
  --muted: #5c6a7a; --border: #d8dee7; --accent: #2563eb; --accent-fg: #ffffff;
  --bad: #b3261e; --ok: #137333; --warn-bg: #fff4d6; --warn-border: #e3b341;
  --shadow: 0 1px 3px rgba(16,24,40,.08);
}
html[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e28; --surface2: #1f2937; --text: #e6edf5;
  --muted: #93a3b5; --border: #2b3646; --accent: #5b93ff; --accent-fg: #0b1220;
  --bad: #ff8a80; --ok: #7ddba3; --warn-bg: #3a2f14; --warn-border: #a67c1a;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; }
.muted { color: var(--muted); } .small { font-size: .85em; } .block { display: block; }
.error { color: var(--bad); } .bad { color: var(--bad); } .ok { color: var(--ok); }
.warntext { display: block; color: var(--bad); font-size: .85em; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 17px; text-decoration: none; color: var(--text); }
.devbadge { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text);
  font-size: 11px; padding: 2px 7px; border-radius: 999px; font-weight: 600; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topnav a { text-decoration: none; color: var(--text); }
.who { color: var(--muted); font-size: .85em; }
.themebtn { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  min-width: 44px; min-height: 36px; cursor: pointer; font-size: 16px; }
.inline { display: inline; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.linkbtn.danger { color: var(--bad); }

button.primary, .btn { min-height: 44px; padding: 8px 16px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text); font: inherit; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; min-height: 48px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; min-height: 44px; width: 100%; }
input[type="checkbox"] { width: auto; min-height: 0; }
label { display: block; margin-bottom: 10px; font-size: .92em; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 10px; }
.stack > * { margin-bottom: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 16px; }
.grid .wide { grid-column: 1 / -1; }
.narrownum { width: 110px; }

.centered { display: flex; justify-content: center; padding: 48px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.narrow { max-width: 460px; width: 100%; }
.page { max-width: 1060px; margin: 0 auto; padding: 20px 16px 60px; }
.tokenbox { background: var(--surface2); padding: 14px; border-radius: 8px; word-break: break-all; white-space: pre-wrap; }

/* Workspace shell: sidebar | thread | members */
.shell { display: grid; grid-template-columns: 264px 1fr 280px; gap: 0;
  height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface);
  padding: 12px; overflow-y: auto; }
.sidehead { font-size: .78em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 4px 6px; }
.chanlist { list-style: none; margin: 0; padding: 0; }
.chan { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  text-decoration: none; color: var(--text); min-height: 40px; }
.chan:hover { background: var(--surface2); }
.chan.active { background: var(--surface2); font-weight: 600; }
.channame { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.unread { background: var(--accent); color: var(--accent-fg); border-radius: 999px;
  font-size: .75em; min-width: 22px; text-align: center; padding: 1px 6px; font-weight: 700; }
.newchan { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
.newchan summary { cursor: pointer; font-weight: 600; }
.alerts { margin-bottom: 8px; }
.alert { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px;
  padding: 8px 10px; font-size: .85em; margin-bottom: 8px; }

.pane { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chanhead { display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chanhead h2 { margin: 0; font-size: 18px; }
.chanhead p { margin: 2px 0 0; }
.banner.warn { background: var(--warn-bg); border-bottom: 1px solid var(--warn-border); padding: 10px 18px; }
.thread { flex: 1; overflow-y: auto; padding: 14px 18px; }
.daysep { text-align: center; color: var(--muted); font-size: .8em; margin: 16px 0 10px; }
.msghead { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 9px; background: var(--surface2);
  border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: .85em; }
.author { font-weight: 700; }
.ts { color: var(--muted); font-size: .78em; }
.botbadge { background: var(--accent); color: var(--accent-fg); font-size: .68em; font-weight: 700;
  border-radius: 5px; padding: 1px 5px; vertical-align: middle; }
.msgbody { margin: 2px 0 2px 42px; white-space: pre-wrap; word-break: break-word; }
.attach { margin: 2px 0 2px 42px; font-size: .9em; }
.composer { display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface); }
.composer input { flex: 1; }
.settings { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 18px; }
.settings summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.rowactions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.empty { padding: 40px; }
.empty-thread { padding: 20px 0; }

.members { border-left: 1px solid var(--border); background: var(--surface); padding: 14px; overflow-y: auto; }
.members.hidden { display: none; }
.members ul { list-style: none; margin: 0; padding: 0; }
.member { display: flex; gap: 9px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.mname { min-width: 0; }

.pdot { display: inline-block; width: 9px; height: 9px; border-radius: 999px; background: var(--muted);
  vertical-align: middle; margin-left: 4px; }
.pdot.active { background: var(--ok); }
.pdot.idle { background: var(--warn-border); }
.pdot.offline { background: var(--muted); opacity: .45; }
.connstatus { font-weight: 600; }
.connstatus.ok { color: var(--ok); }
.connstatus.warn { color: var(--bad); }
.renameform { display: flex; gap: 8px; margin-top: 8px; max-width: 420px; }
.renameform input { flex: 1; min-height: 40px; }
.renameform .btn { min-height: 40px; }

table.dense { border-collapse: collapse; width: 100%; font-size: .92em; }
table.dense th, table.dense td { border-bottom: 1px solid var(--border); text-align: left; padding: 7px 8px; vertical-align: top; }
table.kv th { width: 220px; color: var(--muted); font-weight: 600; }
td.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.curl { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.rowform { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.rowform select { width: auto; }
.console h3 { margin-bottom: 4px; }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 230px 1fr; }
  .members { display: none; }
  .members.open { display: block; position: fixed; right: 0; top: 53px; bottom: 0; width: 280px; z-index: 4; box-shadow: var(--shadow); }
}
@media (max-width: 700px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .thread { min-height: 300px; }
  .who { display: none; }
}
