/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --cream:           #FAF7F2;
  --white:           #FFFFFF;
  --brown-deep:      #2C2416;
  --brown-mid:       #5C4D3A;
  --brown-muted:     #9A8E7E;
  --terracotta:      #C4673A;
  --terracotta-lt:   #D9845E;
  --sage:            #7A9E7E;
  --gold:            #C9A84C;
  --border:          #EAE2D6;
  --shadow:          0 2px 20px rgba(44,36,22,.08);
  --shadow-lg:       0 8px 40px rgba(44,36,22,.14);
  --radius:          14px;
  --radius-sm:       9px;
  --ease:            .2s ease;
  --serif:           'Playfair Display', Georgia, serif;
  --sans:            'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  background: var(--cream);
  color: var(--brown-deep);
  line-height: 1.65;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
img, video { max-width: 100%; height: auto; display: block; }
a { color: var(--terracotta); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }

/* ── Typography ────────────────────────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; color: var(--brown-deep); }
h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); }
h2 { font-size: clamp(1.15rem, 3vw, 1.5rem); }
h3 { font-size: 1.05rem; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 18px; }
@media (min-width: 768px) { .container { padding: 0 36px; } }

/* ── Top Nav ───────────────────────────────────────────────────────────────── */
.top-nav {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.top-nav-inner {
  max-width: 1100px; margin: 0 auto;
  height: 58px; padding: 0 18px;
  display: flex; align-items: center; justify-content: space-between;
}
@media (min-width: 768px) { .top-nav-inner { padding: 0 36px; } }

.nav-logo {
  font-family: var(--serif);
  font-size: 1.05rem; letter-spacing: .02em;
  color: var(--brown-deep);
}
.nav-logo em { color: var(--terracotta); font-style: normal; }
.nav-back {
  display: flex; align-items: center; gap: 6px;
  color: var(--brown-muted); font-size: .85rem;
  padding: 8px 0; min-height: 44px;
}
.nav-back svg { width: 18px; height: 18px; }
.nav-actions { display: flex; align-items: center; gap: 10px; }

/* ── Language Toggle ───────────────────────────────────────────────────────── */
.lang-toggle {
  display: flex; border: 1px solid var(--border); border-radius: 20px; overflow: hidden;
}
.lang-toggle button {
  padding: 5px 11px; font-size: .72rem; font-weight: 600; letter-spacing: .05em;
  color: var(--brown-muted); transition: var(--ease);
  min-height: 32px;
}
.lang-toggle button.active { background: var(--terracotta); color: var(--white); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 24px; border-radius: var(--radius-sm);
  font-weight: 500; font-family: inherit; font-size: .9rem;
  transition: var(--ease); min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--terracotta); color: var(--white); }
.btn-primary:active { background: var(--terracotta-lt); }
@media (hover:hover) { .btn-primary:hover { background: var(--terracotta-lt); } }
.btn-outline {
  border: 1.5px solid var(--border); color: var(--brown-mid); background: var(--white);
}
.btn-ghost { color: var(--brown-muted); padding: 8px 10px; min-height: 44px; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn .icon { font-size: 1.1rem; }

/* ── Hero ──────────────────────────────────────────────────────────────────── */
.hero {
  position: relative; overflow: hidden;
  min-height: 210px;
  background: linear-gradient(155deg, #4A3728 0%, #8B7355 35%, #7A9E7E 70%, #4A7C59 100%);
}
@media (min-width: 768px) { .hero { min-height: 300px; } }
.hero-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; opacity: .65;
}
.hero-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(44,36,22,.15) 0%, rgba(44,36,22,.6) 100%);
}
.hero-content {
  position: relative; z-index: 1; padding: 36px 18px 28px;
  color: var(--white); text-align: center;
}
@media (min-width: 768px) { .hero-content { padding: 56px 36px 40px; } }
.hero-content h1 { color: var(--white); margin-bottom: 6px; text-shadow: 0 1px 8px rgba(0,0,0,.3); }
.hero-content p { color: rgba(255,255,255,.82); font-size: .92rem; letter-spacing: .02em; }

/* ── Section Cards Grid ────────────────────────────────────────────────────── */
.sections-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px; padding: 20px 0 100px;
}
@media (min-width: 480px)  { .sections-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; } }
@media (min-width: 768px)  { .sections-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 28px 0 40px; } }
@media (min-width: 1024px) { .sections-grid { grid-template-columns: repeat(4, 1fr); } }

.section-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 14px 18px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 9px; cursor: pointer;
  transition: transform var(--ease), box-shadow var(--ease);
  -webkit-tap-highlight-color: transparent;
  color: inherit; min-height: 108px;
}
.section-card:active { transform: scale(.96); }
@media (hover:hover) {
  .section-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
}
.section-card .s-icon { font-size: 1.7rem; line-height: 1; }
.section-card .s-label {
  font-family: var(--serif); font-size: .88rem; line-height: 1.3;
  color: var(--brown-deep);
}

/* ── Section Page ──────────────────────────────────────────────────────────── */
.section-page { padding: 24px 0 100px; }
.section-intro {
  font-size: .95rem; color: var(--brown-mid); line-height: 1.7;
  margin-bottom: 20px;
}

/* Accordion subsections */
.subsections { display: flex; flex-direction: column; gap: 8px; }
.subsection {
  background: var(--white); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden;
}
.subsection-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--ease); gap: 12px;
}
.subsection-header:active { background: var(--cream); }
.sh-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sh-icon { font-size: 1.1rem; flex-shrink: 0; }
.sh-title { font-family: var(--serif); font-size: .95rem; color: var(--brown-deep); }
.sh-sub-count { font-size: .72rem; color: var(--brown-muted); }
.subsection-chevron { color: var(--brown-muted); font-size: .75rem; transition: transform var(--ease); flex-shrink: 0; }
.subsection.open .subsection-chevron { transform: rotate(180deg); }
.subsection-content { display: none; padding: 0 18px 18px; }
.subsection.open .subsection-content { display: block; }
.subsection-body {
  font-size: .9rem; color: var(--brown-mid); line-height: 1.75;
  border-top: 1px solid var(--border); padding-top: 14px;
}
/* nested sub-subsections */
.sub-subsections { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sub-sub {
  background: var(--cream); border-radius: var(--radius-sm);
  border: 1px solid var(--border); overflow: hidden;
}
.sub-sub-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-size: .88rem; font-family: var(--serif); color: var(--brown-deep);
}
.sub-sub-content { display: none; padding: 0 14px 12px; }
.sub-sub.open .sub-sub-content { display: block; }
.sub-sub-body {
  font-size: .87rem; color: var(--brown-mid); line-height: 1.7;
  border-top: 1px solid var(--border); padding-top: 10px;
}

/* ── Prose content (HTML from Google Doc) ──────────────────────────────────── */
.section-intro p, .subsection-body p, .sub-sub-body p { margin-bottom: .6em; }
.section-intro p:last-child, .subsection-body p:last-child, .sub-sub-body p:last-child { margin-bottom: 0; }
.section-intro ul, .subsection-body ul, .sub-sub-body ul,
.section-intro ol, .subsection-body ol, .sub-sub-body ol {
  padding-left: 1.3em; margin: .4em 0 .6em;
}
.section-intro li, .subsection-body li, .sub-sub-body li { margin-bottom: .25em; }
.section-intro a, .subsection-body a, .sub-sub-body a {
  color: var(--terracotta); text-decoration: underline;
  text-decoration-color: rgba(196,103,58,.4);
  text-underline-offset: 2px;
}
.section-intro a:hover, .subsection-body a:hover, .sub-sub-body a:hover {
  text-decoration-color: var(--terracotta);
}
.section-intro strong, .subsection-body strong, .sub-sub-body strong {
  color: var(--brown-deep); font-weight: 600;
}
.section-intro em, .subsection-body em, .sub-sub-body em { font-style: italic; }

/* ── Media gallery ─────────────────────────────────────────────────────────── */
.media-gallery {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 20px;
}
@media (min-width: 480px) { .media-gallery { grid-template-columns: repeat(3, 1fr); } }
.media-thumb {
  aspect-ratio: 4/3; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--border); cursor: pointer;
}
.media-thumb img, .media-thumb video {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform var(--ease);
}
@media (hover:hover) { .media-thumb:hover img { transform: scale(1.03); } }

/* ── Chat FAB ──────────────────────────────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 20px; z-index: 200;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--terracotta); color: var(--white);
  box-shadow: 0 4px 24px rgba(196,103,58,.42);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; transition: transform var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.chat-fab:active { transform: scale(.92); }
@media (hover:hover) { .chat-fab:hover { transform: scale(1.06); } }

/* ── Chat Panel — mobile: slide up from bottom ─────────────────────────────── */
.chat-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 92dvh;
  z-index: 300;
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 40px rgba(44,36,22,.18);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.32,.72,0,1);
  will-change: transform;
}
.chat-panel.open { transform: translateY(0); }
.chat-backdrop {
  position: fixed; inset: 0; z-index: 290;
  background: rgba(44,36,22,.35);
  opacity: 0; pointer-events: none;
  transition: opacity .35s ease;
}
.chat-backdrop.open { opacity: 1; pointer-events: all; }

/* Desktop: floating card */
@media (min-width: 768px) {
  .chat-panel {
    inset: auto;
    right: 20px;
    bottom: calc(90px + env(safe-area-inset-bottom));
    width: 390px; height: 580px;
    max-height: calc(100dvh - 120px);
    border-radius: var(--radius);
    transform: translateY(16px) scale(.97);
    opacity: 0; pointer-events: none;
    transition: transform .25s ease, opacity .25s ease;
  }
  .chat-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1; pointer-events: all;
  }
}

/* Chat header grab handle (mobile) */
.chat-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 10px auto 0;
  flex-shrink: 0;
}
@media (min-width: 768px) { .chat-handle { display: none; } }

.chat-header {
  padding: 12px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--terracotta), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.chat-name { font-family: var(--serif); font-size: .95rem; }
.chat-status { font-size: .72rem; color: var(--brown-muted); }
.chat-controls { display: flex; gap: 4px; align-items: center; }
.chat-ctrl-btn {
  width: 36px; height: 36px; border-radius: 50%; color: var(--brown-muted);
  display: flex; align-items: center; justify-content: center; font-size: .95rem;
  transition: background var(--ease);
}
.chat-ctrl-btn:active { background: var(--cream); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.bubble-wrap { display: flex; flex-direction: column; gap: 2px; }
.bubble-wrap.user { align-items: flex-end; }
.bubble-wrap.assistant { align-items: flex-start; }

.chat-bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 18px;
  font-size: .88rem; line-height: 1.55;
}
.chat-bubble.user {
  background: var(--terracotta); color: var(--white);
  border-bottom-right-radius: 5px;
}
.chat-bubble.assistant {
  background: var(--cream); color: var(--brown-deep);
  border: 1px solid var(--border); border-bottom-left-radius: 5px;
}
.chat-bubble p { margin: 0 0 .4em; }
.chat-bubble p:last-child { margin: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble h3 { font-size: .9rem; margin: .6em 0 .2em; }
.chat-bubble ul, .chat-bubble ol { padding-left: 1.1em; margin: .3em 0; }
.chat-bubble li { margin-bottom: .15em; }
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: .6em 0; }
.chat-bubble em { font-style: italic; color: var(--brown-muted); font-size: .85rem; }

.tool-notice {
  display: flex; align-items: center; gap: 6px;
  font-size: .75rem; color: var(--brown-muted); font-style: italic; padding: 2px 4px;
}
.tool-notice-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--gold);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.35; } }

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 32px 20px; color: var(--brown-muted);
}
.chat-empty .e-icon { font-size: 2.2rem; margin-bottom: 10px; }
.chat-empty p { font-size: .85rem; line-height: 1.5; }

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 6px 2px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brown-muted);
  animation: tdot 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes tdot { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* Chat input */
.chat-input-area {
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
  flex-shrink: 0;
}
.chat-textarea {
  flex: 1; border: 1.5px solid var(--border); border-radius: 22px;
  padding: 10px 15px; font-family: inherit; font-size: 1rem;
  background: var(--cream); resize: none; max-height: 110px;
  outline: none; line-height: 1.4;
  transition: border-color var(--ease);
  -webkit-appearance: none;
}
.chat-textarea:focus { border-color: var(--terracotta); }
.chat-send-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--terracotta); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0; transition: var(--ease);
}
.chat-send-btn:disabled { opacity: .4; }
.chat-send-btn:active { transform: scale(.92); }

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(155deg, #4A3728 0%, #8B7355 40%, #7A9E7E 100%);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--white);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 36px 26px 28px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 1.65rem; }
.login-logo p { font-size: .82rem; color: var(--brown-muted); margin-top: 5px; }
.form-group { margin-bottom: 13px; }
.form-label { display: block; font-size: .78rem; font-weight: 500; color: var(--brown-mid); margin-bottom: 5px; }
.form-input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-family: inherit; font-size: 1rem;
  background: var(--cream); outline: none;
  transition: border-color var(--ease); min-height: 48px;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--terracotta); }
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--brown-muted); font-size: .75rem; margin: 14px 0;
}
.divider::before, .divider::after { content:''; flex:1; height:1px; background: var(--border); }
.error-msg { color: var(--terracotta); font-size: .82rem; margin-top: 8px; min-height: 20px; }

/* ── Admin page ────────────────────────────────────────────────────────────── */
.admin-page { padding: 24px 0 80px; }
.admin-section { margin-bottom: 32px; }
.admin-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.admin-section-head h2 { font-size: 1rem; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 500; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }
.user-meta { font-size: .75rem; color: var(--brown-muted); }
.badge {
  padding: 3px 9px; border-radius: 10px; font-size: .68rem; font-weight: 700;
  letter-spacing: .04em; flex-shrink: 0;
}
.badge-admin { background: var(--terracotta); color: var(--white); }
.badge-guest { background: var(--border); color: var(--brown-muted); }
.sync-log-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .82rem; }
.sync-ok  { color: var(--sage); }
.sync-err { color: var(--terracotta); }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--brown-deep); color: var(--white);
  padding: 10px 20px; border-radius: 20px; font-size: .84rem;
  opacity: 0; pointer-events: none; z-index: 600;
  transition: all .25s ease; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--terracotta); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.text-muted { color: var(--brown-muted); }
.mt-16 { margin-top: 16px; }

@media (min-width: 768px) {
  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
}
