:root {
  --bg: #0b0f17;
  --bg-card: #131a26;
  --bg-elev: #1b2432;
  --border: #243044;
  --text: #e6edf6;
  --muted: #8a97ab;
  --accent: #4c8dff;
  --pos: #23c069;
  --neg: #ff5c6c;
  --warn: #f4b740;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; }
.brand p { margin: 2px 0 0; }
.topbar-actions { display: flex; align-items: center; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 0 4px rgba(35, 192, 105, 0.15);
}
.refresh {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 20px; line-height: 1;
  cursor: pointer;
  transition: transform .3s ease;
}
.refresh.spin { transform: rotate(360deg); }

/* ---------- nav chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.chip-id {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
}
.chip-pending { opacity: .55; }
.chip-pending .chip-id { background: var(--muted); }

/* ---------- cards ---------- */
main { padding: 14px 12px 60px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  scroll-margin-top: 120px;
}
.card-head {
  display: flex; flex-direction: column; gap: 4px;
  width: 100%;
  position: relative;
  padding: 0 26px 0 0;
  margin: 0;
  background: none; border: none;
  color: inherit; font: inherit; text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card:not(.collapsed) .card-head { margin-bottom: 10px; }
.chevron {
  position: absolute; top: 2px; right: 2px;
  color: var(--muted); font-size: 13px; line-height: 1;
  transition: transform .2s ease;
}
.card:not(.collapsed) .chevron { transform: rotate(180deg); }
.card.collapsed .card-collapse { display: none; }
.card-title { display: flex; align-items: center; gap: 9px; }
.card-title h2 { font-size: 15px; margin: 0; font-weight: 620; display: flex; align-items: center; gap: 8px; }
.num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.subtitle { color: var(--muted); font-size: 12px; padding-left: 32px; }

.badge {
  min-width: 46px; text-align: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  background: var(--bg-elev); color: var(--muted);
  border: 1px solid var(--border);
}
.badge.ok  { background: rgba(35,192,105,.14); color: var(--pos); border-color: transparent; }
.badge.err { background: rgba(255,92,108,.14); color: var(--neg); border-color: transparent; }
.badge.pending { background: rgba(244,183,64,.12); color: var(--warn); border-color: transparent; }

/* ---------- kpis ---------- */
.kpis { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.kpis:empty { display: none; }
.kpi {
  flex: 1 1 auto; min-width: 96px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
}
.kpi .k { color: var(--muted); font-size: 11px; }
.kpi .v { font-size: 17px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .v.pos { color: var(--pos); }
.kpi .v.neg { color: var(--neg); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--border); }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
thead th {
  position: sticky; top: 0;
  background: var(--bg-elev);
  color: var(--muted);
  text-align: left;
  padding: 8px 10px;
  white-space: nowrap;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 7px 10px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(36,48,68,.5);
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }
tbody td.cell-num { text-align: left; }
tbody td.pos { color: var(--pos); }
tbody td.neg { color: var(--neg); }
.table-name { color: var(--muted); font-size: 11px; margin: 4px 2px 6px; }
.empty { color: var(--muted); font-size: 13px; padding: 16px 4px; text-align: center; }

/* ---------- misc ---------- */
.card-foot { margin-top: 8px; }
.msg { font-size: 13px; padding: 12px; border-radius: 10px; background: var(--bg-elev); }
.msg.err { color: var(--neg); }
.msg.pending { color: var(--warn); }
.skeleton {
  height: 60px; border-radius: 10px;
  background: linear-gradient(90deg, var(--bg-elev) 25%, #202b3c 37%, var(--bg-elev) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  text-align: center;
}
.login-question {
  font-size: 32px; font-weight: 700; margin: 0 0 40px;
  letter-spacing: .2px;
}
.login-error {
  background: rgba(255,92,108,.14); color: var(--neg);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; margin-bottom: 16px;
}
.login-row { position: relative; display: flex; justify-content: center; }
.login-input {
  flex: 0 0 auto; width: 200px; max-width: 60vw;
  background: var(--bg-elev); border: none;
  color: var(--text); border-radius: 12px;
  padding: 13px 14px; font-size: 15px; text-align: center;
}
.login-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(76,141,255,.35); }
.login-btn {
  position: absolute; top: 0; bottom: 0;
  left: 50%; margin-left: 112px;   /* half input width (100) + gap (12) */
  width: 52px;
  background: linear-gradient(135deg, #7c5cff 0%, #4c8dff 55%, #23c0d8 100%);
  color: #fff; border: none;
  border-radius: 12px; padding: 0; font-size: 16px; font-weight: 800;
  letter-spacing: .5px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(76,141,255,.45), inset 0 1px 0 rgba(255,255,255,.35);
  animation: login-breathe 2.4s ease-in-out infinite;
  transition: transform .12s ease, filter .12s ease;
}
.login-btn:hover { filter: brightness(1.1); }
.login-btn:active { transform: scale(.94); }
@keyframes login-breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 6px 16px rgba(76,141,255,.35), inset 0 1px 0 rgba(255,255,255,.3);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 10px 26px rgba(124,92,255,.6), inset 0 1px 0 rgba(255,255,255,.45);
  }
}
@media (prefers-reduced-motion: reduce) {
  .login-btn { animation: none; }
}
.logout {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--muted); text-decoration: none; font-size: 16px;
  margin-left: 8px;
}
