:root {
  --bg-a: #f5f8ff;
  --bg-b: #eef9f2;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --text: #102225;
  --muted: #4b686e;
  --line: #d2e5e0;
  --brand: #0e7490;
  --brand-ink: #f0fcff;
  --danger: #be123c;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #dff7ff 0%, transparent 40%),
    radial-gradient(circle at top right, #dcfce7 0%, transparent 42%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 2.2rem 1rem 2.8rem;
}

.hero {
  margin-bottom: 1.2rem;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.5vw, 2.4rem);
  letter-spacing: -0.03em;
}

.badge {
  display: inline-block;
  margin: 0 0 0.4rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #cffafe;
  color: #115e59;
}

.subtitle {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 2fr 1fr;
}

.admin-view {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
}

.hidden {
  display: none !important;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--surface);
  box-shadow: 0 14px 30px -24px rgba(14, 116, 144, 0.45);
  backdrop-filter: blur(8px);
}

.chat-card {
  display: grid;
  gap: 1rem;
  min-height: 68vh;
}

.chat-log {
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.8rem;
  background: var(--surface-strong);
  overflow-y: auto;
  min-height: 24rem;
  max-height: 58vh;
}

.message {
  margin: 0 0 0.8rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  animation: rise-in 150ms ease-out;
}

.message.user {
  background: #ddf4ff;
  border: 1px solid #bfe8fb;
}

.message.assistant {
  background: #ecfdf3;
  border: 1px solid #c8f5d9;
}

.message-title {
  margin: 0 0 0.4rem;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.4;
  font-size: 0.94rem;
}

.message-meta {
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 0.55rem;
}

label {
  font-size: 0.84rem;
  color: #1d4d55;
}

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

textarea,
select,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

textarea:focus,
select:focus,
input:focus {
  outline: 2px solid rgba(14, 116, 144, 0.25);
  border-color: var(--brand);
}

button {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  background: var(--brand);
  color: var(--brand-ink);
  transition: transform 120ms ease, opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

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

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.controls {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) 110px;
}

.toggles {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.memory-card h2,
.memory-card h3 {
  margin: 0;
}

.muted {
  margin: 0.35rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.memory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

.memory-list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  max-height: 28rem;
  overflow-y: auto;
}

.documents-list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
  max-height: 30rem;
  overflow-y: auto;
}

.document-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.65rem;
  background: #ffffff;
}

.document-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
}

.document-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-word;
}

.document-details {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.document-controls {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: #ecfeff;
  color: #155e75;
  border: 1px solid #bae6fd;
}

.danger-ghost {
  background: transparent;
  border: 1px solid #fecdd3;
  color: var(--danger);
}

.error-text {
  color: var(--danger);
}

.memory-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.55rem 0.65rem;
  background: #ffffff;
}

.memory-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.memory-text {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  line-height: 1.35;
}

.memory-delete {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fbcfe8;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 940px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .admin-view {
    grid-template-columns: 1fr;
  }

  .chat-card {
    min-height: 56vh;
  }
}

@media (max-width: 620px) {
  .controls,
  .toggles {
    grid-template-columns: 1fr;
  }

  .hero-top {
    flex-direction: column;
    align-items: stretch;
  }

  .shell {
    padding: 1rem 0.7rem 1.4rem;
  }
}
