:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e6e9f0;
  --text: #1d2230;
  --muted: #7a8194;
  --primary: #07c160;
  --primary-dark: #06a94f;
  --primary-soft: #e7f9f0;
  --danger: #f03b3b;
  --warn: #f5a623;
  --info: #4a90d9;
  --shadow: 0 8px 30px rgba(20, 30, 60, 0.08);
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--info); text-decoration: none; }
button { font-family: inherit; }
code { background: #eef1f7; padding: 1px 5px; border-radius: 4px; font-size: .78em; }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px 40px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 4px;
}
.topbar .brand { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .brand .logo { width: 24px; height: 24px; display: inline-block; flex-shrink: 0; }
.topbar .userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--muted); }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px;
}
.card h2 { font-size: 1rem; margin-bottom: 12px; font-weight: 700; }
.card h3 { font-size: .95rem; margin-bottom: 10px; font-weight: 600; }

/* Standard single-line card header: title left, control right */
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

.page-title { font-size: 1.4rem; font-weight: 800; margin: 6px 0 2px; }
.page-sub { color: var(--muted); font-size: .88rem; margin-bottom: 18px; }

/* Section heading (not inside a card) */
.sect-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 10px; }
.sect-head h2 { margin: 0; font-size: 1.05rem; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* Two-column responsive grid (collapses to one column on narrow screens) */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color:#fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); background:#fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; border-radius: 8px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 5px; }
.field label .hint-inline { font-weight: 400; }
.input, select.input {
  width: 100%; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: .95rem; background: #fff; color: var(--text); outline: none; transition: border-color .15s;
}
/* inline input + action (no full-line button) */
.inline-cta { display: flex; gap: 8px; align-items: center; }
.inline-cta .input { flex: 1; min-width: 0; }
.input:focus { border-color: var(--primary); }
.input::placeholder { color: #b6bccb; }

/* Badges / pills */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; background: #eef1f7; color: var(--muted);
}
.pill.green { background: var(--primary-soft); color: var(--primary-dark); }
.pill.red { background: #fdeaea; color: var(--danger); }
.pill.orange { background: #fdf2e0; color: var(--warn); }
.pill.blue { background: #e8f0fb; color: var(--info); }
.pill.dark { background: #e9edf5; color: #3b4257; }

/* Buttons row / actions */
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

/* Group list item */
.group-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px;
  background: #fff; transition: all .15s ease; cursor: pointer;
}
.group-item:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(7,193,96,.08); }
.group-item .gi-left { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.group-item .gi-title { font-weight: 700; font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-item .gi-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.group-item .gi-code { font-family: monospace; letter-spacing: 1px; color: var(--muted); font-size: .8rem; }

/* Auth page */
.auth-layout { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .logo-big { width: 62px; height: 62px; display: inline-block; margin-bottom: 12px; }
.auth-logo h1 { font-size: 1.35rem; font-weight: 800; }
.auth-logo p { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab { flex: 1; text-align: center; padding: 10px; border-radius: 10px; background: #eef1f7; color: var(--muted); font-weight: 600; cursor: pointer; }
.auth-tab.active { background: var(--primary); color: #fff; }

/* QR display */
.qr-stage {
  text-align: center; padding: 20px 16px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.qr-box {
  width: min(66vw, 300px); height: min(66vw, 300px);
  border-radius: 16px; background: #fff; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; box-shadow: var(--shadow); position: relative; padding: 12px;
}
.qr-box svg { width: 100% !important; height: 100% !important; }
.qr-box .idle {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); gap: 8px; text-align: center; padding: 20px;
}
.qr-box .idle .pulse-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 0 rgba(7,193,96,.5); animation: pulse 1.6s ease-out infinite; }
.qr-box .idle .pulse-dot.off { background: #c9cfdb; box-shadow:none; animation:none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(7,193,96,.5);} 70% { box-shadow: 0 0 0 16px rgba(7,193,96,0);} 100% { box-shadow: 0 0 0 0 rgba(7,193,96,0);} }

.latency-box {
  display: inline-flex; align-items: baseline; gap: 8px;
  background: var(--primary-soft); color: var(--primary-dark); padding: 10px 20px; border-radius: 12px;
}
.latency-box .num { font-size: 1.5rem; font-weight: 800; }
.latency-box .unit { font-size: .85rem; font-weight: 600; }
.latency-box.waiting { background: #eef1f7; color: var(--muted); }

.qr-value {
  max-width: 100%; word-break: break-all; font-family: monospace; font-size: .8rem; color: var(--muted);
  background: #f2f4f9; padding: 8px 12px; border-radius: 8px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.stat-card .v { font-size: 1.6rem; font-weight: 800; margin-bottom: 2px; }
.stat-card .l { font-size: .8rem; color: var(--muted); }

/* Table */
table.data { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-weight: 600; }
table.data tr:last-child td { border-bottom: none; }
.scroll-x { overflow-x: auto; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(40px);
  background: #2a2f3d; color: #fff; padding: 12px 22px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 1000; max-width: 90%; text-align:center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* Skeleton loading */
.skeleton { background: linear-gradient(90deg,#eef1f7 25%,#f6f8fc 50%,#eef1f7 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Hint banner */
.banner { border-radius: 12px; padding: 12px 16px; font-size: .88rem; margin-bottom: 14px; }
.banner.info { background: #e8f0fb; color: #2f5f9e; }
.banner.warn { background: #fdf2e0; color: #9a6a12; }
.banner.play { margin-top: 12px; }

/* Group management card action row */
.gitem-actions { flex-wrap: wrap; row-gap: 8px; }

/* Pin star (next to group title) */
.star {
  background: none; border: none; cursor: pointer;
  font-size: 1.4rem; line-height: 1; padding: 0 2px; color: var(--muted);
  transition: color .15s ease, transform .1s ease;
}
.star:hover { color: var(--warn); transform: scale(1.1); }

@media (max-width: 620px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .btn { padding: 8px 13px; }
  .page-title { font-size: 1.25rem; }
  .page-sub { margin-bottom: 14px; }
  .gitem-actions { width: 100%; justify-content: flex-start; }
  .inline-cta { flex-wrap: wrap; }
  .inline-cta .btn { flex: 1; }
}
