/* ===========================================================================
   Ask Subaru — client styles
   Warm, plain, screenshot-friendly. Palette matches the admin page in worker.js
   so the family of apps stays visually consistent.
   =========================================================================== */

:root {
  --orange:   #d96a2b;
  --orange-d: #c25c22;
  --ink:      #2b2b2b;
  --ink-soft: #6b6459;
  --line:     #e6e1da;
  --bg:       #faf7f3;
  --panel:    #ffffff;
  --bubble-you: #f0ebe4;
  --danger:   #b03a3a;
  --danger-bg:#fbeaea;
  --radius:   14px;
  --maxw:     720px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over the .gate/.chat display rules below.
   Author `display` values otherwise override the UA `[hidden]{display:none}`,
   which would leave a hidden view still on screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- shared brand ------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--orange);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,0.35);
}
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }

/* ---- shared controls ---------------------------------------------------- */
.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.text-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 17px;
  background: #fff;
  color: var(--ink);
}
.text-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(217,106,43,0.15);
}
.hint { font-size: 14px; color: var(--ink-soft); margin: 8px 0 0; }

.btn-primary {
  margin-top: 18px;
  width: 100%;
  padding: 14px 18px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--orange-d); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.btn-text {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  padding: 6px 8px;
}
.btn-text:hover { color: var(--ink); text-decoration: underline; }

.notice {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  background: var(--danger-bg);
  color: var(--danger);
}

/* ===========================================================================
   GATE
   =========================================================================== */
.gate {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 18px;
}
.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px 30px;
  box-shadow: 0 1px 2px rgba(43,43,43,0.04), 0 8px 24px rgba(43,43,43,0.06);
}
.gate-title {
  font-size: 24px;
  line-height: 1.25;
  margin: 20px 0 10px;
  letter-spacing: -0.01em;
}
.gate-sub {
  color: var(--ink-soft);
  font-size: 16px;
  margin: 0 0 22px;
}
.gate-foot {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0;
}

/* ===========================================================================
   CHAT
   =========================================================================== */
.chat {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--bg);
}
.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(250,247,243,0.92);
  backdrop-filter: saturate(1.1) blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.messages {
  flex: 1 1 auto;
  min-height: 0; /* let this flex child shrink so it scrolls internally, not the page */
  overflow-y: auto;
  padding: 20px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* message rows */
.msg { display: flex; }
.msg.you { justify-content: flex-end; }
.msg.bot { justify-content: flex-start; }

.bubble {
  max-width: 88%;
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 17px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.you .bubble {
  background: var(--bubble-you);
  border-bottom-right-radius: 5px;
  color: var(--ink);
}
.msg.bot .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

/* rendered markdown inside bot bubbles */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble em { font-style: italic; color: var(--orange-d); }
.bubble strong { font-weight: 700; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble a { color: var(--orange-d); }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-soft);
  opacity: 0.4;
  animation: blink 1.3s infinite both;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 0.9; } }

/* suggested starter questions */
.suggestions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 18px 10px;
}
.suggestions:empty { display: none; }
.chip {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 15px;
  cursor: pointer;
  line-height: 1.2;
}
.chip:hover { border-color: var(--orange); color: var(--orange-d); }

/* composer */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 160px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 17px;
  font-family: inherit;
  line-height: 1.4;
  background: #fff;
  color: var(--ink);
}
.composer-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(217,106,43,0.15);
}
.btn-send {
  flex: 0 0 auto;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  height: 46px;
}
.btn-send:hover { background: var(--orange-d); }
.btn-send:disabled { opacity: 0.5; cursor: default; }

.safety-note {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 18px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  background: var(--bg);
}

/* chat-level error/system line */
.system-line {
  align-self: center;
  max-width: 88%;
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
}
.system-line.error { color: var(--danger); }

@media (min-width: 760px) {
  .chat { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
