/* Secretary — public chat (web app, PWA and embedded widget iframe) */
:root {
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1a1f36;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bubble: #eef1f8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
}
@media (min-width: 820px) {
  body:not(.embed) .app {
    height: calc(100dvh - 48px);
    margin: 24px auto;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(26, 31, 54, 0.10), 0 1px 3px rgba(26, 31, 54, 0.06);
    overflow: hidden;
    border: 1px solid var(--border);
  }
}
body.embed { background: var(--surface); }
body.embed .app { max-width: none; height: 100dvh; }

/* ---------- header ---------- */
.hdr {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + var(--sat)) 16px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  flex: 0 0 auto;
  position: relative;
  z-index: 3;
}
body.embed .hdr { padding: 10px 12px 10px 14px; }
.hdr-avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.25); object-fit: cover; flex: 0 0 auto; }
.hdr-text { flex: 1 1 auto; min-width: 0; }
.hdr-name { font-weight: 650; font-size: 16px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-title { font-size: 12.5px; opacity: 0.85; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-actions { position: relative; display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: inherit;
  display: inline-flex; align-items: center; justify-content: center; opacity: 0.9;
}
.icon-btn:hover, .icon-btn:focus-visible { background: rgba(255,255,255,0.18); opacity: 1; outline: none; }
.menu {
  position: absolute; right: 0; top: 42px; min-width: 210px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(26,31,54,0.16); padding: 6px; z-index: 10;
}
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; font-size: 14px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bubble); outline: none; }
.menu-foot { padding: 8px 10px 4px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 4px; }
.menu-foot:empty { display: none; }

/* ---------- banner ---------- */
.banner {
  flex: 0 0 auto;
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  color: #7c2d12;
  padding: 10px 16px;
  font-size: 13.5px;
  line-height: 1.45;
}
.banner.ok { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.banner.ok .banner-dot { background: var(--success); }
.banner-row { display: flex; gap: 10px; align-items: flex-start; }
.banner-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-top: 6px; flex: 0 0 auto; }
.banner-text { flex: 1 1 auto; }
.banner-sub { margin-top: 6px; font-size: 12.5px; opacity: 0.9; }
.contact-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.contact-form .in { flex: 1 1 120px; min-width: 0; padding: 8px 10px; border: 1px solid #fdba74; border-radius: 8px; background: #fff; font-size: 14px; }
.contact-form .in:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn { padding: 8px 14px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- messages ---------- */
.msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.row { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
.row.user { justify-content: flex-end; }
.row.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.row.assistant .bubble, .row.owner .bubble { background: var(--bubble); border-bottom-left-radius: 4px; }
.row.owner .bubble { background: #eef9f1; border: 1px solid #bbf7d0; }
.row.error .bubble { background: #fef2f2; border: 1px solid #fecaca; color: #7f1d1d; }
.row .avatar { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; object-fit: cover; background: var(--bubble); }
.row .avatar.owner-avatar { display: inline-flex; align-items: center; justify-content: center; background: #dcfce7; color: #166534; font-weight: 700; font-size: 12px; }
.col { display: flex; flex-direction: column; gap: 4px; max-width: min(86%, 600px); min-width: 0; }
.row.user .col { align-items: flex-end; }
.who { font-size: 11.5px; color: var(--muted); padding: 0 4px; }
.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.bubble p { margin: 0; }
.bubble p + p, .bubble ul + p, .bubble ol + p, .bubble p + ul, .bubble p + ol { margin-top: 8px; }
.bubble ul, .bubble ol { margin: 4px 0 0; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.bubble code { font-family: var(--mono); font-size: 0.9em; background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 5px; }
.row.user .bubble code { background: rgba(255,255,255,0.22); }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.row.assistant .bubble a { color: var(--accent); }
.bubble .cursor { display: inline-block; width: 6px; height: 1em; background: currentColor; opacity: 0.6; vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.ts { font-size: 11px; color: var(--muted); padding: 0 4px; opacity: 0; transition: opacity .15s; height: 0; overflow: hidden; }
.row:hover .ts, .row.show-ts .ts { opacity: 1; height: auto; }
.row.highlight .bubble { box-shadow: 0 0 0 2px #86efac; }
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); opacity: 1; } }
.retry { margin-top: 6px; background: transparent; border: 1px solid currentColor; border-radius: 8px; padding: 4px 10px; font-size: 13px; color: inherit; }
.sys { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }

/* ---------- estimate card ---------- */
.estimate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  max-width: min(86%, 600px);
  box-shadow: 0 1px 2px rgba(26,31,54,0.04);
}
.estimate .est-title { font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.est-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.est-cell { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.est-label { font-size: 11px; color: var(--muted); }
.est-value { font-weight: 650; font-size: 15px; margin-top: 2px; }
.estimate details { margin-top: 8px; }
.estimate summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; list-style: none; }
.estimate summary::-webkit-details-marker { display: none; }
.estimate summary::before { content: "▸ "; }
.estimate details[open] summary::before { content: "▾ "; }
.est-phases { margin: 6px 0 0; padding: 0; list-style: none; }
.est-phases li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.est-phases li:last-child { border-bottom: 0; }
.est-note { color: var(--muted); font-size: 12.5px; margin-top: 8px; line-height: 1.4; }
.est-assume { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--text); }
@media (max-width: 420px) { .est-grid { grid-template-columns: 1fr 1fr; } .est-grid .est-cell:nth-child(3) { grid-column: 1 / -1; } }

/* ---------- status chip ---------- */
.status-chip {
  flex: 0 0 auto;
  margin: 0 16px 6px;
  align-self: flex-start;
  display: inline-flex; gap: 8px; align-items: center;
  font-size: 12.5px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px;
}
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- composer ---------- */
.composer {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + var(--sab));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer-form { display: flex; gap: 8px; align-items: flex-end; }
.composer-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 16px; /* 16px avoids iOS zoom on focus */
  line-height: 1.4;
  max-height: 160px;
  background: var(--bg);
  outline: none;
}
.composer-input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.composer-input:disabled { opacity: .7; }
.send-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; transition: transform .1s, opacity .15s;
}
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(.95); }
.send-btn svg, .attach-btn svg { pointer-events: none; } /* taps always land on the button itself */
.attach-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; cursor: pointer;
}
.attach-btn:hover:not(:disabled) { color: var(--accent); background: var(--bg); }
.attach-btn:disabled { opacity: .45; cursor: default; }
.att-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 8px; }
.att-list { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.att-chip {
  display: inline-flex; align-items: center; gap: 2px; max-width: 240px; padding: 4px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); font-size: 12.5px; color: var(--text);
}
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-x { border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 0 0 6px; cursor: pointer; }
.composer-hint { font-size: 11px; color: var(--muted); padding: 6px 4px 0; min-height: 14px; text-align: center; }
body.embed .composer-hint { display: none; }

/* ---------- misc ---------- */
.fade-in { animation: pop .25s ease-out; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (prefers-color-scheme: dark) {
  body:not(.embed) { --bg: #0f1220; --surface: #171a2b; --text: #e7e9f3; --muted: #9aa1b5; --border: #2a2f45; --bubble: #232841; }
  body:not(.embed) .row.owner .bubble { background: #0f2a1a; border-color: #1f5a37; color: #d9f5e3; }
  body:not(.embed) .banner { background: #2a1d0b; border-color: #5a3a10; color: #fde7c7; }
  body:not(.embed) .banner.ok { background: #0f2a1a; border-color: #1f5a37; color: #d9f5e3; }
  body:not(.embed) .contact-form .in { background: var(--surface); border-color: var(--border); }
  body:not(.embed) .estimate { background: var(--surface); }
  body:not(.embed) .row.error .bubble { background: #2a1010; border-color: #5a1f1f; color: #fecaca; }
}
