/* Harborview Companion — mobile-first, no framework. Brand color is set at runtime from the tenant. */
:root {
  --brand: #E8739A;
  --brand-ink: #ffffff;
  --brand-soft: #fdeef3;
  --bg: #faf8f9;
  --card: #ffffff;
  --ink: #1f1a1d;
  --muted: #6d5f66;
  --line: #ece4e8;
  --err: #b3261e;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* ---- layout ---- */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px; padding-top: calc(10px + var(--safe-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; text-align: center; letter-spacing: 0.01em; }
.iconbtn { background: rgba(255,255,255,0.18); color: inherit; border: 0; border-radius: 10px; width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.iconbtn.small { width: 30px; height: 30px; font-size: 14px; background: transparent; color: var(--muted); }
.main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 12px 0; }

/* ---- landing ---- */
.landing { max-width: 420px; margin: 12vh auto 0; padding: 24px; text-align: center; }
.landing .mark { width: 96px; height: 96px; border-radius: 28px; margin-bottom: 12px; }
.landing h1 { margin: 0 0 4px; font-size: 26px; }
.landing .tagline { margin: 0 0 20px; color: var(--muted); }
.landing form { display: flex; flex-direction: column; gap: 10px; }
.landing input { padding: 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; background: var(--card); }
.fine { font-size: 13px; color: var(--muted); }
.msg-line { min-height: 1.4em; font-size: 14px; color: var(--muted); }
.msg-line.err { color: var(--err); }

.btn { border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 12px; padding: 13px 16px; font-weight: 600; }
.btn.secondary { background: var(--brand-soft); color: var(--ink); }
.btn:disabled { opacity: 0.55; }
.linkbtn { background: none; border: 0; color: var(--brand); padding: 10px; font-weight: 500; }

/* ---- thread ---- */
.thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.user a { color: inherit; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant.error { border-color: #f1c7c4; background: #fff5f4; }
.msg.assistant.aborted { border-style: dashed; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 13px; text-align: center; }
.msg .meta { margin-top: 6px; font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.msg .meta button { border: 0; background: var(--brand-soft); color: var(--ink); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.msg .thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg .thumbs img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; }

/* markdown */
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md h2, .md h3, .md h4 { margin: 8px 0 6px; font-size: 1.05em; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md code { font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #f3eef1; padding: 1px 5px; border-radius: 5px; }
.md .block { position: relative; margin: 8px 0; }
.md pre { margin: 0; padding: 12px 12px 12px; background: #f6f1f4; border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.md pre code { background: transparent; padding: 0; }
.md .copy { position: absolute; top: 6px; right: 6px; border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; }
.md .copy.done { background: #2e7d5b; }
.md img { display: block; max-width: 100%; border-radius: 12px; margin: 6px 0; }

/* working bubble */
.msg.working .progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.msg.working .text:empty { display: none; }
.dots i { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--brand); opacity: 0.4; animation: pulse 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ---- composer ---- */
.composer {
  position: sticky; bottom: 0; z-index: 4;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}
.composer form { display: flex; gap: 8px; align-items: flex-end; max-width: 760px; margin: 0 auto; }
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 22px; font: inherit; background: var(--card); line-height: 1.35;
}
.composer .send { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 20px; }
.composer .attach { width: 44px; height: 44px; background: var(--card); border: 1px solid var(--line); color: var(--ink); border-radius: 50%; font-size: 20px; }
.attachments { display: flex; gap: 8px; max-width: 760px; margin: 0 auto 8px; flex-wrap: wrap; }
.attachments .att { position: relative; }
.attachments img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.attachments .att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; font-size: 12px; }
.attachments .att.pending img { opacity: 0.4; }

/* ---- drawer ---- */
.drawer-backdrop, .sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); background: var(--card); padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom)); display: flex; flex-direction: column; box-shadow: 4px 0 24px rgba(0,0,0,0.15); }
.drawer-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.drawer-head .btn { flex: 1; }
.drawer-head .iconbtn { background: var(--brand-soft); color: var(--ink); }
.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.convs li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.convs li button[data-open] { flex: 1; text-align: left; background: none; border: 0; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.convs li.active button[data-open] { background: var(--brand-soft); border-radius: 10px; }
.conv-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.conv-when { font-size: 12px; color: var(--muted); }

/* ---- settings sheet ---- */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--card); border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }

/* ---- install hint ---- */
.install-hint { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 10px 14px calc(10px + var(--safe-bottom)); background: var(--ink); color: #fff; font-size: 14px; z-index: 6; }
.install-hint span { flex: 1; }
.install-hint button { background: transparent; border: 0; color: #fff; font-size: 16px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---- support page ---- */
.support { max-width: 760px; margin: 0 auto; padding: 16px; }
.support h2 { margin: 18px 0 8px; font-size: 18px; }
.support table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); border-radius: 12px; overflow: hidden; }
.support th, .support td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.support .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.support .row-actions button { border: 0; background: var(--brand-soft); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.support form.inline { display: flex; gap: 8px; flex-wrap: wrap; }
.support form.inline input { padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.support .linkbox { font: 13px ui-monospace, monospace; background: #f6f1f4; padding: 10px; border-radius: 10px; word-break: break-all; }
