:root {
  --bg0: #071310;
  --bg1: #0c1a17;
  --moss: #1f6f5b;
  --mint: #7dcea0;
  --sand: #e7d7b1;
  --ink: #f3efe4;
  --muted: #a8b5ae;
  --danger: #d9785e;
  --ptt: #2a9d8f;
  --ptt-active: #e9c46a;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(42, 157, 143, 0.35), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 80%, rgba(233, 196, 106, 0.12), transparent 50%),
    linear-gradient(165deg, var(--bg1), var(--bg0) 60%, #050c0a);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from {
    filter: hue-rotate(0deg) saturate(1);
  }
  to {
    filter: hue-rotate(12deg) saturate(1.08);
  }
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 1.25rem 1.25rem calc(1.5rem + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 0.85rem;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 6px rgba(125, 206, 160, 0.15);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.85);
    opacity: 0.7;
  }
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  color: var(--sand);
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.transcript {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.25rem 0.15rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 92%;
  padding: 0.75rem 0.95rem;
  border-radius: 1.1rem;
  line-height: 1.45;
  font-size: 0.98rem;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 280ms ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble.user {
  align-self: flex-end;
  background: rgba(42, 157, 143, 0.28);
  border: 1px solid rgba(125, 206, 160, 0.35);
}

.bubble.assistant {
  align-self: flex-start;
  background: rgba(243, 239, 228, 0.06);
  border: 1px solid rgba(231, 215, 177, 0.18);
}

.bubble.system {
  align-self: center;
  font-size: 0.82rem;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 0.2rem 0.4rem;
}

.text-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.text-row textarea {
  flex: 1;
  border: 1px solid rgba(231, 215, 177, 0.22);
  background: rgba(7, 19, 16, 0.65);
  color: var(--ink);
  border-radius: 1.2rem;
  padding: 0.75rem 1rem;
  font: inherit;
  line-height: 1.45;
  min-height: 10.5rem;
  max-height: 10.5rem;
  resize: none;
  overflow-y: auto;
  outline: none;
}

.text-row textarea:focus {
  border-color: rgba(125, 206, 160, 0.55);
}

.send,
.ghost {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.7rem 1rem;
}

.send {
  background: var(--moss);
  color: var(--ink);
  border-color: rgba(125, 206, 160, 0.4);
}

.ghost {
  background: transparent;
  color: var(--sand);
  border-color: rgba(231, 215, 177, 0.28);
}

.ghost.danger {
  color: var(--danger);
  border-color: rgba(217, 120, 94, 0.4);
}

.ptt-wrap {
  display: grid;
  place-items: center;
  padding: 0.5rem 0 0.25rem;
}

.ptt {
  position: relative;
  width: min(72vw, 220px);
  height: min(72vw, 220px);
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, #3db8a8, var(--ptt) 55%, #1b6f64);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 160ms ease, filter 160ms ease;
}

.ptt:active,
.ptt[aria-pressed="true"] {
  transform: scale(0.96);
  filter: saturate(1.15);
  background: radial-gradient(circle at 35% 30%, #f0d78a, var(--ptt-active) 55%, #b8892d);
  color: #1a1408;
}

.ptt-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(125, 206, 160, 0.35);
  opacity: 0;
  pointer-events: none;
}

.ptt[aria-pressed="true"] .ptt-ring {
  animation: ring 1.1s ease-out infinite;
}

@keyframes ring {
  from {
    transform: scale(0.92);
    opacity: 0.8;
  }
  to {
    transform: scale(1.12);
    opacity: 0;
  }
}

.ptt-label {
  position: relative;
  z-index: 1;
  padding: 0 1rem;
}

dialog {
  border: 1px solid rgba(231, 215, 177, 0.25);
  border-radius: 1.25rem;
  background: #10201c;
  color: var(--ink);
  padding: 0;
  width: min(92vw, 420px);
  max-height: min(90dvh, 720px);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.settings {
  display: grid;
  gap: 0.85rem;
  padding: 1.25rem;
}

.settings h2 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--sand);
}

.settings label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.settings label.check {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.55rem;
}

.settings input[type="url"],
.settings input[type="text"] {
  width: 100%;
  border-radius: 0.65rem;
  border: 1px solid rgba(231, 215, 177, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 0.65rem 0.75rem;
  font: inherit;
}

.settings code {
  font-size: 0.78em;
  color: var(--mint);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.wa-groups-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  max-height: 10rem;
  overflow: auto;
}

.wa-groups-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.55rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(125, 206, 160, 0.18);
  font-size: 0.9rem;
}

.wa-groups-list .wa-group-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wa-groups-list .ghost.danger {
  flex-shrink: 0;
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
}

.wa-groups-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: center;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (prefers-reduced-motion: reduce) {
  .atmosphere,
  .brand-mark,
  .ptt-ring,
  .bubble {
    animation: none;
  }
}

/* Preset Actions */
.preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}

.preset-btn {
  background: rgba(31, 111, 91, 0.4);
  color: var(--sand);
  border: 1px solid rgba(125, 206, 160, 0.3);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.preset-btn:hover {
  background: rgba(31, 111, 91, 0.7);
  border-color: rgba(125, 206, 160, 0.6);
}

/* Cursor live run console */
.live-run {
  margin: 0.5rem 1rem 0.75rem;
  border: 1px solid rgba(125, 206, 160, 0.28);
  border-radius: 0.85rem;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.live-run-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(125, 206, 160, 0.18);
}

.live-run-head h2 {
  margin: 0;
  flex: 1;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--mint);
}

.live-run-status {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sand);
}

.live-run-clear {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
}

.live-run-log {
  max-height: 220px;
  overflow: auto;
  padding: 0.5rem 0.65rem 0.75rem;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

.live-run-line {
  margin: 0.15rem 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.live-run-line[data-type='status'],
.live-run-line[data-type='run_start'],
.live-run-line[data-type='run_end'] {
  color: var(--sand);
}

.live-run-line[data-type='tool'],
.live-run-line[data-type='git'] {
  color: var(--mint);
}

.live-run-line[data-type='thinking'],
.live-run-line[data-type='plan'],
.live-run-line[data-type='assistant'] {
  color: #a8c7fa;
}

.live-run-line[data-type='error'] {
  color: var(--danger);
}

.live-run-line .tag {
  display: inline-block;
  min-width: 4.5rem;
  opacity: 0.75;
  font-size: 0.7rem;
  text-transform: uppercase;
}

/* Console Bubbles */
.bubble.console {
  font-family: monospace;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.4);
  color: #a8c7fa;
  border: 1px solid rgba(168, 199, 250, 0.2);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  white-space: pre-wrap;
}

.bubble.tool {
  font-family: monospace;
  font-size: 0.85rem;
  background: rgba(125, 206, 160, 0.1);
  color: var(--mint);
  border: 1px solid rgba(125, 206, 160, 0.3);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  align-self: flex-start;
}

.bubble.status-update {
  font-size: 0.85rem;
  background: rgba(233, 196, 106, 0.1);
  color: var(--sand);
  border: 1px dashed rgba(233, 196, 106, 0.4);
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  align-self: center;
}

/* ---- Agent History (host-only) ---- */
.history-dialog {
  width: min(96vw, 920px);
  max-height: min(92dvh, 860px);
  border: 1px solid rgba(231, 215, 177, 0.28);
  border-radius: 1.35rem;
  background:
    linear-gradient(165deg, rgba(20, 42, 38, 0.98), rgba(8, 18, 16, 0.98));
  color: var(--ink);
  padding: 0;
  overflow: hidden;
}

.history-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.history-panel {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 0.75rem;
  padding: 1.1rem 1.15rem 1.25rem;
  max-height: min(92dvh, 860px);
}

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.history-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: var(--sand);
}

.history-sub {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.history-chip {
  border: 1px solid rgba(231, 215, 177, 0.22);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.history-chip.is-active {
  color: #10201c;
  background: linear-gradient(120deg, var(--mint), #b8e0c8);
  border-color: transparent;
  font-weight: 600;
}

.history-search {
  width: 100%;
  border-radius: 0.7rem;
  border: 1px solid rgba(231, 215, 177, 0.22);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 0.55rem 0.75rem;
  font: inherit;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 0.75rem;
  min-height: 0;
  height: min(58dvh, 520px);
}

.history-list,
.history-detail {
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(125, 206, 160, 0.18);
  border-radius: 0.9rem;
  background: rgba(0, 0, 0, 0.22);
}

.history-list {
  padding: 0.35rem;
}

.history-item {
  width: 100%;
  text-align: start;
  border: 0;
  border-radius: 0.7rem;
  background: transparent;
  color: inherit;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  display: grid;
  gap: 0.25rem;
}

.history-item:hover,
.history-item.is-selected {
  background: rgba(125, 206, 160, 0.12);
}

.history-item-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.history-badge {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(231, 215, 177, 0.25);
  color: var(--sand);
}

.history-badge[data-platform='cursor'] {
  border-color: rgba(168, 199, 250, 0.45);
  color: #a8c7fa;
}

.history-badge[data-platform='telegram'] {
  border-color: rgba(125, 206, 160, 0.45);
  color: var(--mint);
}

.history-badge[data-platform='voice'] {
  border-color: rgba(233, 196, 106, 0.45);
  color: var(--ptt-active);
}

.history-status {
  margin-inline-start: auto;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
}

.history-status[data-status='running'] {
  color: var(--ptt-active);
}

.history-status[data-status='error'] {
  color: var(--danger);
}

.history-status[data-status='done'] {
  color: var(--mint);
}

.history-item-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
}

.history-item-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.history-item-preview {
  font-size: 0.78rem;
  color: rgba(243, 239, 228, 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-detail {
  padding: 0.85rem;
}

.history-detail-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--sand);
}

.history-detail-meta {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.history-timeline {
  display: grid;
  gap: 0.45rem;
}

.history-event {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.8rem;
}

.history-event-kind {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--mint);
  opacity: 0.85;
}

.history-event-time {
  font-size: 0.68rem;
  color: var(--muted);
}

.history-event-text {
  grid-column: 1 / -1;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(243, 239, 228, 0.9);
}

.history-empty {
  margin: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .history-layout {
    grid-template-columns: 1fr;
    height: min(68dvh, 640px);
  }

  .history-list {
    max-height: 38%;
  }
}
