/* ── Reset & variables ───────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0e1420;
  --bg-surface:  #161d2e;
  --bg-user:     #1a3a5c;
  --bg-asst:     #1a2235;
  --bg-error:    #3d1515;
  --accent:      #00d4aa;
  --text:        #e0e6f0;
  --text-dim:    #6b7a99;
  --border:      #252d42;
  --radius:      14px;
  --radius-sm:   8px;
  /* respect iOS/Android notch/home-bar */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  /* prevent pull-to-refresh interfering with chat scroll */
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Screen wrapper ──────────────────────────────────────────────────────── */

.screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;   /* dynamic viewport height — handles mobile browser chrome */
}

/* ── Setup screen ────────────────────────────────────────────────────────── */

#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.setup-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.setup-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.setup-box input {
  padding: 0.85rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: monospace;
  outline: none;
  transition: border-color 0.15s;
}

.setup-box input:focus {
  border-color: var(--accent);
}

.setup-box button {
  padding: 0.85rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.setup-box button:active { opacity: 0.8; }

/* ── Chat screen layout (3-row grid) ─────────────────────────────────────── */

#chat-screen {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  padding-top: calc(0.7rem + var(--safe-top));
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: var(--accent);
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.agent-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: monospace;
}

/* ── Status dot ──────────────────────────────────────────────────────────── */

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
  flex-shrink: 0;
}

.status-connected    { background: #22c55e; }
.status-connecting   { background: #f59e0b; animation: pulse 1.2s ease-in-out infinite; }
.status-disconnected { background: #ef4444; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Message list ────────────────────────────────────────────────────────── */

#messages {
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  -webkit-overflow-scrolling: touch;
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */

.msg {
  max-width: 86%;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-size: 0.95rem;
}

.msg-user {
  align-self: flex-end;
  background: var(--bg-user);
  border-bottom-right-radius: 3px;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--bg-asst);
  border-bottom-left-radius: 3px;
}

/* blinking cursor while streaming */
.msg-assistant.streaming::after {
  content: '▋';
  color: var(--accent);
  margin-left: 1px;
  animation: blink 0.75s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.msg-system {
  align-self: center;
  background: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.15rem 0;
  max-width: 100%;
  text-align: center;
}

.msg-error {
  align-self: stretch;
  max-width: 100%;
  background: var(--bg-error);
  color: #f87171;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

/* ── Approval dialog ─────────────────────────────────────────────────────── */

#approval-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.approval-box {
  width: 100%;
  background: var(--bg-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--border);
  padding: 1.25rem 1rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.approval-box h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f59e0b;
}

#approval-preview {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--text-dim);
  overflow-x: auto;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre;
}

.approval-buttons {
  display: flex;
  gap: 0.6rem;
}

.approval-buttons button {
  flex: 1;
  padding: 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-approve { background: #22c55e; color: #000; }
.btn-deny    { background: #374151; color: var(--text); }

/* ── Footer / input row ──────────────────────────────────────────────────── */

footer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  padding-bottom: calc(0.6rem + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 0.6rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  overflow-y: auto;
  transition: border-color 0.15s;
}

#input:focus {
  border-color: var(--accent);
}

#input::placeholder {
  color: var(--text-dim);
}

#send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #000;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
}

#send-btn:active {
  opacity: 0.75;
  transform: scale(0.93);
}

/* ── Hover states (desktop/mouse) ────────────────────────────────────────── */

@media (hover: hover) {
  .setup-box button:hover  { opacity: 0.88; }
  #send-btn:hover          { opacity: 0.88; }
  .btn-approve:hover       { opacity: 0.88; }
  .btn-deny:hover          { opacity: 0.88; }
}
