:root {
  --bg0: #f4efe4;
  --bg1: #e8e0d0;
  --ink: #1a2b22;
  --muted: #5a665e;
  --forest: #1f4a32;
  --forest-2: #2d6a48;
  --gold: #b8944c;
  --gold-soft: #f3e6c0;
  --panel: rgba(255, 252, 245, 0.88);
  --line: rgba(26, 58, 36, 0.12);
  --shadow: 0 18px 50px rgba(26, 58, 36, 0.12);
  --radius: 1.15rem;
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 55% at 8% -5%, rgba(45, 106, 72, 0.16), transparent 55%),
    radial-gradient(ellipse 60% 45% at 100% 0%, rgba(184, 148, 76, 0.14), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
}

a { color: var(--forest-2); }

.chat-body { overflow: hidden; }

.layout {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: linear-gradient(180deg, #1a3a24 0%, #14301e 100%);
  color: #f3e6c0;
  padding: 1rem 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}

.sidebar-brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sidebar-top { margin-bottom: 1rem; }

.sidebar-new {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 0.8rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.7;
  margin: 0.15rem 0.35rem 0.55rem;
  flex-shrink: 0;
}

.chat-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-height: 0;
}

.chat-list-empty {
  opacity: 0.65;
  font-size: 0.9rem;
  padding: 0.5rem 0.4rem;
}

.chat-list-item {
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255, 252, 245, 0.06);
  color: #f7f3ea;
  border-radius: 0.75rem;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font: inherit;
}

.chat-list-item:hover,
.chat-list-item.active {
  background: rgba(255, 252, 245, 0.14);
  border-color: rgba(243, 230, 192, 0.25);
}

.chat-title {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  font-size: 0.72rem;
  opacity: 0.65;
}

.sidebar-admin {
  flex-shrink: 0;
  margin-top: 0.75rem;
  color: #f3e6c0;
  text-decoration: none;
  font-size: 0.86rem;
  opacity: 0.8;
  padding: 0.35rem 0.4rem;
}

.sidebar-admin:hover { opacity: 1; }

.main-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 0.85rem;
  display: flex;
}

.mobile-only { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 40;
    height: 100%;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
}

.app-shell {
  width: min(860px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.75rem 0 2.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  text-align: center;
  margin-bottom: 1.25rem;
}

.brand-mark {
  width: 3.2rem;
  height: 3.2rem;
  margin: 0 auto 0.85rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--forest-2), var(--forest));
  color: var(--gold-soft);
  font-size: 1.35rem;
  box-shadow: 0 10px 28px rgba(31, 74, 50, 0.28);
}

.brand-logo {
  display: block;
  width: clamp(4.5rem, 12vw, 6rem);
  height: auto;
  margin: 0 auto 0.95rem;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgba(26, 58, 36, 0.22));
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 2.7rem);
  letter-spacing: 0.02em;
  color: var(--forest);
  line-height: 1.15;
}

.brand p {
  margin: 0.55rem auto 0;
  max-width: 34rem;
  color: var(--muted);
  line-height: 1.45;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.chat-app {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 245, 0.9);
}

.chat-header-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.chat-header-text {
  flex: 1;
  min-width: 0;
}

.chat-header-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--forest);
  line-height: 1.15;
}

.chat-header-text p {
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header .status-pill {
  flex-shrink: 0;
  max-width: 12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 252, 245, 0.35), rgba(244, 239, 228, 0.55));
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.15rem 4.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: min(92%, 640px);
  padding: 0.8rem 1rem;
  border-radius: 1rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(145deg, var(--forest-2), var(--forest));
  color: #f7f3ea;
  border-bottom-right-radius: 0.35rem;
}

.msg.assistant {
  align-self: flex-start;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-bottom-left-radius: 0.35rem;
}

.sources {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

.sources strong { color: var(--forest); }

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0 1rem;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.chip, button, .btn {
  font: inherit;
  cursor: pointer;
}

.chip {
  border: 1px solid rgba(31, 74, 50, 0.22);
  background: rgba(255, 252, 245, 0.96);
  color: var(--forest);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  pointer-events: auto;
  box-shadow: 0 6px 16px rgba(26, 58, 36, 0.08);
}

.chip:hover { background: #eef5ef; border-color: var(--forest-2); }

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 0.65rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 245, 0.95);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 3rem;
  max-height: 3rem;
  border-radius: 0.9rem;
  border: 1px solid var(--line);
  padding: 0.75rem 0.9rem;
  font: inherit;
  background: #fffdf8;
  color: var(--ink);
}

.composer textarea:focus {
  outline: 2px solid rgba(45, 106, 72, 0.25);
  border-color: var(--forest-2);
}

.btn-primary {
  border: none;
  border-radius: 0.9rem;
  padding: 0 1.15rem;
  background: linear-gradient(145deg, var(--forest-2), var(--forest));
  color: var(--gold-soft);
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.footer-note, .meta-line {
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 1rem;
}

.footer-note a { color: var(--forest); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(45, 106, 72, 0.1);
  color: var(--forest);
  font-size: 0.8rem;
}

.status-pill.warn { background: rgba(184, 148, 76, 0.18); color: #7a5c18; }
.status-pill.bad { background: rgba(140, 40, 40, 0.12); color: #8c2828; }

/* Admin */
.admin-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 860px) {
  .admin-grid.two { grid-template-columns: 1.1fr 0.9fr; }
}

.card {
  padding: 1.2rem 1.25rem;
}

.card h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.65rem;
  color: var(--forest);
}

.card .sub {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--forest);
}

input[type="password"], input[type="text"], input[type="file"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fffdf8;
  margin-bottom: 0.85rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.btn-secondary {
  border: 1px solid rgba(31, 74, 50, 0.25);
  background: #fffdf8;
  color: var(--forest);
  border-radius: 0.75rem;
  padding: 0.65rem 0.95rem;
  font-weight: 600;
}

.btn-danger {
  border: 1px solid rgba(140, 40, 40, 0.25);
  background: #fff5f5;
  color: #8c2828;
  border-radius: 0.65rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.doc-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #fffdf8;
}

.doc-list .name { font-weight: 600; }
.doc-list .meta { font-size: 0.8rem; color: var(--muted); }

.toast {
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.7rem;
  background: rgba(45, 106, 72, 0.1);
  color: var(--forest);
  font-size: 0.92rem;
}

.toast.error { background: rgba(140, 40, 40, 0.1); color: #8c2828; }

.typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
}
.typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.top-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.admin-body .admin-shell {
  width: min(1040px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.4rem 0 2.75rem;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.admin-back {
  color: var(--forest);
  text-decoration: none;
  font-weight: 600;
}

[hidden] { display: none !important; }

.login-wrap {
  min-height: 68vh;
  display: grid;
  place-items: center;
}

.login-wrap[hidden] {
  display: none !important;
}

.login-card {
  width: min(420px, 100%);
  padding: 2rem 1.6rem 1.6rem;
  text-align: center;
}

.login-card .toast {
  min-height: 3.1rem;
}

.login-card .toast[hidden] {
  display: block !important;
  visibility: hidden;
}

.login-card .brand-logo {
  margin-bottom: 0.7rem;
}

.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.15rem;
  color: var(--forest);
}

.login-card form {
  text-align: left;
  margin-top: 1.15rem;
}

.login-submit {
  width: 100%;
  padding: 0.8rem 1rem;
  margin-top: 0.25rem;
}

.admin-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.15rem;
}

.admin-hero h1 {
  margin: 0.15rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.6rem);
  color: var(--forest);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.admin-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1rem 1.1rem;
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-value {
  margin: 0.25rem 0 0;
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--forest);
  line-height: 1.1;
}

.stat-value-sm { font-size: 1.15rem; line-height: 1.3; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 8.5rem;
  border: 1.5px dashed rgba(31, 74, 50, 0.35);
  border-radius: 1rem;
  background: rgba(255, 252, 245, 0.7);
  cursor: pointer;
  margin-bottom: 0.9rem;
  color: var(--forest);
  text-align: center;
  padding: 1rem;
}

.dropzone span { color: var(--muted); font-size: 0.92rem; }
.dropzone em { color: var(--muted); font-size: 0.82rem; font-style: normal; margin-top: 0.45rem; }
.dropzone.dragover {
  border-color: var(--forest-2);
  background: #eef5ef;
}

@media (max-width: 800px) {
  .stat-grid { grid-template-columns: 1fr; }
  .admin-hero { flex-direction: column; align-items: flex-start; }
}
