/* ELAN Finance Chat - phone-first PWA.
   Palette and brand treatment follow the finance-dashboard / ELAN Insight
   conventions: same ELAN blue accent as the dashboard and ELAN Insight, so
   the three apps feel like one family. The installed icon is told apart by
   its shape (speech bubble), not by a different brand colour. */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2f5fd8;
  --accent-dark: #24499f;
  --accent-soft: #eaf0ff;
  --green: #15803d;
  --red: #d1453b;
  --yellow: #b8860b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.hidden { display: none !important; }

.screen { height: 100%; }

/* ---------------- Login ---------------- */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 6px 24px rgba(20, 24, 33, 0.06);
}
.brand { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.brand-login { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.brand-login .brand-sub { font-size: 1.55rem; white-space: nowrap; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-logo.small { height: 22px; }
.brand-sub {
  font-weight: 600;
  font-size: 1.7rem;
  color: #000;
  line-height: 1;
  position: relative;
  top: -2px;
}
.login-hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }
#login-form { display: flex; flex-direction: column; gap: 10px; }

input[type="password"], input[type="text"], textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button { font: inherit; cursor: pointer; }
.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
}
.primary:active { background: var(--accent-dark); }
.primary.small { padding: 7px 12px; font-size: 0.85rem; border-radius: 8px; }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
}
.ghost.small { font-size: 0.85rem; padding: 6px 10px; }
.error { color: var(--red); font-size: 0.9rem; margin: 12px 0 0; }

/* ---------------- Chat shell ---------------- */
.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 10px 8px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.thread-title {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  position: relative;
  background: transparent;
  border: none;
  padding: 8px;
  border-radius: 10px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: #eef0f3; }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.icon-btn[aria-pressed="false"] .wave, .icon-btn[aria-pressed="false"] .wave2 { display: none; }
.icon-btn.mic.recording { color: #fff; background: var(--red); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(209,69,59,0.5); } 50% { box-shadow: 0 0 0 8px rgba(209,69,59,0); } }

.badge {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.banner {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-bottom: 1px solid #ccd9f7;
  padding: 10px 14px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.banner button { background: none; border: none; color: inherit; font-weight: 600; text-decoration: underline; padding: 0; }
.banner.warn { background: #fdf6e3; color: #7c5b09; border-bottom-color: #f0e2bb; }

/* ---------------- Messages ---------------- */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.day-sep {
  align-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  background: #eceef1;
  border-radius: 20px;
  padding: 3px 12px;
  margin: 4px 0;
}
.msg {
  max-width: 88%;
  border-radius: var(--radius);
  padding: 10px 13px;
  line-height: 1.45;
  font-size: 0.97rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg.system {
  align-self: center;
  background: #fdf6e3;
  border: 1px solid #f0e2bb;
  color: #7c5b09;
  font-size: 0.88rem;
  max-width: 94%;
}
.msg.unread { box-shadow: 0 0 0 2px var(--accent-soft); }
.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 8px; padding-left: 20px; }
.msg li { margin: 2px 0; }
.msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.87em;
  background: rgba(31, 36, 48, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg.user code { background: rgba(255, 255, 255, 0.2); }
.msg pre {
  background: rgba(31, 36, 48, 0.06);
  padding: 9px 11px;
  border-radius: 9px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg pre code { background: none; padding: 0; }
.msg a { color: inherit; text-decoration: underline; }
.msg h3 { font-size: 1rem; margin: 6px 0 4px; }
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.74rem;
  color: var(--muted);
}
.msg.user .msg-meta { color: rgba(255, 255, 255, 0.85); justify-content: flex-end; }
.msg-meta button {
  background: none;
  border: none;
  padding: 2px;
  color: inherit;
  display: inline-flex;
  align-items: center;
}
.msg-meta svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.msg-meta .speaking { color: var(--accent); }

.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.att {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: rgba(31, 36, 48, 0.06);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 0.87rem;
  color: inherit;
  text-decoration: none;
}
.msg.user .att { background: rgba(255, 255, 255, 0.18); }
.att svg { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { color: inherit; opacity: 0.7; font-size: 0.78rem; flex: 0 0 auto; }
.att img.thumb { width: 100%; border-radius: 9px; display: block; margin-top: 6px; }

/* Pending / working state */
.working {
  align-self: flex-start;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 0.9rem;
  color: var(--muted);
  max-width: 88%;
}
.working .dots span {
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.4s infinite both;
}
.working .dots span:nth-child(2) { animation-delay: .2s; }
.working .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.working-note { color: var(--text); margin-top: 5px; font-size: 0.87rem; }
.working-row { display: flex; align-items: center; gap: 8px; }
.working .cancel { margin-left: auto; }

.status-chip { font-size: 0.72rem; }
.status-chip.error { color: var(--red); font-weight: 600; }
.status-chip.cancelled { text-decoration: line-through; }

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 20px;
}
.empty-state strong { color: var(--text); display: block; font-size: 1.05rem; margin-bottom: 6px; }

/* ---------------- Suggestions ---------------- */
.suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px 8px;
  flex: 0 0 auto;
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 13px;
  font-size: 0.85rem;
  color: var(--text);
}

/* ---------------- Composer ---------------- */
.composer {
  flex: 0 0 auto;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
#input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  border-radius: 20px;
  padding: 10px 14px;
  line-height: 1.4;
}
.send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:disabled { background: #c9ced6; }

.staged-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 16px;
  padding: 5px 10px;
  font-size: 0.8rem;
  max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { background: none; border: none; color: inherit; font-size: 1rem; line-height: 1; padding: 0 2px; }

.mic-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 8px;
  font-size: 0.85rem;
  color: var(--red);
}
.mic-status .interim { color: var(--muted); font-style: italic; }

/* ---------------- Drawer ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 24, 0.35);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(86vw, 340px);
  background: var(--card);
  border-right: 1px solid var(--border);
  z-index: 50;
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.thread-list { flex: 1 1 auto; overflow-y: auto; }
.thread-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.thread-row.active { background: var(--accent-soft); }
.thread-main { flex: 1 1 auto; min-width: 0; }
.thread-row .name { font-weight: 600; font-size: 0.93rem; display: flex; align-items: center; gap: 6px; }
.thread-row .name span.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.thread-row .preview {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-row .when { color: var(--muted); font-size: 0.72rem; margin-top: 3px; }
.thread-actions { display: flex; gap: 6px; margin-top: 4px; }
.thread-actions button {
  background: #f2f4f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 7px 10px;
  font-size: 0.78rem;
}
.thread-actions button:active { background: #e6e9ee; }
.drawer-foot {
  border-top: 1px solid var(--border);
  padding: 12px 14px calc(var(--safe-bottom) + 12px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.switch-row { display: flex; align-items: center; gap: 9px; font-size: 0.88rem; color: var(--text); }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.drawer-note { color: var(--muted); font-size: 0.75rem; margin: 0; }

.install-hint {
  position: fixed;
  left: 10px; right: 10px;
  top: calc(var(--safe-top) + 56px);
  background: #1f2430;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 60;
}
.install-hint .ghost { color: #fff; border-color: rgba(255,255,255,0.4); }

/* Roomier on tablets/desktop, still the same single-column chat. */
@media (min-width: 760px) {
  .chat { max-width: 780px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); background: var(--bg); }
  .msg { max-width: 76%; }
}

.drawer-head-title { flex: 1 1 auto; }

/* Anmeldung ohne Passwort: PIN-Selbstbedienung im Menü */
.login-hint.small { font-size: 0.8rem; margin-top: 14px; }
.pin-box { display: flex; flex-direction: column; gap: 8px; }
.pin-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.pin-box > .ghost { align-self: flex-start; }
.pin-form { display: flex; flex-direction: column; gap: 8px; }
.pin-form input { padding: 10px 12px; font-size: 0.95rem; }
.pin-actions { display: flex; gap: 8px; }
.pin-msg { margin: 0; font-size: 0.8rem; color: var(--muted); }
.pin-msg.ok { color: var(--green); }
.pin-msg.err { color: var(--red); }
