:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --card: #1c1d22;
  --card-2: #16171a;
  --border: #26282d;
  --text: #f4f4f5;
  --muted: #9aa0a6;
  --accent: #f59e0b;
  --accent-fg: #1a1306;
  --me: #2563eb;
  --me-fg: #f0f6ff;
  --ok: #22c55e;
  --danger: #ef4444;
  --header-h: 52px;
  --compose-h: 72px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  height: 100%;
  overflow: hidden;        /* page itself doesn't scroll; thread does */
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---------- Header ---------- */
header {
  flex: 0 0 auto;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-h);
}
header h1 { margin: 0; font-size: 17px; font-weight: 600; display: flex; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 8px; }
.dot.ok { background: var(--ok); }
.btn-mini { background: transparent; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; }

/* ---------- Install banner (above thread, optional) ---------- */
.install-banner {
  background: var(--accent);
  color: var(--accent-fg);
  padding: 10px 14px;
  margin: 8px 12px 0 12px;
  border-radius: 10px;
  font-size: 14px;
}
.install-banner b { font-weight: 700; }
.install-banner button {
  background: transparent;
  border: 0;
  color: var(--accent-fg);
  float: right;
  font-size: 18px;
  cursor: pointer;
}

/* ---------- Thread (scrollable, fills space) ---------- */
#thread {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 16px 12px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 40px 24px;
  font-size: 15px;
  max-width: 320px;
}

/* ---------- Date dividers ---------- */
.day {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 4px 0;
}

/* ---------- Bubbles ---------- */
.bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 18px;
  border: 1px solid var(--border);
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
  position: relative;
  font-size: 15.5px;
}
.bubble.from-claude {
  align-self: flex-start;
  background: var(--card);
  border-bottom-left-radius: 6px;
}
.bubble.from-me {
  align-self: flex-end;
  background: var(--me);
  color: var(--me-fg);
  border-color: transparent;
  border-bottom-right-radius: 6px;
}
.bubble .bubble-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.bubble.from-me .bubble-title { color: rgba(255,255,255,0.6); }
.bubble .bubble-time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.bubble.from-me .bubble-time { color: rgba(255,255,255,0.55); }

/* Bubble accent border for ask/options (decision wanted) */
.bubble.needs-action { border-color: var(--accent); }

/* Brief flash when a deep link focuses a bubble (WhatsApp wake-up taps) */
.bubble.flash {
  animation: flash-highlight 1.6s ease-out;
}
@keyframes flash-highlight {
  0%   { box-shadow: 0 0 0 0 var(--accent); }
  20%  { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* Inline options inside a Claude bubble */
.bubble .options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.bubble .options button {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 15px;
  min-height: 44px;
  cursor: pointer;
  text-align: left;
}
.bubble .options button.tool-allow { background: var(--ok); color: #0a1f0d; }
.bubble .options button.tool-deny { background: var(--danger); color: #fff; }
.bubble .options button:active { transform: scale(0.98); }
.bubble .options button.chosen {
  background: transparent;
  color: var(--ok);
  border: 1px solid var(--ok);
  font-weight: 700;
}
.bubble .options button.faded {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}
.bubble .replied-tag {
  display: inline-block;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ok);
}

/* Free-text reply row (rendered only for asks WITHOUT preset options) */
.bubble .reply-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: stretch;
}
.bubble .reply-row textarea {
  flex: 1;
  background: #0e0f12;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 15px;
  min-height: 44px;
  max-height: 140px;
  resize: vertical;
  font-family: inherit;
}
.bubble .reply-row .send,
.bubble .reply-row .mic {
  width: 44px;
  min-width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 0;
  font-size: 18px;
  cursor: pointer;
}
.bubble .reply-row .send { background: var(--accent); color: var(--accent-fg); }
.bubble .reply-row .mic { background: #2a2c33; color: var(--text); }

/* ---------- Compose bar (fixed at bottom) ---------- */
.compose {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 12px;
}
.compose textarea {
  flex: 1;
  background: #0e0f12;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 16px;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  font-family: inherit;
  line-height: 1.35;
}
.compose .send,
.compose .mic {
  width: 44px;
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  font-size: 18px;
  cursor: pointer;
}
.compose .send { background: var(--accent); color: var(--accent-fg); }
.compose .mic { background: #2a2c33; color: var(--text); }
.compose .mic.rec { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--compose-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; }

/* ---------- Scroll-to-bottom FAB (shown when user scrolled up) ---------- */
.jump-bottom {
  position: fixed;
  right: 16px;
  bottom: calc(var(--compose-h) + 20px + env(safe-area-inset-bottom));
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 20;
}
.jump-bottom.show { opacity: 1; pointer-events: auto; }

/* ---------- Lock screen ---------- */
.lock {
  position: fixed;
  inset: 0;
  background: rgba(11,11,12,0.96);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lock-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
}
.lock-card h2 { margin: 0 0 6px 0; }
.lock-card p { color: var(--muted); font-size: 14px; margin: 0 0 16px 0; }
.lock-card input {
  width: 100%;
  background: #0e0f12;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 22px;
  letter-spacing: 6px;
  text-align: center;
  margin-bottom: 12px;
}
.lock-card button {
  width: 100%;
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: 10px;
  padding: 14px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
.pin-err {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}
/* Email/password are normal text fields — undo the PIN-style centering. */
#login-email, #login-password {
  font-size: 16px;
  letter-spacing: normal;
  text-align: left;
}
/* 2FA code keeps the centered numeric look (inherits the base input rule). */
#login-mfa-row { margin-bottom: 0; }
.header-actions { display: flex; gap: 8px; align-items: center; }
