:root {
  --bg: #f5efe3;
  --bg-accent: #efe2c2;
  --panel: rgba(255, 251, 244, 0.92);
  --panel-strong: #fffaf1;
  --ink: #102a43;
  --muted: #52667a;
  --line: rgba(16, 42, 67, 0.12);
  --primary: #0a6c74;
  --primary-strong: #084f55;
  --accent: #cc5a2f;
  --accent-soft: #ffd5c5;
  --success: #347d56;
  --warning: #b96c00;
  --shadow: 0 24px 80px rgba(35, 52, 70, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(10, 108, 116, 0.22), transparent 30%),
    radial-gradient(circle at top right, rgba(204, 90, 47, 0.18), transparent 24%),
    linear-gradient(180deg, #f9f4ea 0%, var(--bg) 55%, #efe4ce 100%);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

.shell {
  width: min(1360px, calc(100vw - 32px));
  margin: 24px auto 32px;
}

.hero {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(10, 108, 116, 0.92), rgba(8, 79, 85, 0.92)),
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02));
  box-shadow: var(--shadow);
  color: white;
}

.eyebrow,
.meta-label,
.message-role,
.stat-label {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.hero h1 {
  margin: 6px 0 10px;
  max-width: 12ch;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(2.3rem, 4vw, 4.2rem);
  line-height: 0.98;
}

.lede {
  max-width: 64ch;
  color: rgba(255, 255, 255, 0.84);
  font-size: 1rem;
  line-height: 1.55;
}

.hero-stats {
  display: grid;
  gap: 12px;
  align-content: center;
}

.stat-card {
  padding: 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 280px 280px;
  gap: 20px;
  align-items: start;
}

.panel {
  min-height: 180px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

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

.avatar-card {
  display: grid;
  grid-template-columns: 1fr 240px;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.55);
}

.avatar-meta {
  display: grid;
  gap: 6px;
}

.avatar-frame {
  width: 100%;
  max-width: 240px;
  height: auto;
  border-radius: 18px;
  box-shadow: 0 12px 28px rgba(16, 42, 67, 0.16);
  object-fit: cover;
}

.panel h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.5rem;
}

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

.field span {
  font-size: 0.92rem;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  overflow-wrap: anywhere;
}

textarea {
  resize: vertical;
  min-height: 110px;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(10, 108, 116, 0.16);
  border-color: rgba(10, 108, 116, 0.35);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 140ms ease,
    opacity 140ms ease,
    background-color 140ms ease;
}

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

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

.button-primary {
  background: var(--primary);
  color: white;
}

.button-secondary {
  background: #d7e7ea;
  color: var(--primary-strong);
}

.button-accent {
  background: var(--accent);
  color: white;
}

.button-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.status-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.meta-value {
  margin: 6px 0 0;
  font-size: 0.96rem;
}

.badge {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge.neutral {
  background: #dfe7ef;
  color: var(--ink);
}

.badge.connected {
  background: rgba(52, 125, 86, 0.14);
  color: var(--success);
}

.badge.error {
  background: rgba(204, 90, 47, 0.14);
  color: var(--accent);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #f6ead9;
  color: #8d5600;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.35;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.streaming-card {
  margin-bottom: 14px;
  padding: 16px 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, #dceff1, #eef7f8);
  border: 1px solid rgba(10, 108, 116, 0.14);
}

.user-transcript-card {
  background: linear-gradient(135deg, #fff2dd, #fff8ef);
  border-color: rgba(185, 108, 0, 0.16);
}

.streaming-card p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

.conversation-list {
  display: grid;
  gap: 14px;
  overflow-wrap: anywhere;
}

.transcript-history {
  display: grid;
  gap: 12px;
  max-height: 68vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.transcript-entry {
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff6e8, #fffdf7);
  border: 1px solid rgba(185, 108, 0, 0.16);
}

.transcript-entry p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.message-origin {
  display: inline-flex;
  margin-left: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(185, 108, 0, 0.12);
  color: #8d5600;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.message-card {
  padding: 16px 18px;
  border-radius: 22px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.message-card.role-user {
  background: linear-gradient(135deg, #fff3e5, #fffaf2);
}

.message-card.role-assistant {
  background: linear-gradient(135deg, #eff8f8, #f8fcfc);
}

.message-card.role-system {
  background: linear-gradient(135deg, #fff0ed, #fff7f4);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.62;
}

.rtl-text {
  direction: rtl;
  text-align: right;
  font-family: "Geeza Pro", "Noto Naskh Arabic", "Amiri", "Tahoma", sans-serif;
}

.recommendations {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.recommendation-card {
  padding: 14px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid rgba(10, 108, 116, 0.12);
}

.recommendation-card strong {
  display: block;
  margin-bottom: 6px;
}

.event-log {
  display: grid;
  gap: 10px;
  max-height: 68vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.event-row {
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  font-family: "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 0.82rem;
}

.event-row .event-time {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

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

  .hero {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .event-log {
    max-height: 36vh;
  }

  .transcript-history {
    max-height: 36vh;
  }

  .avatar-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100%, calc(100vw - 20px));
    margin: 12px auto 20px;
  }

  .hero,
  .panel {
    border-radius: 22px;
    padding: 18px;
  }

  .hero h1 {
    max-width: none;
    font-size: 2.3rem;
  }

  .panel-header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

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

  .stat-card {
    padding: 12px 14px;
    border-radius: 16px;
  }

  input,
  textarea {
    font-size: 16px;
  }

  #ragPayloadInput {
    max-height: 240px;
  }

  #messageInput {
    min-height: 92px;
  }

  .button-row {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .event-log,
  .transcript-history {
    max-height: 42vh;
  }
}

@media (max-width: 420px) {
  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
