:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1f1f1d;
  --muted: #6b6a66;
  --faint: #9a9893;
  --border: #e3e2de;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --ok: #3b6d11;
  --ok-bg: #eaf3de;
  --warn: #854f0b;
  --warn-bg: #faeeda;
  --neutral-bg: #f1efe8;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 900px; margin: 0 auto; background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; }
.title { font-weight: 600; font-size: 15px; }
.subtitle { font-size: 12px; color: var(--muted); }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn.primary:hover { background: #3a3a37; }
.btn:disabled { opacity: .5; cursor: default; }

.thread { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; }
.welcome { margin: auto 0; text-align: center; color: var(--muted); }
.welcome h2 { color: var(--text); font-weight: 500; font-size: 20px; margin: 0 0 6px; }
.welcome p { margin: 0; }

.msg-user { align-self: flex-end; max-width: 80%; background: var(--accent-bg); color: #0c447c; padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg-bot { display: flex; gap: 10px; align-items: flex-start; }
.avatar { width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; background: var(--neutral-bg); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.bot-body { flex: 1; min-width: 0; }
.bot-text { line-height: 1.55; margin: 3px 0 10px; }
.bot-text p { margin: 0 0 8px; }
.bot-error { color: #a32d2d; white-space: pre-wrap; }
.thinking { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.dots span { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite both; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.loc-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.loc-map { height: 280px; background: var(--neutral-bg); }
.loc-list { list-style: none; margin: 0; padding: 0; }
.loc-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.loc-name { font-weight: 500; }
.loc-van { color: var(--muted); font-weight: 400; }
.loc-addr { font-size: 13px; color: var(--muted); }
.loc-meta { font-size: 12px; color: var(--faint); margin-top: 2px; }
.loc-right { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 6px; white-space: nowrap; }
.badge.moving { background: var(--accent-bg); color: #0c447c; }
.badge.stopped { background: var(--ok-bg); color: var(--ok); }
.badge.stale, .badge.none { background: var(--warn-bg); color: var(--warn); }
.loc-row.is-stale { background: #fcfbf8; }
.loc-foot { font-size: 12px; color: var(--faint); padding: 8px 14px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; }
.pin-label { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; font-size: 12px; white-space: nowrap; box-shadow: none; }

.composer-wrap { border-top: 1px solid var(--border); padding: 10px 16px 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.chip:hover { color: var(--text); border-color: #cfcdc7; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; font: inherit; font-size: 15px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); max-height: 140px; outline: none; }
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.form-error { color: #a32d2d; font-size: 13px; min-height: 0; margin-top: 4px; }


/* auth + admin pages */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; }
.auth-brand { margin-bottom: 18px; }
.auth-title { font-size: 20px; font-weight: 500; margin: 0 0 12px; }
.page { max-width: 1000px; margin: 0 auto; min-height: 100vh; background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.page-body { padding: 20px 16px 40px; }
.page-body h1 { font-size: 22px; font-weight: 500; margin: 0 0 14px; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel h2 { font-size: 16px; font-weight: 500; margin: 0 0 12px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form.narrow { max-width: 380px; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form select, .row-form select { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.form input:focus, .form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.btn.block { justify-content: center; width: 100%; padding: 10px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.alert.error { background: #fcebeb; color: #791f1f; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.temp { background: var(--warn-bg); color: var(--warn); }
.temp-pw { display: inline-block; margin: 4px 0 4px 6px; padding: 3px 8px; background: #fff; border: 1px solid #ecd9b8; border-radius: 6px; font-size: 16px; letter-spacing: .5px; color: var(--text); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border); }
table.users td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users tr.inactive td { color: var(--faint); }
.row-form { display: inline; margin: 0; }
.actions { white-space: nowrap; text-align: right; }
.badge.fail { background: #fcebeb; color: #a32d2d; }
table.checks { width: 100%; border-collapse: collapse; font-size: 14px; }
table.checks th { text-align: left; font-weight: 500; font-size: 13px; padding: 12px 6px 6px; border-bottom: 1px solid var(--border); }
table.checks td { padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ck-icon { width: 52px; }
.panel h2 .badge { margin-left: 6px; vertical-align: 2px; }
.btn.small-btn { padding: 4px 9px; font-size: 12px; }

@media (max-width: 600px) {
  .hide-sm, .subtitle { display: none; }
  .topbar { padding: 8px 12px; }
  .who { gap: 4px; }
  .msg-user { max-width: 90%; }
  .loc-map { height: 220px; }
}
