:root {
  --bg: #0f1218;
  --panel: #151a22;
  --raised: #1c222c;
  --line: #272e3a;
  --text: #e7eaf0;
  --muted: #8a93a5;
  --accent: #8c9cff;
  --accent-ink: #0f1218;
  --mine: #2a3163;
  --danger: #ff8d9b;
  --online: #58d68d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- Shared controls ---------- */
.btn {
  padding: 8px 14px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #252c38; border-color: #343c4b; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #a3b0ff; border-color: #a3b0ff; }
.btn.danger { color: var(--danger); }
.btn.danger-solid { background: #c2485c; border-color: #c2485c; color: #fff; font-weight: 600; }
.btn.danger-solid:hover { background: #d4586c; border-color: #d4586c; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.wide { width: 100%; padding-block: 11px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn:disabled { opacity: .5; cursor: default; }

.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.fine { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.counter { margin-top: 4px; color: var(--muted); font-size: 12px; text-align: right; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.form-error { min-height: 1.3em; margin: 0; color: var(--danger); font-size: 13.5px; }
.form-ok { margin: 0; color: var(--online); font-size: 13.5px; }
.form-ok:empty { display: none; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Avatars ---------- */
.avatar {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background-color: var(--raised);
  background-size: cover;
  background-position: center;
  color: #f1f3fa;
  font-weight: 600;
  user-select: none;
}
.avatar.xs { width: 28px; height: 28px; font-size: 11px; }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.avatar.md { width: 48px; height: 48px; font-size: 17px; }
.avatar.xl { width: 96px; height: 96px; font-size: 34px; }
.avatar.on::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--panel);
}

/* ---------- Log in / sign up ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { font-size: 21px; font-weight: 650; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: var(--bg); border-radius: 12px; }
.tab { padding: 8px; background: transparent; border: 0; border-radius: 9px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--raised); color: var(--text); font-weight: 600; }
.or { display: flex; align-items: center; gap: 12px; margin: 2px 0 14px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
#googleBtn { display: flex; justify-content: center; min-height: 44px; }
.auth h2 { font-size: 17px; }
.intro { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100vh; height: 100dvh; }

.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 8px; }
.me-btn { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 4px 8px 4px 4px; background: transparent; border: 0; border-radius: 12px; cursor: pointer; text-align: left; }
.me-btn:hover { background: var(--raised); }
.me-btn .name { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; flex: none; }
.search { padding: 4px 12px 10px; }
.search input { width: 100%; padding: 9px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.search input:focus { outline: none; border-color: var(--accent); }

.conv-list { flex: 1; min-height: 0; margin: 0; padding: 0 8px 12px; list-style: none; overflow-y: auto; }
.conv-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; background: transparent; border: 0; border-radius: 12px; cursor: pointer; text-align: left; }
.conv-btn:hover { background: var(--raised); }
.conv.active .conv-btn { background: var(--raised); }
.conv-text { flex: 1; min-width: 0; }
.conv-top, .conv-bottom { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { flex: none; color: var(--muted); font-size: 12px; }
.conv-preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; min-width: 20px; padding: 0 6px; background: var(--accent); border-radius: 999px; color: var(--accent-ink); font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.list-empty { padding: 24px 22px; color: var(--muted); text-align: center; }

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.pane-empty { margin: auto; padding: 24px; max-width: 32ch; color: var(--muted); text-align: center; }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.back-btn { display: none; margin-left: -8px; }
.head-info { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; padding: 4px 8px; background: transparent; border: 0; border-radius: 12px; cursor: pointer; text-align: left; }
.head-info:hover { background: var(--raised); }
.head-info .t { min-width: 0; }
.head-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-sub.live { color: var(--online); }
.conn { color: var(--danger); font-size: 13px; }

.scroller { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 20px 8px; overscroll-behavior: contain; }
.older { display: block; margin: 0 auto 10px; }
#list { display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 18px 0 6px; padding: 3px 12px; background: var(--raised); border-radius: 999px; color: var(--muted); font-size: 12.5px; }

.row { display: flex; align-items: flex-end; gap: 8px; max-width: min(640px, 90%); }
.row.first { margin-top: 12px; }
.row.mine { align-self: flex-end; flex-direction: row-reverse; }
.row .avatar { visibility: visible; }
.row.cont .avatar { visibility: hidden; }
.body { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.mine .body { align-items: flex-end; }
.uname { margin: 0 2px 3px; font-size: 12.5px; font-weight: 600; }

.bubble { max-width: 100%; padding: 7px 11px 6px; background: var(--raised); border-radius: 14px 14px 14px 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.mine .bubble { background: var(--mine); color: #eef0ff; border-radius: 14px 14px 4px 14px; }
.bubble .t { float: right; margin: 8px 0 -3px 12px; font-size: 11px; opacity: .6; white-space: nowrap; }
.bubble.image { padding: 4px 4px 3px; }
.bubble.image .t { display: block; float: none; margin: 2px 6px 0 0; text-align: right; }
.bubble img { display: block; max-width: min(340px, 100%); max-height: 360px; border-radius: 10px; background: var(--panel); cursor: zoom-in; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-width: 0; max-height: 140px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; line-height: 1.4; resize: none; overflow-y: auto; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer .send { height: 40px; padding: 0 18px; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
dialog::backdrop { background: rgba(6, 8, 12, .68); }
.dlg { display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.dlg h2 { font-size: 18px; }
.dlg h3 { font-size: 15px; }
.pic { display: flex; align-items: center; gap: 16px; }
.found { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.found .info { flex: 1; min-width: 0; }
.who-name { font-weight: 600; overflow-wrap: anywhere; }
.who-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; background: var(--raised); border: 1px solid var(--line); border-radius: 999px; font-size: 13.5px; }
.chips button { width: 22px; height: 22px; padding: 0; background: transparent; border: 0; border-radius: 50%; color: var(--muted); cursor: pointer; }
.chips button:hover { background: var(--line); color: var(--text); }
.members { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.members li { display: flex; align-items: center; gap: 10px; }
.members .info { flex: 1; min-width: 0; }
.tag { display: inline-block; margin-left: 6px; padding: 0 7px; background: var(--raised); border-radius: 999px; color: var(--muted); font-size: 11.5px; }
.member-actions { display: flex; flex: none; gap: 6px; }

.lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(6, 8, 12, .88); cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: 92px; z-index: 60; max-width: 90vw; padding: 10px 16px; transform: translateX(-50%); background: #2b1f26; border: 1px solid #5a3340; border-radius: 10px; color: #ffd5db; font-size: 14px; }

/* ---------- Small screens: one pane at a time ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { border-right: 0; }
  .pane { display: none; }
  .app.chat-open .pane { display: flex; }
  .app.chat-open .side { display: none; }
  .back-btn { display: inline-grid; }
  .row { max-width: 94%; }
  .scroller { padding-inline: 12px; }
  .dlg { padding: 20px; }
}

/* ---------- Reply, edit, forward, menu ---------- */
.bubble { position: relative; }
.mbtn { position: absolute; top: 3px; right: 3px; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; background: rgba(0, 0, 0, .28); border: 0; border-radius: 8px; color: inherit; cursor: pointer; opacity: 0; }
.bubble:hover .mbtn, .mbtn:focus-visible { opacity: .85; }
@media (hover: none) { .mbtn { opacity: .55; } }
.bubble.deleted { color: var(--muted); font-style: italic; }
.mine .bubble.deleted { color: #b3b8dc; }
.fwd { display: block; margin-bottom: 3px; font-size: 12px; font-style: italic; opacity: .7; }
.quote { display: block; width: 100%; margin: 0 0 5px; padding: 5px 9px; text-align: left; background: rgba(0, 0, 0, .22); border: 0; border-left: 3px solid var(--accent); border-radius: 8px; color: inherit; cursor: pointer; }
.q-name { font-size: 12.5px; font-weight: 600; }
.q-text { max-width: 260px; font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote.gone .q-text { font-style: italic; }
.row.flash .bubble { animation: flash 1.4s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }

.compose-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.bar-text { flex: 1; min-width: 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.bar-title { color: var(--accent); font-size: 12.5px; font-weight: 600; }
.bar-snippet { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu { position: fixed; z-index: 40; min-width: 172px; padding: 6px; background: var(--raised); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45); }
.menu button { display: block; width: 100%; padding: 8px 12px; background: transparent; border: 0; border-radius: 8px; text-align: left; cursor: pointer; }
.menu button:hover { background: #252c38; }
.menu button.danger { color: var(--danger); }

.fw-preview { padding: 8px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick { max-height: 260px; margin: 0; padding: 0; list-style: none; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.pick label { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.pick label:hover { background: var(--raised); }
.pick input { accent-color: var(--accent); }

/* ---------- Profile card and banner ---------- */
.pv { position: relative; margin-bottom: 48px; }
.banner { height: 112px; background-color: var(--raised); background-size: cover; background-position: center; border-radius: 14px; }
.pv-avatar { position: absolute; left: 16px; bottom: -46px; border: 4px solid var(--panel); }
.pcard-name { margin: 0; font-size: 19px; font-weight: 650; overflow-wrap: anywhere; }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch { width: 28px; height: 28px; padding: 0; border: 2px solid transparent; border-radius: 50%; cursor: pointer; }
.swatch.sel { border-color: var(--text); }
.swatches input[type=color] { width: 34px; height: 30px; padding: 0; background: none; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }

/* ---------- Location sharing ---------- */
.field select { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.field select:focus { outline: none; border-color: var(--accent); }

.bubble.loc { padding: 4px; }
.loc-card { display: block; width: min(280px, 100%); padding: 0; text-align: left; background: transparent; border: 0; color: inherit; cursor: pointer; }
.loc-map { position: relative; width: 100%; height: 150px; overflow: hidden; background: var(--panel); border-radius: 10px; }
.loc-info { padding: 8px 6px 2px; }
.loc-title { font-weight: 600; }
.loc-sub { font-size: 13px; opacity: .75; }
.loc-card.active .loc-title::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; background: var(--online); border-radius: 50%; }
.bubble.loc .t { display: block; float: none; margin: 2px 6px 0 0; text-align: right; }

.map-tiles, .map-overlay { position: absolute; inset: 0; }
.map-tiles { filter: invert(.92) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.7); }
.loc-map .map-overlay { pointer-events: none; }
.live-map .map-overlay { touch-action: none; cursor: grab; }

.live-bar { position: fixed; top: 10px; left: 50%; z-index: 35; display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 16px); padding: 6px 8px 6px 14px; transform: translateX(-50%); background: var(--raised); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.pulse { flex: none; width: 10px; height: 10px; background: var(--online); border-radius: 50%; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(88, 214, 141, .5); } 100% { box-shadow: 0 0 0 10px rgba(88, 214, 141, 0); } }
.live-text { padding: 0; background: none; border: 0; font-size: 13.5px; text-align: left; cursor: pointer; }

.live-dlg { width: min(760px, calc(100vw - 16px)); height: min(760px, calc(100vh - 16px)); }
.live-dlg[open] { display: flex; }
.live-wrap { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.live-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.live-head .t { flex: 1; min-width: 0; }
.live-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-sub { color: var(--muted); font-size: 12.5px; }
.live-map { position: relative; flex: 1; min-height: 240px; overflow: hidden; background: var(--bg); }
.map-controls { position: absolute; top: 10px; right: 10px; z-index: 3; display: flex; flex-direction: column; gap: 6px; }
.map-btn { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; background: var(--raised); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 20px; line-height: 1; cursor: pointer; }
.map-btn:hover { background: #252c38; }
.map-btn.on { color: var(--accent); border-color: var(--accent); }
.map-attrib { position: absolute; left: 8px; bottom: 6px; z-index: 3; padding: 1px 6px; background: rgba(15, 18, 24, .75); border-radius: 6px; color: var(--muted); font-size: 11px; }
.live-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.stat { padding: 10px 12px; background: var(--panel); text-align: center; }
.stat .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12px; }
.live-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); }

.live-riders { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); }
.rider-chip { display: flex; flex: none; align-items: center; gap: 8px; padding: 6px 12px; background: var(--raised); border: 1px solid var(--line); border-radius: 999px; font-size: 13.5px; white-space: nowrap; cursor: pointer; }
.rider-chip:hover { background: #252c38; }
.rider-chip.sel { border-color: var(--accent); }
.rider-dot { width: 10px; height: 10px; border-radius: 50%; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
