:root {
  --brand: #1565C0;
  --brand-600: #1257a8;
  --brand-050: #e8f0fb;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #16202c;
  --muted: #667085;
  --line: #e3e8ef;
  --ok: #17845b;
  --warn: #b5620a;
  --danger: #c0392b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #16202f; --text: #e7edf5; --muted: #93a0b4;
    --line: #26324a; --brand-050: #16273f;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); overscroll-behavior-y: none;
}
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); color: var(--text);
}
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; box-shadow: 0 10px 30px rgba(16,24,40,.08);
}
.brand-badge {
  width: 58px; height: 58px; border-radius: 14px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 28px; margin: 0 auto 12px;
}
.auth-card h1 { text-align: center; margin: 4px 0 2px; font-size: 20px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 0 0 16px; font-size: 13px; }

.btn {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--brand);
  color: #fff; font-weight: 600; margin-top: 16px;
}
.btn:active { background: var(--brand-600); }
.btn.secondary { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.small { width: auto; padding: 8px 14px; margin: 0; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- App shell ---------- */
.app { display: none; flex-direction: column; height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  padding-top: var(--safe-top);
}
.topbar-inner { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; }
.topbar .who { font-size: 12px; opacity: .9; }
.iconbtn { background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 9px; padding: 8px 10px; font-size: 13px; }

.tabbar {
  display: flex; gap: 4px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line);
  padding: 6px 8px; position: sticky; top: calc(var(--safe-top)); z-index: 15; scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: 0 0 auto; background: transparent; border: 0; color: var(--muted);
  padding: 8px 12px; border-radius: 9px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.tab-btn.active { background: var(--brand-050); color: var(--brand); }

.content { flex: 1; overflow-y: auto; padding: 14px; padding-bottom: calc(24px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
.view { display: none; }
.view.active { display: block; }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 12px; }
.section-head h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--brand-050); color: var(--brand); font-weight: 600; }
.pill.gray { background: var(--line); color: var(--muted); }
.pill.ok { background: rgba(23,132,91,.14); color: var(--ok); }
.pill.warn { background: rgba(181,98,10,.14); color: var(--warn); }
.pill.danger { background: rgba(192,57,43,.14); color: var(--danger); }
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .t { font-weight: 600; }
.list-item .s { color: var(--muted); font-size: 13px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.form-sec { color: var(--brand); font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; margin: 18px 0 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* chat */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 190px); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 6px 2px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; margin: 6px 0; background: var(--card); border: 1px solid var(--line); }
.msg.mine { margin-left: auto; background: var(--brand); color: #fff; border-color: var(--brand); }
.msg .meta { font-size: 11px; opacity: .7; margin-bottom: 2px; }
.chat-input { display: flex; gap: 8px; padding-top: 8px; }
.chat-input input { flex: 1; }
.chat-input .btn { width: auto; margin: 0; padding: 10px 16px; }
.seg { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.seg button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(2,6,23,.5); display: none; place-items: center; z-index: 50; padding: 16px; }
.modal-back.open { display: grid; }
.modal { background: var(--card); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto; }
.modal h3 { margin: 0 0 8px; }
.fab { position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom)); width: 54px; height: 54px; border-radius: 50%; background: var(--brand); color: #fff; border: 0; font-size: 28px; box-shadow: 0 8px 20px rgba(21,101,192,.4); z-index: 30; }

/* ---------- floating chat widget ---------- */
.chat-fab {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: #fff;
  border: 0; display: grid; place-items: center; box-shadow: 0 8px 20px rgba(21,101,192,.45); z-index: 46;
}
.chat-fab .dot { position: absolute; top: 12px; right: 12px; width: 11px; height: 11px; border-radius: 50%; background: #e5484d; border: 2px solid var(--brand); display: none; }
.chat-fab.unread .dot { display: block; }
.chat-panel {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom));
  width: 340px; height: 460px; max-height: 68vh; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; overflow: hidden; z-index: 47;
  display: flex; flex-direction: column; box-shadow: 0 18px 44px rgba(2,6,23,.4);
}
.chat-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; background: var(--brand); color: #fff; font-weight: 600; }
.chat-panel-head button { background: transparent; border: 0; color: #fff; font-size: 16px; line-height: 1; }
.chat-panel .seg { padding: 8px 8px 4px; margin: 0; overflow-x: auto; flex-wrap: nowrap; }
.chat-panel .chat-scroll { flex: 1; overflow-y: auto; padding: 6px 10px; }
.chat-panel .chat-input { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.chat-panel .chat-input input { flex: 1; }
.chat-panel .chat-input .btn { width: auto; margin: 0; padding: 10px 14px; }
@media (max-width: 480px) {
  .chat-panel { right: 10px; left: 10px; width: auto; bottom: calc(82px + var(--safe-bottom)); height: 62vh; }
}

/* pull-to-refresh spinner (web) */
.toast { position: fixed; left: 50%; bottom: calc(22px + var(--safe-bottom)); transform: translateX(-50%); background: #16202c; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }
.banner { background: var(--brand-050); color: var(--brand); border: 1px solid var(--brand); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }

@media (min-width: 760px) {
  .content { max-width: 860px; margin: 0 auto; width: 100%; }
  .grid2 { grid-template-columns: 1fr 1fr; }
}
