:root {
  --ink: #211b17;
  --muted: #63564a;
  --paper: #f7f1e5;
  --paper-strong: #fffaf1;
  --paper-deep: #f2e8d4;
  --sand: #eadcc2;
  --oak: #6f4c33;
  --oak-deep: #43291e;
  --oak-soft: #9f7d5f;
  --olive: #5c6845;
  --line: rgba(67, 41, 30, 0.14);
  --line-strong: rgba(67, 41, 30, 0.22);
  --shadow: 0 18px 60px rgba(56, 36, 24, 0.15);
  --shadow-soft: 0 10px 30px rgba(56, 36, 24, 0.08);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(173, 144, 97, 0.28), transparent 28%),
    radial-gradient(circle at 85% 12%, rgba(92, 104, 69, 0.12), transparent 18%),
    radial-gradient(circle at bottom right, rgba(92, 104, 69, 0.2), transparent 24%),
    linear-gradient(180deg, #f2e4ca 0%, #f8f1e3 42%, #f0dfc0 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(67, 41, 30, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(67, 41, 30, 0.02) 1px, transparent 1px);
  background-size: 24px 24px;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.24), transparent 16%),
    radial-gradient(circle at 82% 76%, rgba(255, 255, 255, 0.18), transparent 14%);
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: 18px;
  padding: 18px;
  max-width: 1560px;
  margin: 0 auto;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar,
.main-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar {
  position: sticky;
  top: 18px;
  align-self: start;
  min-height: calc(100vh - 36px);
}

.main-column {
  min-width: 0;
  min-height: calc(100vh - 36px);
}

.brand-card,
.panel,
.hero-card,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.96), rgba(249, 241, 227, 0.88));
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.brand-card,
.panel,
.hero-card {
  padding: 20px;
}

.brand-card,
.hero-card {
  position: relative;
  overflow: hidden;
}

.brand-card::before,
.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at top right, rgba(111, 76, 51, 0.12), transparent 28%),
    linear-gradient(140deg, rgba(255, 255, 255, 0.18), transparent 35%);
}

.brand-card h1,
.hero-card h2,
.panel h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  letter-spacing: -0.02em;
}

.brand-card h1 {
  margin-top: 0;
  font-size: clamp(1.8rem, 3.4vw, 2.75rem);
  line-height: 1.02;
  max-width: 10ch;
}

.brand-header {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.brand-logo {
  display: block;
  width: 82px;
  min-width: 82px;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(67, 41, 30, 0.16));
}

.brand-signoff {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: center;
}

.brand-name {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--oak-deep);
}

.eyebrow {
  margin: 0;
  font-size: 0.77rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--olive);
  font-weight: 700;
}

.brand-eyebrow {
  margin-bottom: 10px;
  color: var(--oak);
}

.brand-credit {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.lead,
.panel-head p,
#profileSummary,
.helper-text,
.library-meta,
.status-chip {
  color: var(--muted);
}

.lead {
  margin: 10px 0 0;
  line-height: 1.55;
}

.panel-head {
  margin-bottom: 12px;
}

.panel {
  box-shadow: var(--shadow-soft);
}

.sidebar .panel:last-of-type {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.panel-head p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.mode-grid {
  display: grid;
  gap: 10px;
}

.mode-button {
  width: 100%;
  position: relative;
  padding: 16px 16px 16px 18px;
  border: 1px solid rgba(67, 41, 30, 0.12);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.98), rgba(241, 230, 207, 0.82));
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

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

.mode-button:hover {
  border-color: rgba(67, 41, 30, 0.22);
  box-shadow: 0 12px 24px rgba(56, 36, 24, 0.08);
}

.mode-button strong,
.library-card strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 6px;
}

.mode-button span,
.library-card span {
  display: block;
  line-height: 1.5;
  color: var(--muted);
}

.mode-button.active {
  border-color: rgba(92, 104, 69, 0.5);
  background: linear-gradient(180deg, rgba(92, 104, 69, 0.18), rgba(255, 250, 241, 0.94));
  box-shadow: inset 0 0 0 1px rgba(92, 104, 69, 0.16), 0 12px 26px rgba(56, 36, 24, 0.08);
}

.mode-button.active::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 14px;
  bottom: 14px;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--olive), rgba(92, 104, 69, 0.3));
}

.field,
.composer-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field select {
  min-height: 50px;
}

.source-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(92, 104, 69, 0.12);
  color: var(--oak-deep);
  font-size: 0.92rem;
  font-weight: 700;
}

.field span,
.composer-field span {
  font-size: 0.9rem;
  font-weight: 600;
}

select,
textarea {
  width: 100%;
  border: 1px solid rgba(67, 41, 30, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 250, 241, 0.96);
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  box-shadow: inset 0 1px 2px rgba(67, 41, 30, 0.04);
}

textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.6;
}

.ghost-button,
.primary-button,
.starter {
  border: none;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease;
}

.ghost-button {
  padding: 12px 16px;
  background: rgba(67, 41, 30, 0.08);
  color: var(--oak-deep);
  box-shadow: inset 0 0 0 1px rgba(67, 41, 30, 0.08);
}

.sidebar #newConversationButton {
  margin-top: auto;
}

.primary-button {
  padding: 13px 20px;
  background: linear-gradient(135deg, var(--oak), var(--oak-deep));
  color: #fff8ef;
  box-shadow: 0 12px 22px rgba(67, 41, 30, 0.2);
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-drop {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px dashed rgba(67, 41, 30, 0.26);
  border-radius: var(--radius-md);
  background: rgba(234, 220, 194, 0.4);
  cursor: pointer;
}

.upload-drop input {
  width: 100%;
}

.upload-drop small {
  color: var(--muted);
  line-height: 1.45;
}

.status-chip {
  display: inline-flex;
  align-self: flex-start;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(92, 104, 69, 0.1);
  font-size: 0.9rem;
}

.library-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.library-card {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(67, 41, 30, 0.08);
}

.library-meta {
  font-size: 0.9rem;
  line-height: 1.55;
  margin-top: 8px;
}

.file-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.file-tag {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(67, 41, 30, 0.08);
  font-size: 0.85rem;
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  background: linear-gradient(135deg, rgba(255, 250, 241, 0.98), rgba(242, 232, 212, 0.88));
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-select {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 250, 241, 0.72);
  border: 1px solid rgba(67, 41, 30, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.hero-select span {
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--olive);
  font-weight: 700;
}

.hero-select select {
  min-width: 0;
  padding: 11px 12px;
}

.badge {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(92, 104, 69, 0.14);
  color: var(--oak-deep);
  font-size: 0.88rem;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(92, 104, 69, 0.08);
}

.chat-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  flex: 1;
  background:
    linear-gradient(180deg, rgba(255, 250, 241, 0.96), rgba(246, 236, 218, 0.92));
}

.conversation-shell {
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(250, 243, 231, 0.78));
  border: 1px solid rgba(67, 41, 30, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  flex: 1;
  display: flex;
  min-height: 0;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.message {
  max-width: min(860px, 100%);
  padding: 18px 20px;
  border-radius: 24px;
  border: 1px solid rgba(67, 41, 30, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(250, 243, 231, 0.82));
  box-shadow: var(--shadow-soft);
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(111, 76, 51, 0.2), rgba(234, 220, 194, 0.78));
}

.message.assistant {
  align-self: flex-start;
}

.message-role {
  margin-bottom: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--olive);
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.72;
}

.message-citations {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-citation {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(92, 104, 69, 0.12);
  font-size: 0.83rem;
  color: var(--oak-deep);
  text-decoration: none;
  box-shadow: inset 0 0 0 1px rgba(92, 104, 69, 0.08);
}

.message-citation:hover {
  text-decoration: underline;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(67, 41, 30, 0.08);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.98), rgba(241, 231, 213, 0.92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.starter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.starter {
  padding: 10px 14px;
  background: rgba(255, 250, 241, 0.94);
  color: var(--oak-deep);
  box-shadow: inset 0 0 0 1px rgba(67, 41, 30, 0.1);
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.send-button {
  min-width: 130px;
}

html[dir="rtl"] .brand-card,
html[dir="rtl"] .panel,
html[dir="rtl"] .hero-card,
html[dir="rtl"] .chat-panel,
html[dir="rtl"] .message,
html[dir="rtl"] .composer,
html[dir="rtl"] .mode-button {
  text-align: right;
}

html[dir="rtl"] .mode-button.active::before {
  left: auto;
  right: 10px;
}

html[dir="rtl"] .hero-badges {
  justify-content: flex-start;
}

html[dir="rtl"] .brand-header {
  align-items: flex-start;
  flex-direction: row-reverse;
}

html[dir="rtl"] .brand-signoff {
  align-items: flex-end;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px;
    min-height: auto;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .hero-card,
  .composer-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .main-column,
  .chat-panel,
  .conversation-shell,
  .message-list {
    min-height: auto;
  }

  .sidebar .panel:last-of-type {
    flex: initial;
  }

  .hero-select {
    width: 100%;
  }

  .brand-card h1 {
    max-width: none;
  }

  .brand-logo {
    width: 78px;
    min-width: 78px;
  }
}
