:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: #0f172a;
  --panel-2: #131d33;
  --panel-3: #1a263f;
  --border: #26344f;
  --text: #e8edf7;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --danger: #f87171;
  --ok: #34d399;
  --warning: #fbbf24;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 0, #10233d 0, var(--bg) 60%);
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  background: rgba(15, 23, 42, .96);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.auth-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 15px;
  color: var(--accent);
  background: #0c1628;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
}
.auth-card h1 { margin: 18px 0 4px; font-size: 27px; letter-spacing: -.03em; }
.auth-subtitle { margin: 0 0 24px; color: var(--muted); }
.auth-warning { margin: 18px 0 0; color: var(--muted); font-size: 12px; }
.form-message { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; text-align: center; }

.field-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  color: var(--text);
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 12px;
  appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 19px) 20px, calc(100% - 14px) 20px; background-size: 5px 5px; background-repeat: no-repeat; }

.primary-button {
  min-height: 47px;
  width: 100%;
  margin-top: 16px;
  color: #04121f;
  font-weight: 700;
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  border: 0;
  border-radius: 13px;
}
.primary-button:disabled { opacity: .5; }
.danger-button { color: #fff; background: #991b1b; border: 1px solid #dc2626; border-radius: 12px; }
.danger-outline-button { min-height: 42px; width: 100%; color: var(--danger); background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.45); border-radius: 12px; }
.small-button, .small-danger-button { min-height: 32px; padding: 0 11px; color: var(--text); background: var(--panel-3); border: 1px solid var(--border); border-radius: 9px; }
.small-danger-button { color: var(--danger); background: rgba(248,113,113,.08); border-color: rgba(248,113,113,.35); }
.compact { min-height: 40px; width: auto; margin-top: 0; padding: 0 16px; }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  min-height: calc(59px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 8px;
  background: rgba(7, 11, 20, .96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(15px);
}
.header-copy { min-width: 0; text-align: center; }
.header-copy strong { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-copy small { color: var(--muted); }
.icon-button {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.new-button { color: var(--accent); font-size: 25px; }
.menu-icon, .menu-icon::before, .menu-icon::after {
  position: relative; display: block;
  width: 17px; height: 2px;
  background: currentColor; border-radius: 2px;
}
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }

.main-area {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
}
.setup-panel {
  width: min(680px, 100%);
  margin: auto;
  padding: 28px 20px 60px;
}
.setup-panel h2 { margin: 0 0 8px; }
.form-grid { display: grid; gap: 13px; margin: 20px 0; }
.muted { color: var(--muted); }

#conversation {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
}
.approval-list { padding: 10px 10px 0; }
.approval-card {
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid rgba(251,191,36,.55);
  border-radius: 14px;
  background: rgba(69,26,3,.55);
}
.approval-title { display: flex; align-items: center; gap: 8px; margin: 0; padding: 11px 13px 8px; color: #fde68a; font-weight: 700; }
.approval-body { padding: 0 13px 11px; color: #f8fafc; overflow-wrap: anywhere; }
.approval-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 13px 13px; }
.approval-actions button { flex: 1 1 110px; min-height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-3); color: var(--text); }
.approval-actions .approve { color: #052e16; background: var(--ok); border-color: var(--ok); font-weight: 700; }
.approval-actions .deny { color: #fff; background: #7f1d1d; border-color: #dc2626; }
.approval-resolved { padding: 10px 13px; color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; }

.transcript {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px 20px;
  scroll-behavior: smooth;
}
.turn-block { margin: 0 0 16px; }
.turn-status { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.message {
  max-width: 92%;
  margin: 0 0 10px;
  padding: 11px 13px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  border-radius: 17px;
}
.message.user { margin-left: auto; color: #06131f; background: #67e8f9; border-bottom-right-radius: 6px; }
.message.agent { color: var(--text); background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.event-card { max-width: 94%; margin: 0 0 9px; padding: 9px 11px; color: var(--muted); background: #0b1324; border: 1px solid var(--border); border-radius: 12px; }
.event-card code, .event-card pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.event-card pre { overflow-x: auto; margin: 7px 0 0; white-space: pre-wrap; }
.event-title { color: var(--text); font-weight: 650; }
.status-line { padding: 7px 10px; color: var(--muted); font-size: 12px; }
.typing { color: var(--accent); }

.composer {
  position: sticky;
  bottom: 0;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(7,11,20,0), rgba(7,11,20,.98) 30%);
}
.composer-inner { display: grid; gap: 8px; }
.prompt-input {
  width: 100%;
  min-height: 46px;
  max-height: 180px;
  padding: 12px;
  color: var(--text);
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 15px;
  resize: none;
}
.composer-actions { display: flex; gap: 8px; justify-content: flex-end; }
.thread-meta-row { display: flex; gap: 9px; align-items: center; justify-content: space-between; padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(2,6,23,.72); }
.drawer {
  position: fixed;
  z-index: 40;
  inset: 0 auto 0 0;
  width: min(86vw, 370px);
  padding: calc(14px + env(safe-area-inset-top)) 15px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(0);
}
.drawer[hidden] { display: none; }
.drawer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.drawer-header h2 { margin: 0; font-size: 20px; }
.drawer-section { margin-bottom: 23px; }
.section-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-row h3, .drawer-section h3 { margin: 0; font-size: 14px; color: var(--muted); }
.thread-list { display: grid; gap: 8px; }
.thread-item { width: 100%; padding: 11px; text-align: left; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 13px; }
.thread-item.active { border-color: var(--accent); background: #10243b; }
.thread-item-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.thread-item-preview, .thread-item-time { display: block; color: var(--muted); font-size: 12px; }
.thread-item-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(85px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: min(520px, calc(100vw - 28px));
  padding: 11px 14px;
  color: #fff;
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  overflow-wrap: anywhere;
}

@media (min-width: 750px) {
  .app-shell { grid-template-columns: 350px 1fr; grid-template-rows: auto; }
  .app-header { grid-column: 1 / -1; }
  .menu-button { display: none; }
  .drawer-backdrop { display: none !important; }
  .drawer { position: static; width: auto; transform: none; border-right: 1px solid var(--border); }
  .setup-panel { padding-top: 60px; }
  .message { max-width: 78%; }
  .composer { padding-right: 22px; padding-left: 22px; }
}

