:root {
  --bg: #0b1220;
  --bg-2: #111a2e;
  --surface: #16203a;
  --surface-2: #1d2a48;
  --line: #263456;
  --text: #eaf0ff;
  --muted: #8da2c8;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 16px;
  --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%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #16213f 0%, var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}
h1 { font-size: 1.15rem; margin: 0; font-weight: 700; letter-spacing: .2px; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.hidden { display: none !important; }

.screen { min-height: 100dvh; max-width: 560px; margin: 0 auto; }

/* ---------- Login ---------- */
#login {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  gap: 20px;
}
.login-card {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(160deg, var(--primary), #1e3a8a);
  box-shadow: 0 10px 24px rgba(37,99,235,.45);
}
.brand-mark svg { width: 30px; height: 30px; }
.brand p { margin: 6px 0 0; font-size: .9rem; }
.auth-step { display: flex; flex-direction: column; gap: 12px; }
label { font-size: .82rem; color: var(--muted); font-weight: 600; }
input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px 14px; font-size: 1rem; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
.phone-input { position: relative; display: flex; align-items: center; }
.phone-input .cc {
  position: absolute; left: 12px; color: var(--muted); font-weight: 600;
  border-right: 1px solid var(--line); padding-right: 10px;
}
.phone-input input { padding-left: 60px; }
.otp-input { letter-spacing: .5em; text-align: center; font-size: 1.4rem; font-weight: 700; }

.btn {
  border: none; border-radius: 12px; padding: 14px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform .05s, opacity .15s, background .15s; color: #fff;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: linear-gradient(160deg, var(--primary), var(--primary-2)); }
.btn[disabled] { opacity: .55; cursor: default; }
.link { background: none; border: none; color: var(--primary); font-size: .85rem; cursor: pointer; padding: 4px; }
.link[disabled] { color: var(--muted); cursor: default; }
.otp-actions { display: flex; justify-content: space-between; align-items: center; }
.auth-msg { margin: 14px 2px 0; font-size: .85rem; min-height: 1.1em; }
.auth-msg.error { color: var(--red); }
.auth-msg.ok { color: var(--green); }
.auth-msg.dev { color: var(--amber); }
.footer-note { font-size: .75rem; }

/* ---------- Dashboard ---------- */
#app { padding: calc(14px + var(--safe-top)) 16px calc(28px + var(--safe-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.topbar .muted { margin: 2px 0 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  position: relative; overflow: hidden;
}
.card-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(59,130,246,.14); color: #7eb0ff;
}
.card-icon svg { width: 20px; height: 20px; }
.card-value { font-size: 1.9rem; font-weight: 800; margin: 12px 0 2px; font-variant-numeric: tabular-nums; }
.card-label { font-size: .8rem; color: var(--muted); font-weight: 600; }

.search { display: block; }
.segmented {
  display: flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; margin-bottom: 10px;
}
.seg {
  flex: 1; border: none; background: none; color: var(--muted); font-weight: 700;
  padding: 9px; border-radius: 9px; cursor: pointer; font-size: .9rem; transition: .15s;
}
.seg.active { background: var(--primary); color: #fff; }
.search-box { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 13px; color: var(--muted); display: grid; place-items: center; pointer-events: none; }
.search-icon svg { width: 18px; height: 18px; }
.search-box input { padding-left: 42px; padding-right: 42px; }
.clear-btn {
  position: absolute; right: 8px; width: 28px; height: 28px; border-radius: 8px;
  border: none; background: var(--surface-2); color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.clear-btn svg { width: 15px; height: 15px; }
.search-btn { width: 100%; margin-top: 10px; }
.hint { text-align: center; color: var(--muted); font-size: .88rem; padding: 36px 16px; }

.results { margin-top: 14px; }
.results-meta { font-size: .78rem; color: var(--muted); margin: 0 2px 8px; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: background .12s, transform .05s;
}
.result-row:active { transform: scale(.99); background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: .8rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-chevron { color: var(--muted); display: grid; place-items: center; }
.row-chevron svg { width: 18px; height: 18px; }
.badge {
  font-size: .68rem; font-weight: 800; padding: 3px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.badge.active { background: rgba(34,197,94,.18); color: #6ee7a8; }
.badge.suspended { background: rgba(245,158,11,.18); color: #fbbf24; }
.badge.deactivated { background: rgba(239,68,68,.18); color: #fca5a5; }
.badge.unknown { background: rgba(141,162,200,.18); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- Detail sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(3,7,18,.6); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; background: var(--bg-2);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: none;
  padding: 8px 20px calc(24px + var(--safe-bottom)); max-height: 88dvh; overflow-y: auto;
  animation: slideUp .22s cubic-bezier(.2,.8,.2,1);
}
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 14px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.detail-title { font-size: 1.1rem; font-weight: 800; }
.detail-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.detail-hero {
  margin: 16px 0; padding: 16px; border-radius: 14px; text-align: center;
  background: linear-gradient(160deg, rgba(59,130,246,.18), rgba(37,99,235,.06));
  border: 1px solid var(--line);
}
.detail-hero .v { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.detail-hero .l { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.field { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-top: 10px; }
.detail-grid .field { margin-top: 0; }
.field.full { grid-column: 1 / -1; }
.field .k { font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.field .val { font-size: .95rem; font-weight: 600; margin-top: 3px; word-break: break-word; }
.field .val.agentid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.05rem; letter-spacing: .02em; }
.detail-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.badge.type { background: rgba(59,130,246,.16); color: #93c0ff; }
.sheet .btn { width: 100%; margin-top: 18px; background: var(--surface-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 12px; z-index: 80; font-size: .9rem; max-width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: fade .15s;
}

.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }
