/* LocalMind on the phone: the same palette as the desktop app, laid out for a thumb. */
:root {
  --bg: #0D0F14;
  --surface: #151923;
  --elevated: #1C2130;
  --hover: #242A3B;
  --border: #272D3D;
  --text: #E6EAF2;
  --text-2: #B4BDCD;
  --muted: #7A8599;
  --accent: #4F8EF7;
  --accent-strong: #3F7BE6;
  --accent-soft: #1B2A47;
  --green: #3ECF8E;
  --amber: #F5A623;
  --red: #E5685F;
  --code: #0F131C;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input, select, textarea {
  background: var(--elevated); border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; /* 16px stops iPhone Safari from zooming in on focus */
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--elevated); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { height: 40px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none; border-radius: 10px; border: 0; background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---- sign in ---- */
.login {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
}
.login-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px;
  padding: 28px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
}
.brand-mark { width: 56px; height: 56px; border-radius: 14px; align-self: center; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; text-align: center; letter-spacing: -.01em; }
.login-card > p.muted { margin: 0; text-align: center; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input { height: 46px; padding: 0 14px; color: var(--text); }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 14px; text-align: center; }

/* ---- app shell ---- */
.app { height: 100vh; height: 100dvh; display: flex; overflow: hidden; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: min(84vw, 300px);
  display: flex; flex-direction: column; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .2s ease;
}
.sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, .6); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding-left: 6px; }
.brand-name { font-weight: 700; letter-spacing: -.01em; }
.section-label { margin: 10px 6px 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sidebar .btn svg { width: 18px; height: 18px; }
.chat-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-list li {
  display: flex; align-items: center; gap: 4px; border-radius: 10px;
}
.chat-list li:hover { background: var(--hover); }
.chat-list li.active { background: var(--elevated); box-shadow: inset 3px 0 0 var(--accent); }
.chat-open {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; padding: 11px 10px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text-2); font-size: 14px;
}
.chat-list li.active .chat-open { color: var(--text); }
.chat-delete {
  flex: none; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 8px; color: var(--muted);
}
.chat-delete svg { width: 17px; height: 17px; }
.chat-delete:hover { color: var(--red); }
.empty-list { color: var(--muted); font-size: 14px; margin: 8px 6px; }

.scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .5); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px 6px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.title { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.status {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 12px; color: var(--muted); padding-right: 6px;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="ok"] { color: var(--green); }
.status[data-state="ok"] .dot { background: var(--green); }
.status[data-state="offline"], .status[data-state="auth"] { color: var(--red); }
.status[data-state="offline"] .dot, .status[data-state="auth"] .dot { background: var(--red); }

/* ---- model bar ---- */
.model-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: none;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.model-bar select { flex: 1; min-width: 0; height: 40px; padding: 0 10px; }
.model-bar .btn { min-width: 84px; }
.model-note { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--muted); min-height: 1em; }

/* ---- messages ---- */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  padding: 18px 16px 12px; overscroll-behavior: contain;
}
.thread { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { min-width: 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 16px 16px 4px 16px;
  background: var(--accent-soft); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant { display: flex; gap: 12px; align-items: flex-start; }
.avatar {
  width: 28px; height: 28px; flex: none; border-radius: 8px; margin-top: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--elevated); border: 1px solid var(--border); color: var(--accent); font-size: 13px; font-weight: 700;
}
.reply { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.reply p { margin: 0 0 10px; }
.reply p:last-child, .reply ul:last-child, .reply ol:last-child, .reply pre:last-child { margin-bottom: 0; }
.reply h4 { margin: 14px 0 6px; font-size: 15px; font-weight: 650; }
.reply ul, .reply ol { margin: 0 0 10px; padding-left: 22px; }
.reply li { margin: 2px 0; }
.reply blockquote { margin: 0 0 10px; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--text-2); }
.reply code { font: 13px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; background: var(--code); padding: 1px 5px; border-radius: 5px; }
.reply pre {
  margin: 8px 0 12px; padding: 12px; background: var(--code); border: 1px solid var(--border);
  border-radius: 10px; overflow-x: auto; max-width: 100%;
}
.reply pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; white-space: pre; }
.reply a { color: var(--accent); }

.thinking { margin: 0 0 8px; }
.thinking summary { cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "\25B8"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.thinking[open] summary::before { transform: rotate(90deg); }
.thinking pre {
  margin: 8px 0 0; padding: 10px; background: #0B1424; border-radius: 10px; color: var(--muted);
  font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow-y: auto;
}

.progress { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; min-height: 24px; }
.dots { display: inline-flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sources a {
  max-width: 100%; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; color: var(--accent); text-decoration: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.note { margin-top: 8px; font-size: 13px; color: var(--muted); }
.error-box {
  margin-top: 8px; padding: 8px 12px; border-left: 3px solid var(--red); border-radius: 6px;
  background: rgba(229, 104, 95, .08); color: var(--red); font-size: 14px;
}

.welcome { text-align: center; margin: 12vh auto 0; max-width: 420px; }
.welcome .brand-mark { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px; display: block; }
.welcome h3 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.01em; }
.welcome p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.suggest { display: grid; gap: 8px; }
.suggest button {
  text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 14px;
}
.suggest button:hover { background: var(--elevated); color: var(--text); }

.notice { margin: 4px 0; text-align: center; font-size: 13px; color: var(--muted); }
.table-wrap { margin: 8px 0 12px; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.reply table { width: 100%; border-collapse: collapse; font-size: 13px; }
.reply th, .reply td { padding: 7px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.reply th { background: var(--elevated); color: var(--text-2); font-weight: 600; white-space: nowrap; }
.reply tr:last-child td { border-bottom: 0; }

/* ---- composer ---- */
.composer-wrap {
  flex: none; background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
}
.chips { display: flex; gap: 8px; margin: 0 auto 8px; max-width: 760px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.composer { display: flex; align-items: flex-end; gap: 8px; max-width: 760px; margin: 0 auto; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 160px; padding: 11px 14px;
  line-height: 1.4; border-radius: 22px;
}
.send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.send:hover { background: var(--accent-strong); }
.send:disabled { opacity: .4; cursor: default; }
.send svg { width: 20px; height: 20px; }
.send .i-stop { display: none; }
.send[data-mode="stop"] { background: var(--red); }
.send[data-mode="stop"] .i-send { display: none; }
.send[data-mode="stop"] .i-stop { display: block; fill: currentColor; stroke: none; }

/* ---- wide screens: chats in a fixed column beside the conversation ---- */
@media (min-width: 900px) {
  .sidebar {
    position: static; transform: none; width: 280px; flex: none; box-shadow: none;
    padding: 18px 14px;
  }
  .sidebar.open { box-shadow: none; }
  .menu-only, #menu-btn, .scrim { display: none !important; }
  .messages { padding: 24px 32px 16px; }
  .model-bar, .topbar { padding-left: 24px; padding-right: 24px; }
  .composer-wrap { padding-left: 24px; padding-right: 24px; }
}
