:root {
  --brand-orange: #ed4f16;
  --brand-orange-dark: #c93e0f;
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.72);
  --text-faint: rgba(255, 255, 255, 0.52);
  --surface: rgba(255, 255, 255, 0.07);
  --surface-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.14);
  --danger: #ff6b5e;
  --ok: #3ddc84;
  --warn: #ffb340;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(140deg, #14100d, #2a1a10 55%, #59300e);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.app {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 12px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 12px;
  background: var(--brand-orange);
  color: #fff;
  font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(237, 79, 22, 0.35);
}

.brand-name { font-weight: 800; font-size: 20px; letter-spacing: 0.08em; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--text-dim); font-weight: 600; letter-spacing: 0.04em; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.health { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
.health-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; background: var(--text-faint); }
.health-dot.health-ok { background: var(--ok); box-shadow: 0 0 8px rgba(61, 220, 132, 0.7); }
.health-dot.health-down { background: var(--danger); box-shadow: 0 0 8px rgba(255, 107, 94, 0.7); }
.health-dot.health-unknown { background: var(--warn); }

/* Buttons & inputs */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 700;
  border-radius: 12px; padding: 12px 18px;
  color: var(--text); background: var(--surface-strong);
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--brand-orange); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-orange-dark); }
.btn-secondary { background: var(--surface-strong); border: 1px solid var(--border); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

.input {
  width: 100%;
  font: inherit; color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--brand-orange); box-shadow: 0 0 0 3px rgba(237, 79, 22, 0.25); }

.error {
  background: rgba(255, 107, 94, 0.14);
  border: 1px solid rgba(255, 107, 94, 0.45);
  color: #ffd9d4;
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
  overflow-wrap: anywhere;
}

/* Auth */
.auth-view { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 28px 0 40px; }
.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
.auth-card { max-width: 440px; padding: 28px 24px; }
.auth-title { margin: 0 0 8px; font-size: 26px; font-weight: 800; }
.auth-subtitle { margin: 0 0 20px; color: var(--text-dim); font-size: 15px; line-height: 1.45; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--text-dim); letter-spacing: 0.02em; }
.auth-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.auth-actions .btn { flex: 1 1 140px; }
.auth-note { margin: 2px 0 0; font-size: 12px; color: var(--text-faint); text-align: center; }

/* Chat */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: 16px; }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: 12px;
  padding: 8px 0 16px;
}

.msg { max-width: 88%; padding: 12px 14px; border-radius: 16px; line-height: 1.5; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-user { align-self: flex-end; background: var(--brand-orange); color: #fff; font-weight: 600; border-bottom-right-radius: 6px; }
.msg-assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg-system { align-self: center; background: transparent; color: var(--text-faint); font-size: 13px; text-align: center; }
.msg-meta { display: block; margin-top: 6px; font-size: 11px; font-weight: 500; color: var(--text-faint); }
.msg-user .msg-meta { color: rgba(255, 255, 255, 0.75); }

/* Actions */
.actions-panel {
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.actions-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.actions-title { margin: 0; font-size: 15px; font-weight: 800; letter-spacing: 0.03em; }
.actions-list { display: flex; flex-direction: column; gap: 10px; }

.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.action-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.action-tool { font-weight: 800; font-size: 14px; overflow-wrap: anywhere; }
.action-status {
  font-size: 11px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
  background: var(--surface-strong); border: 1px solid var(--border); color: var(--text-dim);
}
.action-status.status-awaiting_approval { color: #ffd9a8; border-color: rgba(255, 179, 64, 0.55); }
.action-status.status-approved, .action-status.status-executed, .action-status.status-completed, .action-status.status-done { color: #b9f4d2; border-color: rgba(61, 220, 132, 0.5); }
.action-status.status-failed, .action-status.status-error, .action-status.status-rejected { color: #ffd9d4; border-color: rgba(255, 107, 94, 0.55); }

.action-args, .action-result {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 10px;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  max-width: 100%; overflow-x: hidden;
}
.action-label { font-size: 11px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; margin: 10px 0 5px; }
.action-label:first-of-type { margin-top: 0; }
.action-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.action-buttons .btn { flex: 1 1 120px; }
.action-id { font-size: 11px; color: var(--text-faint); overflow-wrap: anywhere; }

/* Composer */
.composer-wrap {
  position: sticky; bottom: 0;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(20, 16, 13, 0), rgba(20, 16, 13, 0.55) 30%);
  display: flex; flex-direction: column; gap: 8px;
}
.composer { display: flex; gap: 8px; align-items: stretch; }
.composer-input { flex: 1 1 auto; min-width: 0; }
.btn-send { flex: 0 0 auto; }
.btn-mic { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; background: var(--surface-strong); border: 1px solid var(--border); padding: 12px 13px; }
.btn-mic.recording { background: var(--brand-orange); border-color: var(--brand-orange); color: #fff; }
.mic-label { font-size: 13px; }
.composer-hint { margin: 0; font-size: 12px; color: var(--text-faint); text-align: center; }
.voice-note { font-size: 13px; color: #ffd9a8; background: rgba(255, 179, 64, 0.12); border: 1px solid rgba(255, 179, 64, 0.4); border-radius: 10px; padding: 8px 11px; }

@media (max-width: 480px) {
  .app { padding: 0 12px; }
  .msg { max-width: 94%; }
  .mic-label { display: none; }
  .btn-mic { padding: 12px 11px; }
  .auth-card { padding: 24px 18px; }
}
