/* ZAYANDAY — Agent Console
   Design of record: UI-UX/BOT-CONSOLE-SPEC.md (Claude spec)
   Single-user iPhone PWA, native iOS feel. */

:root {
  /* Core palette */
  --bg: #0A0A0C;
  --surface: #16161A;
  --accent: #5B6CFF;

  /* State colors (desaturated ~10%) */
  --st-idle: #7FB88E;
  --st-working: #E8A23D;
  --st-approval: #4C8DFF;
  --st-error: #E8483D;

  /* Text */
  --txt: #F2F2F4;
  --txt2: #8A8A90;
  --txt3: #4A4A50;

  /* Radii */
  --r-sheet: 14px;
  --r-card: 10px;
  --r-pill: 22px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
}

/* ---- Background glow (state-driven) ---- */
.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(48% 30% at 50% 12%, rgba(91,108,255,0) 0%, rgba(91,108,255,0) 100%);
  opacity: 0;
  transition: opacity 250ms ease;
  z-index: 0;
}
.glow.on { opacity: 1; }
.glow.breath { animation: breathe 4s ease-in-out infinite; }
.glow.steady { animation: none; }
@keyframes breathe {
  0%, 100% { opacity: .35; }
  50%      { opacity: .7; }
}
.glow.amber { background: radial-gradient(48% 30% at 50% 12%, rgba(232,162,61,0) 0%, rgba(232,162,61,0.55) 100%); }
.glow.blue  { background: radial-gradient(48% 30% at 50% 12%, rgba(76,141,255,0) 0%, rgba(76,141,255,0.5) 100%); }
.glow.red   { background: radial-gradient(48% 30% at 50% 12%, rgba(232,72,61,0) 0%, rgba(232,72,61,0.4) 100%); opacity: 1; }
.glow.green { background: radial-gradient(48% 30% at 50% 12%, rgba(127,184,142,0) 0%, rgba(127,184,142,0.28) 100%); }

/* ---- Status line ---- */
.statusline {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: linear-gradient(180deg, rgba(10,10,12,0.96) 0%, rgba(10,10,12,0.86) 70%, rgba(10,10,12,0) 100%);
}
.stateline-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--txt);
  padding: 6px 0;
  text-align: left;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: rgba(127,184,142,0.12);
  color: var(--st-idle);
  white-space: nowrap;
  transition: background 250ms ease, color 250ms ease;
}
.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.pill.thinking { background: rgba(232,162,61,0.12); color: var(--st-working); }
.pill.working  { background: rgba(232,162,61,0.16); color: var(--st-working); }
.pill.approval { background: rgba(76,141,255,0.14); color: var(--st-approval); }
.pill.paused   { background: rgba(138,138,144,0.12); color: var(--txt2); }
.pill.error    { background: rgba(232,72,61,0.14); color: var(--st-error); }

.pill.pulse { animation: pillPulse 1.6s ease-in-out infinite; }
@keyframes pillPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.task-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 500;
  color: var(--txt);
  opacity: 0.92;
}
.task-line.shimmer { animation: shimmer 3s ease-in-out infinite; }
@keyframes shimmer { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

.dots-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--txt2);
  font-size: 20px;
  letter-spacing: 2px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

/* ---- Thread ---- */
.thread {
  position: fixed;
  inset: calc(var(--safe-top) + 52px) 0 calc(var(--safe-bottom) + 66px) 0;
  overflow-y: auto;
  padding: 12px 16px 24px;
  -webkit-overflow-scrolling: touch;
  z-index: 1;
}
.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  animation: msgIn 220ms ease both;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 16px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-user { align-items: flex-end; }
.msg-user .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-agent { align-items: flex-start; }
.msg-agent .msg-bubble { background: var(--surface); color: var(--txt); border-bottom-left-radius: 4px; }

/* ---- Tool micro-card ---- */
.tool-card {
  display: flex;
  flex-direction: column;
  margin: 6px 0 6px auto;
  max-width: 92%;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-card);
  overflow: hidden;
  animation: toolIn 150ms ease both;
}
@keyframes toolIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.tool-toggle { color: var(--txt3); font-size: 12px; flex: none; transition: transform 200ms ease; }
.tool-card.open .tool-toggle { transform: rotate(90deg); }
.tool-icon { flex: none; font-size: 14px; width: 20px; text-align: center; }
.tool-label {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--txt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-mask-image: linear-gradient(90deg, #000 70%, transparent 100%);
          mask-image: linear-gradient(90deg, #000 70%, transparent 100%);
}
.tool-status { flex: none; font-size: 12px; color: var(--txt2); }
.tool-status.done { color: var(--st-idle); }
.tool-status.failed { color: var(--st-error); }
.tool-progress { height: 2px; background: transparent; position: relative; overflow: hidden; }
.tool-progress .bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: var(--accent);
}
.tool-card.running .tool-progress .bar { width: 100%; transition: width 3s linear; }
.tool-card.done .tool-progress .bar { width: 100%; background: var(--st-idle); transition: none; }
.tool-card.failed .tool-progress .bar { width: 100%; background: var(--st-error); transition: none; }
.tool-body {
  display: none;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.05);
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--txt2);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 160px;
  overflow-y: auto;
  user-select: text;
}
.tool-card.open .tool-body { display: block; }

/* ---- Footer ---- */
.footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(0deg, rgba(10,10,12,0.96) 0%, rgba(10,10,12,0.86) 70%, rgba(10,10,12,0) 100%);
}
.cost-pill {
  flex: none;
  height: 40px;
  padding: 0 10px;
  border: none;
  border-radius: var(--r-pill);
  background: rgba(255,255,255,0.05);
  color: var(--txt2);
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 200ms ease, transform 200ms ease;
}
.cost-pill.flash { animation: costFlash 300ms ease; }
@keyframes costFlash { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--r-pill);
  border: 1px solid rgba(255,255,255,0.07);
  padding: 6px 12px;
  min-height: 40px;
}
.input-wrap textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--txt);
  font-size: 16px;
  line-height: 1.4;
  max-height: 96px;
  padding: 4px 0;
  user-select: text;
}
.input-wrap textarea::placeholder { color: var(--txt3); }
.input-wrap.disabled { opacity: .45; }

.primary-btn {
  flex: none;
  height: 40px;
  min-width: 72px;
  padding: 0 16px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease, background 250ms ease, box-shadow 250ms ease;
  box-shadow: 0 2px 14px rgba(91,108,255,0.4);
}
.primary-btn:active { transform: scale(0.96); }
.primary-btn.outline { background: transparent; border: 1px solid rgba(255,255,255,0.3); box-shadow: none; color: var(--txt); }
.primary-btn.stop { background: var(--st-error); box-shadow: 0 2px 14px rgba(232,72,61,0.4); }

/* ---- Sheets ---- */
.sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  opacity: 1;
  transition: opacity 250ms ease;
}
.sheet-scrim[hidden] { display: none; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--surface);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  transform: translateY(100%);
  transition: transform 300ms cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 70vh;
  overflow-y: auto;
}
.sheet.show { transform: translateY(0); }
.sheet[hidden] { display: none; }
.sheet-grabber {
  width: 40px; height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.15);
  margin: 4px auto 14px;
}
.sheet-title { font-size: 20px; font-weight: 600; margin: 0 0 10px; }
.sheet-desc { font-size: 15px; color: var(--txt2); line-height: 1.5; margin: 0 0 20px; white-space: pre-wrap; }
.sheet-actions { display: flex; gap: 12px; }
.btn-approve {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-approve:active { transform: scale(0.97); }
.btn-deny {
  flex: none;
  height: 48px;
  padding: 0 20px;
  border: none;
  background: transparent;
  color: var(--txt2);
  font-size: 15px;
  cursor: pointer;
}
.btn-kill {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--st-error);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-kill:active { transform: scale(0.97); }
.task-sheet-body { font-size: 14px; color: var(--txt2); line-height: 1.55; }
.task-sheet-body .k { color: var(--txt3); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

/* ---- Menu (dots) list ---- */
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list li button {
  width: 100%;
  padding: 14px 4px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: var(--txt);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.menu-list li:last-child button { border-bottom: none; }
.menu-list li button.kill { color: var(--st-error); font-weight: 500; }

/* ---- Pause overlay ---- */
.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,12,0.08);
  z-index: 20; /* below footer (30) so controls stay usable */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.pause-overlay[hidden] { display: none; }
.pause-pill {
  background: rgba(22,22,26,0.92);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font-size: 13px;
  color: var(--txt2);
}

/* ---- Empty state (Idle) ---- */
.thread:empty::after {
  content: "Ready when you are.";
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: var(--txt2);
  font-size: 15px;
}

/* ---- Misc ---- */
.hidden { display: none !important; }
::-webkit-scrollbar { width: 0; height: 0; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}