:root {
  --bg: #eef1ee;
  --surface: #ffffff;
  --surface-2: #f6f8f6;
  --text: #17201c;
  --muted: #5d6b64;
  --border: #d8dfda;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #dcefe8;
  --user-bubble: #d9efe6;
  --danger: #b3261e;
  --ok: #2e7d4f;
  --code-bg: #eef1ef;
  --shadow: 0 1px 2px rgba(20, 30, 25, .08);
  --good: #0ca30c;
  --critical: #d03b3b;
  --spark: #9fb6ac;
  --chip-on: #1f6f5c;
  --chip-on-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #18201c;
    --surface-2: #1d2622;
    --text: #e4ebe7;
    --muted: #93a39b;
    --border: #2a3530;
    --accent: #3fae8e;
    --accent-text: #06140f;
    --accent-soft: #1d3a31;
    --user-bubble: #1f3b32;
    --danger: #f2837a;
    --ok: #6fd39b;
    --code-bg: #111815;
    --shadow: none;
    --spark: #52665d;
    --chip-on: #3fae8e;
    --chip-on-text: #06140f;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1412;
  --surface: #18201c;
  --surface-2: #1d2622;
  --text: #e4ebe7;
  --muted: #93a39b;
  --border: #2a3530;
  --accent: #3fae8e;
  --accent-text: #06140f;
  --accent-soft: #1d3a31;
  --user-bubble: #1f3b32;
  --danger: #f2837a;
  --ok: #6fd39b;
  --code-bg: #111815;
  --shadow: none;
  --spark: #52665d;
  --chip-on: #3fae8e;
  --chip-on-text: #06140f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* ---- login ---------------------------------------------------------- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px 20px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}
.login-logo { border-radius: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 17px;
}
.login-card button[type="submit"] {
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
.login-card button:disabled { opacity: .6; cursor: default; }

input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- app shell -------------------------------------------------------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  background: var(--bg);
}

.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.chat {
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  border-left: 1px solid var(--border);
}

/* ---- Binance status ------------------------------------------------------ */
.side { padding: 16px 12px 16px 16px; overflow-y: auto; }
.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
  position: relative;
}
.side-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bn-state { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.bn-icon {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; line-height: 1; color: #fff; background: var(--muted);
}
.bn-state.ok .bn-icon { background: var(--good); }
.bn-state.down .bn-icon { background: var(--critical); }
.bn-state.down { color: var(--danger); }
.bn-facts { margin: 0; display: grid; gap: 4px; font-size: 13px; }
.bn-facts div { display: flex; justify-content: space-between; gap: 8px; }
.bn-facts dt { color: var(--muted); }
.bn-facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.bn-history-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.bn-history {
  height: 36px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}
.bn-bar {
  flex: 1;
  min-width: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--spark);
  position: relative;
}
.bn-bar.fail { background: var(--critical); height: 100%; }
.bn-bar.last { background: var(--accent); }
.bn-bar.fail.last { background: var(--critical); }
.bn-bar::after { content: ""; position: absolute; inset: -12px -1px 0; } /* bigger hover target */
.bn-tip {
  position: absolute;
  z-index: 2;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
}
.bn-note { margin: 0; font-size: 12px; line-height: 1.4; }

/* ---- filters ---------------------------------------------------------------- */
.filters {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: grid;
  gap: 6px;
}
.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--chip-on); border-color: var(--chip-on); color: var(--chip-on-text); }
.chip .n { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .8; }
.chip.empty-chip { opacity: .55; }
.filter-summary { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.filter-summary .link-button { padding: 0; font-size: 12px; color: var(--accent); }
.filter-empty { margin: 24px 16px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .chat { border-left: 0; }
  .side { padding: 0; overflow: visible; }
  .side-card {
    border-radius: 0; border-width: 0 0 1px; padding: 6px 16px;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  }
  .side-title { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 13px; }
  .bn-state { font-size: 13px; gap: 6px; }
  .bn-icon { width: 16px; height: 16px; font-size: 10px; }
  .bn-facts { display: flex; gap: 10px; font-size: 12px; }
  .bn-facts dt { display: none; }
  .bn-history-head, .bn-history, .bn-tip { display: none !important; }
  .bn-note { flex-basis: 100%; display: none; }
  .bn-state.down ~ .bn-note { display: block; } /* on a phone: only when something is wrong */
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.bar img { border-radius: 8px; }
.bar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.status { font-size: 12px; color: var(--muted); }
.status.ok::before, .status.down::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 5px; vertical-align: 1px;
}
.status.ok::before { background: var(--ok); }
.status.down { color: var(--danger); }
.status.down::before { background: var(--danger); }

.link-button {
  background: none; border: 0; padding: 6px 4px; color: var(--muted); cursor: pointer;
}
.link-button:hover { color: var(--text); }

/* ---- feed -------------------------------------------------------------- */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
}

.day {
  align-self: center;
  margin: 10px 0 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.msg {
  max-width: min(640px, 92%);
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px 6px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-color: transparent;
  border-radius: 14px 14px 4px 14px;
}
.msg .body { white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg code, .msg pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  border-radius: 4px;
}
.msg code { padding: 0 3px; }
.msg pre { padding: 8px; margin: 4px 0; overflow-x: auto; white-space: pre; }
.msg blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--border); }
.msg a { color: var(--accent); }

.cmd {
  background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px;
}

.buttons { display: grid; gap: 6px; margin-top: 8px; }
.buttons .row { display: flex; gap: 6px; }
.buttons button, .buttons a {
  flex: 1;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.buttons button:disabled { opacity: .6; cursor: default; }

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 340px; }

.jump {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 118px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  cursor: pointer;
}

/* ---- composer ---------------------------------------------------------- */
.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.quick {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: none;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.command-row { display: flex; gap: 8px; }
.command-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 16px; /* no zoom-on-focus on iOS */
}
.command-row button {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
