:root {
  --bg: #0c0d12;
  --surface: #15171f;
  --surface-strong: #1d202a;
  --surface-soft: #232631;
  --text: #f7f7fb;
  --muted: #a7a9b7;
  --border: #2a2d38;
  --primary: #8b5cf6;
  --primary-strong: #7c3aed;
  --primary-soft: rgba(139, 92, 246, 0.16);
  --success: #34d399;
  --danger: #fb7185;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
  --header-height: 68px;
  --nav-height: 76px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.app-shell {
  width: 100%;
  min-height: 100dvh;
}

.screen {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 80% -15%, rgba(124, 58, 237, 0.2), transparent 30%),
    var(--bg);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: calc(var(--header-height) + env(safe-area-inset-top));
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 13, 18, 0.9);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #9f7aea, #6d28d9);
  box-shadow: 0 8px 25px rgba(124, 58, 237, 0.32);
}

.brand-mark svg,
.icon-button svg,
.primary-button svg,
.send-button svg,
.nav-item svg,
.project-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.chat-heading h1 {
  overflow: hidden;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.online::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.7);
  content: "";
}

.icon-button,
.back-button {
  display: grid;
  min-width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}

.icon-button:active,
.back-button:active {
  background: var(--surface-soft);
}

.content {
  padding: 22px 16px calc(var(--nav-height) + 32px + env(safe-area-inset-bottom));
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.04em;
}

.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.primary-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.28);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  transition: filter 180ms ease, opacity 180ms ease;
}

.primary-button:active,
.send-button:active {
  filter: brightness(0.9);
}

.primary-button:disabled,
.send-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.chat-list,
.project-list {
  display: grid;
  gap: 10px;
}

.chat-card,
.project-card {
  display: flex;
  width: 100%;
  min-height: 78px;
  align-items: center;
  gap: 13px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: linear-gradient(145deg, rgba(29, 32, 42, 0.92), rgba(21, 23, 31, 0.96));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.chat-card:active,
.project-card:active {
  border-color: #4b426a;
  background: var(--surface-soft);
}

.chat-avatar,
.project-icon {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 15px;
  background: var(--primary-soft);
  color: #c4b5fd;
}

.chat-main,
.project-main {
  min-width: 0;
  flex: 1;
}

.chat-title,
.project-title {
  overflow: hidden;
  margin: 0 0 3px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-meta,
.project-meta {
  display: flex;
  overflow: hidden;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #6b7280;
}

.status-dot.running {
  background: var(--primary);
  box-shadow: 0 0 0 5px rgba(139, 92, 246, 0.13);
  animation: pulse 1.4s infinite;
}

.status-dot.completed {
  background: var(--success);
}

.status-dot.failed,
.status-dot.stopped {
  background: var(--danger);
}

.chevron {
  color: #6d7080;
  font-size: 24px;
}

.empty {
  display: grid;
  min-height: 52vh;
  place-items: center;
  text-align: center;
}

.empty-card {
  max-width: 360px;
  padding: 28px 22px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(21, 23, 31, 0.82);
}

.empty-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 20px;
  background: var(--primary-soft);
  color: #c4b5fd;
}

.empty h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.empty p {
  margin: 0 0 22px;
  color: var(--muted);
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  width: min(100%, 760px);
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  margin: 0 auto;
  align-items: flex-start;
  justify-content: space-around;
  padding: 9px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(15, 16, 22, 0.94);
  backdrop-filter: blur(20px);
}

.nav-item {
  display: flex;
  min-width: 78px;
  min-height: 54px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-soft);
  color: #ddd6fe;
}

.sheet-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.64);
  animation: fade-in 180ms ease;
}

.sheet {
  width: min(100%, 560px);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 12px 18px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: slide-up 220ms ease;
}

.sheet-handle {
  width: 42px;
  height: 5px;
  margin: 0 auto 17px;
  border-radius: 5px;
  background: #414451;
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

.sheet-intro {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: #d7d8e1;
  font-size: 14px;
  font-weight: 600;
}

.field select,
.field textarea,
.login-card input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 16px;
  outline: none;
  background: var(--surface-strong);
  color: var(--text);
}

.field select,
.login-card input {
  padding: 0 14px;
}

.field textarea {
  min-height: 142px;
  padding: 14px;
  resize: vertical;
}

.field select:focus,
.field textarea:focus,
.login-card input:focus,
.composer textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}

.sheet-actions {
  display: flex;
  gap: 10px;
}

.sheet-actions .primary-button {
  flex: 1;
}

.secondary-button,
.stop-button {
  min-height: 48px;
  padding: 0 17px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
}

.stop-button {
  border-color: rgba(251, 113, 133, 0.35);
  color: #fda4af;
}

.chat-screen {
  display: flex;
  height: 100dvh;
  flex-direction: column;
}

.chat-screen .topbar {
  flex: 0 0 auto;
  align-items: flex-end;
  justify-content: flex-start;
}

.chat-heading {
  min-width: 0;
  flex: 1;
}

.chat-project {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 22px 14px 18px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  max-width: 90%;
  flex-direction: column;
  gap: 5px;
}

.message.user {
  align-self: flex-end;
}

.message.assistant,
.message.system {
  align-self: flex-start;
}

.bubble {
  overflow-wrap: anywhere;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 19px 19px 19px 6px;
  background: var(--surface-strong);
  white-space: pre-wrap;
}

.message.user .bubble {
  border-color: rgba(139, 92, 246, 0.5);
  border-radius: 19px 19px 6px;
  background: linear-gradient(145deg, #7c3aed, #6d28d9);
  color: #fff;
}

.message.system .bubble {
  border-color: rgba(251, 113, 133, 0.25);
  background: rgba(127, 29, 29, 0.24);
  color: #fecdd3;
}

.message-time {
  padding: 0 5px;
  color: #777a89;
  font-size: 11px;
}

.message.user .message-time {
  text-align: right;
}

.activity {
  display: flex;
  max-width: 92%;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.typing {
  display: flex;
  gap: 4px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: typing 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 150ms;
}

.typing span:nth-child(3) {
  animation-delay: 300ms;
}

.composer-wrap {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(15, 16, 22, 0.96);
  backdrop-filter: blur(20px);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
}

.composer textarea {
  width: 100%;
  min-height: 50px;
  max-height: 160px;
  flex: 1;
  padding: 13px 14px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 17px;
  outline: none;
  background: var(--surface-strong);
  color: var(--text);
}

.send-button {
  display: grid;
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  color: #fff;
  cursor: pointer;
}

.running-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.login-screen {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(22px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 70% 8%, rgba(124, 58, 237, 0.3), transparent 32%),
    var(--bg);
}

.login-card {
  width: min(100%, 420px);
  padding: 28px 22px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: rgba(21, 23, 31, 0.94);
  box-shadow: var(--shadow);
}

.login-card .brand-mark {
  width: 56px;
  height: 56px;
  margin-bottom: 22px;
  border-radius: 18px;
}

.login-card h1 {
  margin: 0 0 7px;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-card input {
  margin-bottom: 12px;
}

.login-card .primary-button {
  width: 100%;
}

.error-text {
  margin: 9px 0 0 !important;
  color: #fda4af !important;
  font-size: 13px;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 16px;
  bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom));
  left: 16px;
  width: min(calc(100% - 32px), 520px);
  margin: 0 auto;
  padding: 13px 15px;
  border: 1px solid rgba(251, 113, 133, 0.35);
  border-radius: 15px;
  background: #381b26;
  box-shadow: var(--shadow);
  color: #fecdd3;
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes slide-up {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
}

@media (min-width: 680px) {
  .content {
    padding-right: 24px;
    padding-left: 24px;
  }

  .chat-list,
  .project-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
