/* ============================================================
   Design tokens. Swap the values in :root to re-theme for another
   reseller — the palette below is the numerojyotish brand + the
   OccultSanctum gold. Everything else is derived from these.
   ============================================================ */
:root {
  --bg: #FBF7EF;
  --bg-deep: #F3EAD8;
  --surface: #FFFFFF;
  --surface-2: #F4ECDC;
  --ink: #2A2118;
  --ink-soft: #6B5E4B;
  --primary: #A9791C;
  --primary-deep: #8A6212;
  --accent: #7A1F2B;
  --muted: #E0A630;
  --line: #E7DCC6;
  --danger: #8A1F1F;

  /* derived — tints/gradients built from the palette above */
  --gold-grad: linear-gradient(135deg, #E0A630 0%, #A9791C 100%);
  --gold-soft: rgba(169, 121, 28, .10);
  --gold-line: rgba(169, 121, 28, .26);
  --ring: rgba(169, 121, 28, .35);
  --maroon-soft: rgba(122, 31, 43, .08);

  --radius: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(42, 33, 24, .06);
  --shadow-sm: 0 1px 2px rgba(42, 33, 24, .05), 0 2px 8px rgba(42, 33, 24, .05);
  --shadow: 0 1px 2px rgba(42, 33, 24, .06), 0 10px 28px rgba(42, 33, 24, .07);
  --shadow-lg: 0 2px 6px rgba(42, 33, 24, .07), 0 22px 50px rgba(42, 33, 24, .12);

  --font-display: 'Marcellus', Georgia, serif;
  --font-body: 'Mukta', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: .2px; margin: 0; }
a { color: var(--primary-deep); }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--muted); color: #fff; }

/* ---------------------------------------------------------------- buttons */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  background: var(--gold-grad); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: .72rem 1.15rem;
  font-size: 1rem; font-weight: 500; letter-spacing: .2px;
  box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .15s ease, filter .15s ease;
}
.btn-primary:hover { filter: brightness(1.04); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .55; cursor: default; box-shadow: none; transform: none; filter: none; }
.btn-primary.block { width: 100%; }
.btn-primary svg { width: 16px; height: 16px; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: .4rem;
  background: transparent; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .48rem .85rem; color: var(--ink-soft);
  font-size: .92rem; transition: border-color .15s, color .15s, background .15s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--ink); background: var(--gold-soft); }

/* ---------------------------------------------------------------- notices */
.notice {
  border-radius: var(--radius-sm); padding: .7rem .95rem; margin: .2rem 0 .6rem;
  background: var(--surface-2); border: 1px solid var(--line); font-size: .95rem;
  display: flex; align-items: center; gap: .55rem;
}
.notice::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: none; }
.notice-warn { background: #FBF1DA; border-color: var(--muted); }
.notice-warn::before { background: var(--muted); }
.notice-error { background: #F7E6E6; border-color: var(--danger); color: var(--danger); }
.notice-error::before { background: var(--danger); }

/* ---------------------------------------------------------------- avatars / glyphs */
.avatar, .bot-avatar, .user-avatar, .chat-head-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; flex: none; color: #fff; background: var(--gold-grad);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), var(--shadow-xs);
}
.avatar { width: 30px; height: 30px; }
.avatar svg { width: 16px; height: 16px; }
.avatar-user { background: #efe6d2; color: var(--primary-deep); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------------------------------------------------------------- auth / login */
body.auth {
  min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 2.5rem 1rem 1.5rem;
  background:
    radial-gradient(900px 420px at 50% -8%, #FFFDF8 0%, rgba(255, 253, 248, 0) 70%),
    radial-gradient(700px 500px at 90% 110%, var(--gold-soft) 0%, rgba(0, 0, 0, 0) 60%),
    var(--bg);
}
.auth-card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-width: 430px; width: 100%; padding: 2.6rem 2.2rem 2.2rem; text-align: center;
}
.auth-card::before {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  padding: 1px; background: linear-gradient(160deg, var(--gold-line), transparent 45%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}
.auth-ornament { color: var(--muted); margin-bottom: .4rem; display: flex; justify-content: center; }
.auth-ornament svg { width: 26px; height: 26px; }
.brand-logo { height: 66px; width: auto; margin: 0 auto .7rem; display: block; }
.brand-name { font-size: 2rem; margin: .1rem 0 .15rem; color: var(--accent); }
.brand-tagline { color: var(--ink-soft); margin: 0 0 1.7rem; font-style: italic; }
.auth-divider {
  height: 1px; margin: 0 auto 1.5rem; max-width: 200px;
  background: linear-gradient(90deg, transparent, var(--gold-line), transparent);
}
.btn-google {
  display: inline-flex; align-items: center; gap: .7rem; justify-content: center;
  width: 100%; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .8rem 1rem; color: var(--ink);
  font-size: 1rem; font-weight: 500; text-decoration: none;
  box-shadow: var(--shadow-xs); transition: box-shadow .15s, border-color .15s, transform .12s;
}
.btn-google:hover { box-shadow: var(--shadow); border-color: var(--primary); transform: translateY(-1px); }
.btn-google svg { width: 20px; height: 20px; flex: none; }
.auth-hint { color: var(--ink-soft); font-size: .85rem; margin-top: 1.1rem; }
.auth-card .notice { text-align: left; }

/* ---------------------------------------------------------------- site footer (login) */
.site-footer { margin-top: 2rem; text-align: center; color: var(--ink-soft); font-size: .85rem; max-width: 560px; }
.site-footer .socials { display: flex; gap: 1.1rem; justify-content: center; margin: .6rem 0; flex-wrap: wrap; }
.site-footer a { color: var(--primary-deep); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer .contact { margin: .3rem 0; }
.powered {
  margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid var(--line);
  font-size: .8rem; letter-spacing: .04em; color: var(--ink-soft);
}
.powered a { font-weight: 600; }

/* ---------------------------------------------------------------- app shell */
body.app { min-height: 100%; display: flex; flex-direction: column; background: var(--bg); }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.3rem; background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(140%) blur(6px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand-logo-sm { height: 34px; width: auto; }
.brand-name-sm { font-family: var(--font-display); font-size: 1.25rem; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: .85rem; }

.credits {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--surface-2); border: 1px solid var(--gold-line); border-radius: var(--radius-pill);
  padding: .32rem .8rem; font-weight: 600; font-size: .88rem; color: var(--primary-deep);
  transition: background .2s, border-color .2s, color .2s;
}
.credits .credits-ico { width: 14px; height: 14px; color: var(--primary); }
.credits.is-low { background: var(--maroon-soft); border-color: var(--accent); color: var(--accent); }
.credits.is-low .credits-ico { color: var(--accent); }

.user { display: flex; align-items: center; gap: .5rem; }
.user-avatar { width: 30px; height: 30px; font-size: .82rem; font-weight: 600; }
.user-name { color: var(--ink-soft); font-size: .9rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- body grid */
.app-body { flex: 1; display: grid; grid-template-columns: 304px 1fr; min-height: 0; }

.sidebar {
  border-right: 1px solid var(--line); padding: 1.1rem 1rem; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  display: flex; flex-direction: column; gap: 1.3rem;
}
.btn-new { letter-spacing: .3px; }
.panel { display: flex; flex-direction: column; gap: .55rem; }
.panel-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-soft); margin: 0; font-family: var(--font-body); font-weight: 600;
}
.conversation-list { display: flex; flex-direction: column; gap: .45rem; }

/* conversation rows */
.conversation-item {
  display: flex; flex-direction: column; gap: .12rem; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .5rem .65rem; color: var(--ink); transition: background .15s, border-color .15s;
}
.conversation-item:hover { background: var(--surface); border-color: var(--line); }
.conversation-item.active { background: var(--surface); border-color: var(--gold-line); box-shadow: var(--shadow-xs); }
.conv-title { font-size: .9rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: .73rem; color: var(--ink-soft); display: flex; align-items: center; gap: .35rem; }
.conv-meta::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); flex: none; }
.muted { color: var(--ink-soft); font-size: .85rem; padding: .2rem .1rem; }

/* loading skeletons */
.skel-row { height: 52px; border-radius: var(--radius-sm); margin: 0; background: linear-gradient(90deg, var(--surface-2) 25%, #efe4cd 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skel-row.sm { height: 40px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------------------------------------------------------------- chat column */
.chat { display: flex; flex-direction: column; min-height: 0; position: relative; }

/* gallery — the guide selection panel (landing) */
.gallery { flex: 1; overflow-y: auto; }
.gallery-inner { width: 100%; max-width: 920px; margin: 0 auto; padding: 2.4rem 1.4rem; }
.gallery-head { text-align: center; margin-bottom: 1.7rem; }
.kicker { display: inline-block; font-size: .73rem; letter-spacing: .18em; text-transform: uppercase; color: var(--primary); margin-bottom: .45rem; }
.gallery-head h1 { font-size: 2rem; color: var(--accent); margin: 0 0 .35rem; }
.gallery-head p { margin: 0 auto; max-width: 460px; color: var(--ink-soft); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }

.guide-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: .45rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.6rem 1.2rem 1.3rem; box-shadow: var(--shadow-sm); color: var(--ink); position: relative;
  transition: transform .15s ease, box-shadow .2s ease, border-color .15s ease;
}
.guide-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.guide-card-icon { width: 58px; height: 58px; margin-bottom: .25rem; }
.guide-card-icon svg { width: 28px; height: 28px; }
.guide-card-name { font-family: var(--font-display); font-size: 1.25rem; color: var(--ink); line-height: 1.2; }
.guide-card-desc { font-size: .9rem; color: var(--ink-soft); line-height: 1.5; }
.guide-card-tag {
  margin-top: .35rem; font-size: .7rem; letter-spacing: .05em; text-transform: uppercase;
  color: var(--primary-deep); background: var(--gold-soft); border: 1px solid var(--gold-line);
  border-radius: var(--radius-pill); padding: .22rem .65rem;
}
.guide-card-cta { margin-top: .5rem; font-size: .85rem; font-weight: 600; color: var(--primary-deep); opacity: 0; transform: translateY(-3px); transition: opacity .15s, transform .15s; }
.guide-card:hover .guide-card-cta, .guide-card:focus-visible .guide-card-cta { opacity: 1; transform: translateY(0); }

.skel-card { height: 196px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2) 25%, #efe4cd 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }

.chat-active {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 1.1rem 1.2rem 1.2rem; max-width: 860px; width: 100%; margin: 0 auto;
}
.chat-head {
  display: flex; align-items: center; gap: .7rem; padding: .2rem .2rem 1rem;
  border-bottom: 1px solid var(--line); margin-bottom: .9rem;
}
.chat-back {
  display: none; flex: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink-soft); transition: border-color .15s, color .15s, background .15s;
}
.chat-back:hover { border-color: var(--primary); color: var(--ink); background: var(--gold-soft); }
.chat-back svg { width: 19px; height: 19px; }
.chat-head-avatar { width: 42px; height: 42px; }
.chat-head-avatar svg { width: 21px; height: 21px; }
.chat-head-meta { min-width: 0; }
.chat-head-title { font-size: 1.18rem; color: var(--ink); line-height: 1.25; }
.chat-head-sub { margin: .1rem 0 0; font-size: .85rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* prechat (name/dob/photo) */
.prechat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-bottom: .9rem; box-shadow: var(--shadow-sm); }
.prechat-hint { margin: 0 0 .7rem; color: var(--ink-soft); font-size: .9rem; display: flex; align-items: center; gap: .45rem; }
.prechat-hint svg { width: 15px; height: 15px; color: var(--primary); flex: none; }
.field { display: flex; flex-direction: column; gap: .28rem; margin-bottom: .65rem; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: .82rem; color: var(--ink-soft); font-weight: 500; }
.field input {
  padding: .58rem .72rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 1rem; background: var(--bg); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--gold-soft); }
.field input[type="file"] { padding: .45rem .5rem; background: var(--surface-2); cursor: pointer; }

/* messages */
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .85rem; padding: .3rem .1rem .5rem; scroll-behavior: smooth; }
.msg-row { display: flex; gap: .55rem; align-items: flex-end; max-width: 100%; animation: rise .26s ease both; }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.msg { max-width: 80%; padding: .72rem .95rem; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; box-shadow: var(--shadow-xs); }
.msg-user { background: var(--gold-grad); color: #fff; border-bottom-right-radius: 5px; }
.msg-assistant { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }

/* formatted (markdown) assistant content */
.markdown { white-space: normal; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 .6rem; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-family: var(--font-display); color: var(--accent); margin: .9rem 0 .45rem; line-height: 1.25; }
.markdown h1 { font-size: 1.3rem; } .markdown h2 { font-size: 1.18rem; } .markdown h3 { font-size: 1.05rem; } .markdown h4 { font-size: .98rem; }
.markdown ul, .markdown ol { margin: 0 0 .6rem; padding-left: 1.3rem; }
.markdown li { margin: .18rem 0; }
.markdown li::marker { color: var(--primary); }
.markdown strong { color: var(--primary-deep); font-weight: 600; }
.markdown em { color: var(--accent); }
.markdown a { color: var(--primary-deep); text-decoration: underline; text-underline-offset: 2px; }
.markdown blockquote { margin: .6rem 0; padding: .35rem .9rem; border-left: 3px solid var(--muted); background: var(--gold-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--ink-soft); }
.markdown code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: .05rem .35rem; font-size: .9em; }
.markdown pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .8rem; overflow-x: auto; }
.markdown pre code { background: none; border: none; padding: 0; }
.markdown hr { border: none; border-top: 1px solid var(--line); margin: .9rem 0; }
.markdown table { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .92rem; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: .4rem .55rem; text-align: left; }
.markdown th { background: var(--surface-2); }

/* typing indicator */
.typing { display: inline-flex; align-items: center; gap: .6rem; color: var(--ink-soft); }
.typing-caption { font-size: .9rem; font-style: italic; }
.dots { display: inline-flex; gap: 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); opacity: .35; animation: blink 1.25s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .18s; }
.dots span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* composer */
.composer { display: flex; gap: .6rem; align-items: flex-end; margin-top: .9rem; }
.composer textarea {
  flex: 1; resize: none; min-height: 50px; max-height: 160px; padding: .7rem .85rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 1rem; line-height: 1.5; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-xs); transition: border-color .15s, box-shadow .15s;
}
.composer textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--gold-soft); }
.btn-send {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  background: var(--gold-grad); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: .72rem 1.05rem; min-height: 50px; font-size: .98rem; font-weight: 500;
  box-shadow: var(--shadow-sm); transition: filter .15s, transform .12s, box-shadow .15s;
}
.btn-send:hover { filter: brightness(1.04); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-send:disabled { opacity: .6; cursor: default; transform: none; box-shadow: none; filter: none; }
.btn-send .send-ico { width: 17px; height: 17px; }
.btn-send.sending .send-ico { display: none; }
.btn-send .spinner { display: none; }
.btn-send.sending .spinner { display: inline-block; }
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- app footer */
.app-footer {
  text-align: center; padding: .55rem 1rem; font-size: .78rem; letter-spacing: .04em;
  color: var(--ink-soft); background: var(--surface); border-top: 1px solid var(--line);
}
.app-footer a { font-weight: 600; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- responsive */
/* ---------------------------------------------------------------- responsive
   Mobile is a master-detail flow: the gallery (selection) is "home", the chat
   is the "detail". Picking a guide opens the chat full-screen; Back returns. */
@media (max-width: 860px) {
  .app-body { display: flex; flex-direction: column; }
  .chat { order: 1; min-height: 0; }
  .sidebar {
    order: 2; border-right: none; border-top: 1px solid var(--line);
    max-height: none; overflow: visible; gap: 1rem;
  }
  .btn-new { display: none; }            /* the gallery is the new-reading surface */
  .gallery { overflow: visible; flex: none; }
  .gallery-inner { padding: 1.5rem 1rem 1rem; }
  .gallery-head h1 { font-size: 1.7rem; }
  .messages { overflow: visible; flex: none; }
  .chat-active { max-width: none; padding: 1rem 1rem 0; }
  .chat-back { display: inline-flex; }
  .user-name { display: none; }
  .msg { max-width: 90%; }
  .btn-send .send-label { display: none; }
  .btn-send { padding: .72rem .9rem; min-width: 48px; }

  /* chat open: hide the home view, keep the composer pinned to the viewport */
  body.chat-open .sidebar { display: none; }
  body.chat-open .app-footer { display: none; }
  body.chat-open .composer {
    position: sticky; bottom: 0; z-index: 5; margin-top: .4rem;
    padding: .55rem 0 calc(.7rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(251, 247, 239, 0), var(--bg) 26%);
  }
  body.chat-open .msg-row { scroll-margin-bottom: 92px; }
}

@media (max-width: 480px) {
  .app-header { padding: .55rem .8rem; }
  .brand-name-sm { display: none; }
  .user-avatar { display: none; }
  .header-right { gap: .55rem; }
  .credits { padding: .3rem .6rem; font-size: .82rem; }
  .gallery-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
