:root {
  --bg: #f6efe6;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-strong: #fffaf4;
  --line: rgba(83, 55, 30, 0.12);
  --line-strong: rgba(83, 55, 30, 0.24);
  --ink: #2c2218;
  --muted: #75624d;
  --accent: #155e63;
  --accent-2: #c46c2c;
  --accent-soft: rgba(21, 94, 99, 0.10);
  --shadow: 0 24px 60px rgba(69, 43, 15, 0.10);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(196, 108, 44, 0.12), transparent 32%),
    radial-gradient(circle at top left, rgba(21, 94, 99, 0.15), transparent 34%),
    linear-gradient(180deg, #f7f2eb 0%, #f3ebe0 100%);
}

.page-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.hero {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(255, 250, 244, 0.96), rgba(249, 241, 231, 0.90));
  box-shadow: var(--shadow);
}

.eyebrow,
.section-label {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--accent);
}

.hero h1 {
  margin: 0;
  font-size: clamp(32px, 4vw, 52px);
  line-height: 1.08;
}

.hero-copy {
  margin: 14px 0 0;
  color: var(--muted);
  max-width: 720px;
  line-height: 1.7;
}

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

.stat-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.66);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 28px;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 1.35fr 0.95fr;
  gap: 18px;
  margin-top: 18px;
}

.chat-panel,
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.chat-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: 760px;
}

.panel-head,
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.panel-head h2,
.card-head h3 {
  margin: 0;
  font-size: 26px;
}

.avatar-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar,
.avatar-fallback {
  width: 88px;
  height: 88px;
  border-radius: 26px;
  object-fit: cover;
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(21, 94, 99, 0.15), rgba(196, 108, 44, 0.15));
}

.avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.hidden {
  display: none !important;
}

.greeting {
  margin: 14px 0 0;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.7;
}

.banner {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(196, 108, 44, 0.10);
  border: 1px solid rgba(196, 108, 44, 0.22);
  color: #7b471f;
}

.messages {
  margin-top: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.message {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.message[data-role="user"] {
  background: linear-gradient(135deg, rgba(21, 94, 99, 0.12), rgba(21, 94, 99, 0.05));
}

.message-role {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.message-body {
  margin-top: 10px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.message-sources {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}

.chat-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

textarea,
input[type="text"],
input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
}

textarea:focus,
input[type="text"]:focus,
input[type="file"]:focus {
  outline: 2px solid rgba(21, 94, 99, 0.20);
  border-color: var(--accent);
}

.chat-actions {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.helper-text {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  padding: 20px;
}

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

.primary-button,
.secondary-button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #1c7f86);
  color: white;
  box-shadow: 0 14px 28px rgba(21, 94, 99, 0.24);
}

.secondary-button {
  background: linear-gradient(135deg, var(--accent-2), #d98949);
  color: white;
  box-shadow: 0 14px 28px rgba(196, 108, 44, 0.24);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  opacity: 0.96;
}

.mini-summary,
.knowledge-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.knowledge-item {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.knowledge-item strong {
  display: block;
  margin-bottom: 6px;
}

.knowledge-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.knowledge-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}

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

  .chat-panel {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 16px 14px 28px;
  }

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

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

  .chat-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
