:root {
  --bg: #f4efe6;
  --bg-strong: #e8dcc8;
  --panel: rgba(255, 252, 247, 0.86);
  --panel-strong: #fffaf2;
  --text: #1d1b19;
  --muted: #665d52;
  --line: rgba(88, 63, 36, 0.14);
  --accent: #c15c2d;
  --accent-strong: #8f3b16;
  --accent-soft: rgba(193, 92, 45, 0.12);
  --success: #1f6b46;
  --shadow: 0 24px 80px rgba(61, 40, 18, 0.16);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI Variable", "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(193, 92, 45, 0.18), transparent 28%),
    radial-gradient(circle at right center, rgba(84, 118, 92, 0.16), transparent 30%),
    linear-gradient(180deg, #f7f3ed 0%, var(--bg) 44%, #efe4d1 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 78%);
}

.page-shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.7fr);
  gap: 18px;
  margin-bottom: 22px;
}

.hero-copy,
.hero-card,
.panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 28px 28px 30px;
}

.hero-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(255, 246, 235, 0.96), rgba(255, 250, 242, 0.82));
}

.hero-card p,
.hero-text,
.panel-note,
.knowledge-card p,
.chat-empty,
.message-time {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.04;
}

h1 {
  font-size: clamp(2.5rem, 5vw, 4.75rem);
  max-width: 11ch;
}

h2 {
  font-size: clamp(1.4rem, 2vw, 2rem);
}

.hero-text {
  margin: 18px 0 0;
  max-width: 62ch;
  line-height: 1.65;
  font-size: 1.03rem;
}

#hero-stats {
  display: block;
  margin-top: 14px;
  font-size: 1.1rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  gap: 22px;
  align-items: start;
}

.panel {
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.chat-panel,
.knowledge-panel {
  min-height: 720px;
}

.chat-stage {
  height: 480px;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 250, 242, 0.94), rgba(247, 239, 230, 0.9));
}

.chat-empty {
  padding: 14px;
  line-height: 1.6;
}

.chat-message {
  max-width: 88%;
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.chat-message.user {
  margin-left: auto;
  background: linear-gradient(180deg, #362b24, #241b15);
  color: #fff7f1;
  border-bottom-right-radius: 6px;
}

.chat-message.assistant {
  margin-right: auto;
  background: var(--panel-strong);
  border: 1px solid rgba(88, 63, 36, 0.1);
  border-bottom-left-radius: 6px;
}

.chat-form,
.unlock-form,
.editor-card {
  display: grid;
  gap: 10px;
}

.chat-form {
  margin-top: 16px;
}

textarea,
input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"] {
  width: 100%;
  border: 1px solid rgba(88, 63, 36, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 251, 245, 0.92);
  padding: 12px 13px;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

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

textarea:focus,
input:focus {
  border-color: rgba(193, 92, 45, 0.72);
  box-shadow: 0 0 0 4px rgba(193, 92, 45, 0.12);
}

.chat-actions,
.unlock-row,
.editor-actions,
.search-row,
.knowledge-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-actions {
  justify-content: space-between;
}

.unlock-row input {
  flex: 1;
}

.primary-button,
.ghost-button,
.danger-button {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease, color 150ms ease;
}

.primary-button:hover,
.ghost-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: linear-gradient(180deg, #d56b39, var(--accent-strong));
  color: #fffaf4;
  box-shadow: 0 10px 24px rgba(143, 59, 22, 0.24);
}

.ghost-button {
  background: rgba(255, 250, 242, 0.84);
  color: var(--text);
  border: 1px solid rgba(88, 63, 36, 0.12);
}

.danger-button {
  background: rgba(132, 34, 34, 0.1);
  color: #7e1f1f;
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.knowledge-meta {
  flex-wrap: wrap;
  margin: 16px 0;
}

.stat-pill {
  min-width: 120px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 248, 239, 0.9);
}

.stat-pill span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stat-pill strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.knowledge-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.72fr) minmax(280px, 1fr);
  gap: 18px;
  min-height: 520px;
}

.knowledge-list-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.knowledge-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 2px;
}

.knowledge-card,
.editor-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 251, 245, 0.9);
}

.knowledge-card {
  width: 100%;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.knowledge-card:hover,
.knowledge-card.selected {
  transform: translateY(-1px);
  border-color: rgba(193, 92, 45, 0.36);
  background: rgba(255, 247, 237, 0.96);
}

.knowledge-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.knowledge-card p {
  margin: 8px 0 0;
  font-size: 0.94rem;
  line-height: 1.45;
}

.knowledge-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.tag.inactive {
  background: rgba(102, 93, 82, 0.12);
  color: var(--muted);
}

.editor-card {
  padding: 16px;
  align-content: start;
}

.editor-card label {
  font-size: 13px;
  font-weight: 700;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.panel-note.success {
  color: var(--success);
}

.panel-note.error {
  color: #8f2d2d;
}

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

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

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

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding-top: 16px;
  }

  .hero-copy,
  .hero-card,
  .panel {
    border-radius: 22px;
  }

  .panel {
    padding: 16px;
  }

  .chat-stage {
    height: 380px;
  }

  .chat-actions,
  .unlock-row,
  .editor-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }
}
