:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --bg-card: #161b27;
  --bg-elev: #1c2231;
  --border: #232a3a;
  --border-soft: #1b2130;
  --text: #e8ecf4;
  --text-dim: #98a2b8;
  --text-faint: #6b768c;
  --accent: #22d3ee;
  --accent-2: #3b82f6;
  --accent-soft: rgba(34, 211, 238, 0.12);
  --danger: #f87171;
  --ok: #34d399;
  --user: linear-gradient(135deg, #2563eb, #0ea5e9);
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(34, 211, 238, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

/* ---------- top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 14, 20, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
}

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

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(34, 211, 238, 0.25);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.2px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.status.online .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}

.status.offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.96);
}

/* ---------- chat ---------- */

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 860px;
  margin: 0 auto;
}

.empty {
  max-width: 620px;
  margin: 4vh auto 0;
  text-align: center;
  padding: 0 8px;
}

.empty.hidden {
  display: none;
}

.empty-logo {
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 16px 44px rgba(34, 211, 238, 0.22);
}

.empty h1 {
  font-size: clamp(22px, 6vw, 30px);
  margin: 0 0 8px;
  letter-spacing: -0.5px;
}

.empty p {
  margin: 0 auto 22px;
  max-width: 440px;
  color: var(--text-dim);
  font-size: 14px;
}

.examples {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  text-align: left;
}

@media (min-width: 560px) {
  .examples {
    grid-template-columns: 1fr 1fr;
  }
}

.example {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-card), rgba(22, 27, 39, 0.6));
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}

.example:hover {
  border-color: rgba(34, 211, 238, 0.5);
  background: var(--bg-elev);
}

.example:active {
  transform: scale(0.985);
}

/* ---------- messages ---------- */

.msg {
  display: flex;
  width: 100%;
  animation: rise 0.22s ease both;
}

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

.msg.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(88%, 680px);
  padding: 11px 14px;
  border-radius: 16px;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.24);
}

.msg.assistant .bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.bubble .md > :first-child {
  margin-top: 0;
}

.bubble .md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 8px;
}

.md h1,
.md h2,
.md h3 {
  margin: 14px 0 6px;
  line-height: 1.25;
}

.md h1 {
  font-size: 19px;
}

.md h2 {
  font-size: 17px;
}

.md h3 {
  font-size: 15px;
}

.md ul {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.md li {
  margin: 3px 0;
}

.md a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(34, 211, 238, 0.35);
}

.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
}

.md pre.code {
  margin: 10px 0;
  padding: 12px;
  border-radius: 10px;
  background: #080b12;
  border: 1px solid var(--border);
  overflow-x: auto;
  max-width: 100%;
}

.md pre.code code {
  padding: 0;
  background: none;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
}

.msg.user .md code {
  background: rgba(255, 255, 255, 0.18);
}

/* tools */

.tools {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool {
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12.5px;
  overflow: hidden;
}

.tool summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  color: var(--text-dim);
  list-style: none;
  user-select: none;
}

.tool summary::-webkit-details-marker {
  display: none;
}

.tool summary .tname {
  font-family: var(--mono);
  color: var(--text);
}

.tool summary .tstate {
  margin-left: auto;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-faint);
  white-space: nowrap;
}

.tool summary .tstate.completed {
  color: var(--ok);
}

.tool summary .tstate.error {
  color: var(--danger);
}

.tool summary .tstate.running {
  color: var(--accent);
}

.tool pre {
  margin: 0;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 240px;
  overflow: auto;
}

/* typing */

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: blink 1.2s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.msg-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 6px;
}

/* ---------- permissions ---------- */

.permission-host {
  flex: none;
  padding: 0 14px 8px;
}

.perm-card {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(250, 204, 21, 0.35);
  background: linear-gradient(180deg, rgba(250, 204, 21, 0.09), rgba(250, 204, 21, 0.03));
}

.perm-title {
  font-size: 13px;
  font-weight: 600;
  color: #facc15;
  margin-bottom: 4px;
}

.perm-body {
  font-size: 13px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.perm-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
}

.perm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.perm-actions button {
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
  font-size: 13px;
}

.perm-actions button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #06121a;
  font-weight: 600;
}

.perm-actions button.danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.4);
}

/* ---------- composer ---------- */

.composer {
  flex: none;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
  background: rgba(11, 14, 20, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  max-width: 860px;
  margin: 0 auto;
}

#input {
  flex: 1 1 auto;
  resize: none;
  min-height: 46px;
  max-height: 150px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 15px;
  line-height: 1.4;
}

#input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

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

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: none;
  color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.hint {
  max-width: 860px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  animation: slideUp 0.24s ease both;
  padding-bottom: env(safe-area-inset-bottom);
}

@keyframes slideUp {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.sheet-head h2 {
  margin: 0;
  font-size: 16px;
}

.sheet-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.text-btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.text-btn:hover {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.4);
}

.projects {
  overflow-y: auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.project {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.project-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-name {
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.badge {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.badge.bot {
  background: rgba(168, 85, 247, 0.14);
  color: #c084fc;
}

.badge.other {
  background: var(--bg-elev);
  color: var(--text-dim);
}

.project-meta {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.project-actions a,
.project-actions button {
  font-size: 12.5px;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.project-actions a:hover,
.project-actions button:hover {
  border-color: rgba(34, 211, 238, 0.45);
}

.empty-projects {
  padding: 30px 10px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 520px);
  padding: 10px 15px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.toast[hidden] {
  display: none;
}

/* ---------- login ---------- */

.login {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 400px at 50% 0%, rgba(34, 211, 238, 0.12), transparent 65%),
    var(--bg);
}

.login[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px calc(24px + env(safe-area-inset-bottom));
  border-radius: 22px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-card), var(--bg-soft));
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 36px rgba(34, 211, 238, 0.24);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: -0.5px;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.login-card input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  border-color: rgba(34, 211, 238, 0.6);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.login-btn {
  width: 100%;
  height: 50px;
  margin-top: 12px;
  border: none;
  border-radius: 13px;
  color: #06121a;
  font-size: 15px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.login-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.login-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.login-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

.login-error[hidden] {
  display: none;
}

/* ---------- misc ---------- */

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