:root {
  --bg: #0b0d13;
  --bg2: #14171f;
  --bg3: #1d212c;
  --text: #e6e8ee;
  --text2: #8b90a3;
  --accent: #5ea1ff;
  --accent2: #4f8cff;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff453a;
  --border: #262a36;
  --radius: 10px;
  --radius-lg: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── Auth ───────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, #1a2240, var(--bg) 60%);
}
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 100%;
  max-width: 420px;
}
.brand { text-align: center; margin-bottom: 28px; }
.brand .logo { font-size: 36px; }
.brand h1 { font-size: 1.6em; margin: 6px 0 4px; }
.brand .tagline { color: var(--text2); font-size: 0.9em; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg3); border-radius: var(--radius); margin-bottom: 20px; }
.tab { flex: 1; padding: 10px; background: none; border: none; color: var(--text2); cursor: pointer; border-radius: 6px; font-size: 0.9em; transition: all .15s; }
.tab.active { background: var(--bg2); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.2); }

.form { display: none; }
.form.active { display: block; }
label { display: block; color: var(--text2); font-size: 0.82em; margin-top: 14px; margin-bottom: 6px; }
input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.92em;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9em;
  font-weight: 500;
  cursor: pointer;
  transition: transform .05s, background .15s;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg3); }
.btn-sm { padding: 6px 12px; font-size: 0.82em; }
.btn-lg { padding: 12px 24px; font-size: 1em; width: 100%; margin-top: 22px; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }

.err { color: var(--red); font-size: 0.85em; margin-top: 12px; min-height: 18px; }
.auth-footer { text-align: center; color: var(--text2); font-size: 0.85em; margin-top: 24px; }

/* ── App ────────────────────────────────────────── */
.app-page { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand-mini { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mini .logo { font-size: 22px; }
.nav { display: flex; gap: 4px; }
.nav-item {
  padding: 7px 14px;
  border-radius: 7px;
  color: var(--text2);
  font-size: 0.9em;
  cursor: pointer;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--text); }
.user-menu { display: flex; gap: 10px; align-items: center; font-size: 0.88em; color: var(--text2); }

.main { flex: 1; max-width: 980px; width: 100%; margin: 28px auto; padding: 0 24px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 18px;
}
.card h3 { font-size: 1.05em; margin-bottom: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

.muted { color: var(--text2); font-size: 0.88em; }

/* Hero (quota card) */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.hero h2 { font-size: 1.4em; margin-bottom: 4px; }
.hero .muted { font-size: 0.85em; }
.hero-right { min-width: 220px; }

.quota-bar { background: var(--bg3); height: 8px; border-radius: 4px; overflow: hidden; margin-top: 8px; }
.quota-fill { background: linear-gradient(90deg, var(--green), var(--accent)); height: 100%; border-radius: 4px; }
.quota-fill.warn { background: linear-gradient(90deg, var(--orange), var(--red)); }
.quota-text { display: flex; justify-content: space-between; font-size: 0.85em; color: var(--text2); margin-bottom: 2px; }

/* Format tabs */
.format-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.format-tabs button {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 0.82em;
  cursor: pointer;
}
.format-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Subscription block */
.sub-block { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.sub-url-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.sub-url-row input { font-family: ui-monospace, monospace; font-size: 0.82em; background: #0a0c12; }
.sub-url-row .btn { white-space: nowrap; }
.sub-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.qr-box {
  background: #fff;
  padding: 12px;
  border-radius: var(--radius);
  text-align: center;
}
.qr-box svg { display: block; max-width: 200px; height: auto; }
.qr-box .qr-caption { font-size: 0.8em; color: #555; margin-top: 6px; }

@media (max-width: 720px) {
  .sub-block { grid-template-columns: 1fr; }
  .qr-box { max-width: 240px; margin: 0 auto; }
}

.hint {
  margin-top: 18px;
  padding: 12px 16px;
  background: rgba(94,161,255,.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85em;
  color: var(--text);
}

/* Action grid */
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s;
}
.action:hover { border-color: var(--accent); }
.action-icon { font-size: 26px; }
.action-title { font-weight: 600; font-size: 0.95em; }
.action-desc { font-size: 0.8em; color: var(--text2); margin-top: 2px; }

/* Devices */
.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.device-row:last-child { border-bottom: none; }
.device-meta { font-size: 0.82em; color: var(--text2); }

/* KV list (settings) */
.kv-list { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: 0.9em; }
.kv-list .k { color: var(--text2); }
.kv-list .v { word-break: break-all; }
.kv-list code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

/* Footer */
.footer { padding: 24px; text-align: center; color: var(--text2); font-size: 0.82em; border-top: 1px solid var(--border); }

/* Toast */
.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.88em;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
