:root {
  color-scheme: light dark;
  font-family: "Manrope", "Inter", system-ui, sans-serif;
  background: #0b1020;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(59, 130, 246, 0.2), transparent 55%),
    radial-gradient(circle at 20% 20%, rgba(16, 185, 129, 0.18), transparent 45%),
    #0b1020;
}

.app {
  width: min(1100px, 100%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1.5rem;
  padding: 2rem 1.5rem;
}

.app__header {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.app__header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2vw + 1rem, 2.5rem);
  letter-spacing: -0.02em;
}

.app__header p {
  margin: 0;
  color: rgba(226, 232, 240, 0.75);
}

.header__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.status {
  background: rgba(148, 163, 184, 0.18);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
}

.status__dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
}

.status[data-state="thinking"] .status__dot {
  background: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  animation: pulse 1.2s ease-in-out infinite;
}

.status[data-state="locked"] .status__dot {
  background: #94a3b8;
  box-shadow: none;
}

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

.chat {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 1.5rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-height: 55vh;
  max-height: 65vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(18px);
}

.chat__container {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 1.5rem;
}

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
}

.login__card {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 1.5rem;
  padding: 2rem;
  width: min(420px, 100%);
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.45);
  display: grid;
  gap: 1.5rem;
  text-align: left;
}

.login__card h2 {
  margin: 0;
  font-size: 1.6rem;
}

.login__card p {
  margin: 0;
  color: rgba(226, 232, 240, 0.75);
}

.login__form {
  display: grid;
  gap: 1rem;
}

.login__form label {
  display: grid;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.login__form input {
  padding: 0.8rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: inherit;
  font-size: 1rem;
}

.login__form input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.6);
  border-color: rgba(59, 130, 246, 0.6);
}

.login__form button {
  border: none;
  padding: 0.85rem 1.6rem;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #f8fafc;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.login__form button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.35);
}

.login__error {
  min-height: 1.2rem;
  color: #f87171;
  font-size: 0.9rem;
}

.chat__bubble {
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  line-height: 1.6;
  max-width: 80%;
  position: relative;
  display: grid;
  gap: 0.75rem;
}

.chat__content {
  display: grid;
  gap: 0.65rem;
}

.chat__bubble--user .chat__content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat__bubble--assistant .chat__content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat__content p {
  margin: 0;
}

.chat__content ul,
.chat__content ol {
  margin: 0;
  padding-left: 1.2rem;
}

.chat__content li {
  margin: 0.2rem 0;
}

.chat__content code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.92em;
  padding: 0.1rem 0.35rem;
  border-radius: 0.4rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.chat__content pre {
  margin: 0;
  padding: 0.75rem;
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow-x: auto;
}

.chat__content pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
}

.chat__content p {
  margin: 0;
}

.chat__content ul,
.chat__content ol {
  margin: 0;
  padding-left: 1.2rem;
}

.chat__content li {
  margin: 0.2rem 0;
}

.chat__content code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.92em;
  padding: 0.1rem 0.35rem;
  border-radius: 0.4rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.chat__content pre {
  margin: 0;
  padding: 0.75rem;
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow-x: auto;
}

.chat__content pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
}

.chat__bubble--assistant {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.35);
  align-self: flex-start;
}

.chat__bubble--user {
  background: rgba(34, 197, 94, 0.2);
  border: 1px solid rgba(34, 197, 94, 0.3);
  align-self: flex-end;
}

.chat__bubble--streaming {
  position: relative;
}

.chat__bubble--streaming::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(148, 163, 184, 0.2);
  pointer-events: none;
}

.chat__meta {
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.7);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chat__password-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 220px;
}

.chat__password-label {
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.7);
}

.chat__password-input {
  border-radius: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: inherit;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

.chat__password-input:focus {
  outline: 2px solid rgba(56, 189, 248, 0.6);
  outline-offset: 2px;
}

.chat__password-error {
  min-height: 1rem;
  font-size: 0.75rem;
  color: #fca5a5;
}

.chat__action {
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat__action--confirm {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #f8fafc;
}

.chat__action--cancel {
  background: rgba(148, 163, 184, 0.2);
  color: inherit;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.chat__action:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.35);
}

.chat__action:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.chat__avatar {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(248, 250, 252, 0.9);
}

.typing {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

.typing span {
  width: 0.4rem;
  height: 0.4rem;
  background: rgba(248, 250, 252, 0.65);
  border-radius: 999px;
  animation: typing 1s infinite ease-in-out;
}

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

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

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

.composer {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
}

.composer input {
  flex: 1;
  padding: 0.9rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: inherit;
  font-size: 1rem;
}

.composer input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.6);
  border-color: rgba(59, 130, 246, 0.6);
}

.composer button {
  border: none;
  padding: 0.9rem 1.6rem;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #f8fafc;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.composer button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.35);
}

.composer button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.helper {
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.65);
}

@media (min-width: 900px) {
  .app__header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  body {
    align-items: stretch;
  }

  .app {
    padding: 1.2rem 1rem 1.5rem;
  }

  .chat {
    min-height: 55vh;
  }

  .chat__bubble {
    max-width: 100%;
  }

  .composer {
    flex-direction: column;
  }

  .composer button {
    width: 100%;
  }
}
