:root {
  --bg: #1a1d21;
  --sidebar: #19171d;
  --sidebar-active: #1164a3;
  --panel: #1a1d21;
  --text: #d1d2d3;
  --text-strong: #ffffff;
  --text-muted: #ababad;
  --border: #35373b;
  --hover: #222529;
  --accent: #1d9bd1;
  --code-bg: #232529;
  --code-border: #35373b;
  --danger: #e01e5a;
  --warn: #ecb22e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The browser's own `[hidden] { display: none }` sits in the user-agent
   stylesheet, so any author rule setting `display` beats it — `.channel__typing
   { display: flex }` left "Billy is typing…" on screen permanently, however
   diligently the JS set the attribute. The composer and lock notice are toggled
   the same way, so guard the attribute once, here. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.46668;
}

/* ---------- login ---------- */

.login-page {
  display: grid;
  place-items: center;
  background: #350d36;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: #ffffff;
  color: #1d1c1d;
  border-radius: 10px;
  padding: 36px 32px 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 26px;
  letter-spacing: -0.5px;
}

.login-intro {
  margin: 0 0 24px;
  color: #616061;
  font-size: 14px;
}

.login-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #fdeced;
  color: #a30e2e;
  font-size: 14px;
}

.login-form label {
  display: block;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 13px;
  color: #1d1c1d;
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font: inherit;
  font-weight: 400;
  border: 1px solid #bbbabc;
  border-radius: 6px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 155, 209, 0.25);
}

.login-form button {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: #007a5a;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.login-form button:hover { background: #148567; }

/* ---------- channel shell ---------- */

.channel-page {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  min-width: 0;
}

.sidebar__org {
  padding: 0 16px 16px;
  font-size: 18px;
  font-weight: 900;
  color: var(--text-strong);
  border-bottom: 1px solid var(--border);
}

.sidebar__channels { padding: 16px 8px; flex: 1; }

.sidebar__heading {
  padding: 0 8px 8px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
}

.sidebar__channel {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__channel--active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 700;
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.sidebar__avatar,
.msg__avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #4a154b;
  color: #fff;
  font-weight: 700;
  flex: 0 0 auto;
}

.sidebar__avatar { width: 28px; height: 28px; border-radius: 6px; font-size: 13px; }

/* ---------- channel ---------- */

.channel {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-width: 0;
  min-height: 0;
}

.channel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.channel__title {
  margin: 0;
  font-size: 17px;
  color: var(--text-strong);
}

.channel__topic {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.channel__timer {
  text-align: right;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 130px;
}

.channel__timer-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.channel__timer-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.channel__timer.is-urgent { border-color: var(--danger); }
.channel__timer.is-urgent .channel__timer-value { color: var(--danger); }

.channel__messages {
  overflow-y: auto;
  padding: 20px 20px 8px;
  min-height: 0;
}

/* ---------- messages ---------- */

.msg {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  padding: 8px 8px 8px 0;
  border-radius: 6px;
}

.msg:hover { background: var(--hover); }

.msg--system .msg__avatar { background: #2a6b3f; }
.msg--support .msg__avatar { background: #8b3a2f; }
.msg--assistant .msg__avatar { background: #1d4e8f; }
.msg--user .msg__avatar { background: #4a154b; }

.msg__body { min-width: 0; }

.msg__meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.msg__author {
  font-weight: 900;
  color: var(--text-strong);
  font-size: 15px;
}

.msg__tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--border);
  color: var(--text-muted);
}

.msg__time {
  font-size: 12px;
  color: var(--text-muted);
}

.msg__text { overflow-wrap: anywhere; }

.msg__text ul { margin: 4px 0; padding-left: 22px; }
.msg__text li { margin: 2px 0; }
.msg__text strong { color: var(--text-strong); }

.msg__text code {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  color: #e8912d;
}

.msg__text pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  overflow-x: auto;
}

/* Tables carry a lot of Billy's evidence — metric series, queue attributes,
   search hits. They scroll inside their own container so a wide one never
   makes the whole channel scroll sideways. */
.msg__text .table-scroll {
  margin: 8px 0;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: 6px;
}

.msg__text table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.msg__text th,
.msg__text td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--code-border);
  vertical-align: top;
  white-space: nowrap;
}

.msg__text thead th {
  background: var(--code-bg);
  color: var(--text-strong);
  font-weight: 700;
  position: sticky;
  top: 0;
}

.msg__text tbody tr:last-child th,
.msg__text tbody tr:last-child td {
  border-bottom: none;
}

.msg__text tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.msg__text td code {
  white-space: pre;
}

.msg__text pre code {
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
}

/* ---------- typing ---------- */

.channel__typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 20px 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-style: italic;
}

.channel__typing .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}

.channel__typing .dot:nth-child(2) { animation-delay: 0.2s; }
.channel__typing .dot:nth-child(3) { animation-delay: 0.4s; margin-right: 6px; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .channel__typing .dot { animation: none; opacity: 0.6; }
}

/* ---------- composer ---------- */

.channel__composer { padding: 0 20px 20px; }

#composer-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

#composer-form:focus-within { border-color: #5c5e63; }

#composer-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 6px 4px;
  max-height: 180px;
}

#composer-input::placeholder { color: #7c7e82; }

#composer-send {
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: #007a5a;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

#composer-send:hover { background: #148567; }

.channel__locked {
  margin: 0 20px 20px;
  padding: 14px 16px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  background: rgba(236, 178, 46, 0.08);
  color: var(--text);
  font-size: 14px;
}

.channel__locked strong { color: var(--warn); }

@media (max-width: 720px) {
  .channel-page { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
