* {
  box-sizing: border-box;
}

:root {
  --bg: #050505;
  --surface: #111111;
  --surface-2: #181818;
  --surface-3: #220d10;
  --line: rgba(255, 255, 255, 0.1);
  --line-hot: rgba(228, 18, 35, 0.48);
  --text: #ffffff;
  --muted: #b7b7b7;
  --muted-2: #7f7f7f;
  --crimson: #e41223;
  --crimson-dark: #8b000b;
  --crimson-soft: rgba(228, 18, 35, 0.16);
  --green: #45d483;
  --yellow: #ffbf4d;
  --red: #ff5c6b;
  --radius: 8px;
}

html {
  min-width: 320px;
  background: var(--bg);
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(228, 18, 35, 0.14), transparent 36%),
    linear-gradient(135deg, #030303 0%, #111111 50%, #050505 100%);
}

button,
input {
  font: inherit;
}

.chat-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    calc(clamp(12px, 3vw, 28px) + env(safe-area-inset-top))
    calc(clamp(12px, 3vw, 28px) + env(safe-area-inset-right))
    calc(clamp(12px, 3vw, 28px) + env(safe-area-inset-bottom))
    calc(clamp(12px, 3vw, 28px) + env(safe-area-inset-left));
}

.chat-app {
  width: min(1040px, 100%);
  height: min(840px, calc(100vh - 24px));
  min-height: 620px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018)),
    var(--surface);
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.62),
    0 0 90px rgba(228, 18, 35, 0.08);
}

.install-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px clamp(16px, 3vw, 24px);
  border-bottom: 1px solid var(--line);
  background: rgba(228, 18, 35, 0.12);
}

.install-banner[hidden] {
  display: none;
}

.install-banner strong,
.install-banner span {
  display: block;
}

.install-banner span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.install-banner button,
.ghost-btn {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: white;
  background: linear-gradient(145deg, #ff2637, var(--crimson-dark));
  padding: 0 14px;
  cursor: pointer;
  font-weight: 900;
}

.install-banner .ghost-btn {
  background: rgba(255, 255, 255, 0.06);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(16px, 3vw, 24px);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #ff2637, var(--crimson-dark));
  font-weight: 950;
  box-shadow: 0 0 34px rgba(228, 18, 35, 0.42);
}

.brand-name {
  margin: 0;
  color: #ff737d;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

.connection-badge {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.24);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--yellow);
  box-shadow: 0 0 14px rgba(255, 191, 77, 0.55);
}

.connection-badge.online .connection-dot {
  background: var(--green);
  box-shadow: 0 0 14px rgba(69, 212, 131, 0.55);
}

.connection-badge.offline .connection-dot {
  background: var(--red);
  box-shadow: 0 0 14px rgba(255, 92, 107, 0.58);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 14px clamp(16px, 3vw, 24px);
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.14);
}

.quick-action {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: white;
  background: #0b0b0b;
  cursor: pointer;
  font-size: 13px;
  font-weight: 820;
  line-height: 1.2;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.quick-action:hover:not(:disabled) {
  border-color: var(--line-hot);
  background: var(--crimson-soft);
  transform: translateY(-1px);
}

.quick-action:focus-visible,
.connection-badge:focus-visible,
.composer button:focus-visible,
.install-banner button:focus-visible,
.app-nav a:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.38);
  outline-offset: 3px;
}

.quick-action:disabled,
.composer button:disabled,
.composer input:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.message-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: clamp(16px, 3vw, 24px);
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: min(760px, 92%);
}

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

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: white;
  background: #0a0a0a;
  font-size: 11px;
  font-weight: 950;
}

.message-row.bot .avatar {
  background: linear-gradient(145deg, #ff2637, var(--crimson-dark));
  border-color: rgba(255, 255, 255, 0.18);
}

.message-bubble {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--surface-2);
}

.message-row.user .message-bubble {
  border-color: var(--line-hot);
  background: linear-gradient(180deg, rgba(228, 18, 35, 0.2), rgba(228, 18, 35, 0.1));
}

.message-row.bot .message-bubble {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.01)),
    var(--surface-2);
}

.message-label {
  display: block;
  margin-bottom: 6px;
  color: #ff737d;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.message-bubble p {
  margin: 0;
  color: #f4f4f4;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 5px 0 2px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #ff737d;
  animation: blink 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.14s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.28s;
}

.status-line {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 8px clamp(16px, 3vw, 24px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
  font-size: 13px;
  font-weight: 760;
}

.status-line[data-state="busy"] {
  color: white;
  background: var(--crimson-soft);
}

.status-line[data-state="error"] {
  color: white;
  background: rgba(255, 92, 107, 0.14);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px clamp(16px, 3vw, 24px) clamp(16px, 3vw, 24px);
  background: rgba(0, 0, 0, 0.2);
}

.composer input {
  min-height: 50px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  color: white;
  background: #090909;
  outline: none;
  font-size: 16px;
}

.composer input:focus {
  border-color: var(--line-hot);
  box-shadow: 0 0 0 3px rgba(228, 18, 35, 0.14);
}

.composer button {
  min-width: 112px;
  min-height: 50px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  color: white;
  background: linear-gradient(145deg, #ff2637, var(--crimson-dark));
  cursor: pointer;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: 0 14px 34px rgba(228, 18, 35, 0.18);
}

.composer button:hover:not(:disabled) {
  filter: saturate(1.08);
}

.app-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px clamp(16px, 3vw, 24px);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
}

.app-nav a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
  touch-action: manipulation;
}

.app-nav a.active,
.app-nav a:active {
  color: white;
  background: var(--crimson-soft);
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 14px;
  padding: 9px clamp(16px, 3vw, 24px);
  color: var(--muted-2);
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.35;
}

.offline-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.offline-card {
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.58);
}

.offline-card .brand-mark {
  margin: 0 auto 18px;
}

.offline-card p {
  color: var(--muted);
  line-height: 1.55;
}

.brand-footer {
  margin-top: 24px;
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

@media (max-width: 860px) {
  .chat-app {
    height: calc(100dvh - 24px);
    min-height: 560px;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .quick-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .install-banner {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .chat-shell {
    padding: 0;
  }

  .chat-app {
    height: 100dvh;
    min-height: 100dvh;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .message-row {
    max-width: 100%;
  }

  .avatar {
    display: none;
  }

  .composer {
    grid-template-columns: 1fr;
    padding-bottom: 12px;
  }

  .composer button {
    width: 100%;
  }

  .app-nav {
    position: sticky;
    bottom: 0;
    z-index: 5;
  }

  .app-footer {
    display: grid;
  }
}

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