/* xyzq88 Dashboard */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f9fafb; --border: #e5e7eb; --border-strong: #d1d5db;
  --text: #111827; --text-2: #374151; --muted: #6b7280;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef2ff; --accent-text: #ffffff;
  --ok: #047857; --ok-soft: #ecfdf5; --warn: #b45309; --warn-soft: #fffbeb; --danger: #dc2626; --danger-soft: #fef2f2;
  --vs: #2563eb; --vs-soft: #eff6ff; --pb: #7c3aed; --pb-soft: #f5f3ff; --hb: #0d9488; --hb-soft: #f0fdfa;
  --sidebar: #0f172a; --sidebar-text: #cbd5e1; --sidebar-muted: #64748b; --sidebar-active: #1e293b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --radius: 12px; --radius-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14; --surface: #131722; --surface-2: #171c28; --border: #232a3a; --border-strong: #2f3748;
    --text: #e6e9ef; --text-2: #c3c9d4; --muted: #8a93a6;
    --accent: #818cf8; --accent-hover: #a5b4fc; --accent-soft: #1e1b4b; --accent-text: #0b0e14;
    --ok: #34d399; --ok-soft: #062e22; --warn: #fbbf24; --warn-soft: #2d2208; --danger: #f87171; --danger-soft: #2c1215;
    --vs: #60a5fa; --vs-soft: #0f1f3d; --pb: #a78bfa; --pb-soft: #1f1640; --hb: #2dd4bf; --hb-soft: #0a2925;
    --sidebar: #0a0d13; --sidebar-text: #c3c9d4; --sidebar-muted: #5b6577; --sidebar-active: #171c28;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.25; letter-spacing: -.02em; margin: 0; font-weight: 650; }
h2 { font-size: .95rem; margin: 0; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .85em; } .strong { font-weight: 600; } .nowrap { white-space: nowrap; }
.mono, code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.code { background: var(--surface-2); border: 1px solid var(--border); padding: .1rem .4rem; border-radius: 6px; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- layout ---------- */
body.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1rem;
  background: var(--sidebar); color: var(--sidebar-text); padding: 20px 14px; }
.brand, .authbrand { display: flex; align-items: center; gap: .65rem; color: inherit; font-weight: 700; font-size: 1.05rem; padding: 0 6px; }
.brand:hover { text-decoration: none; }
.brand small, .authbrand small { display: block; font-weight: 500; font-size: .72rem; color: var(--sidebar-muted); letter-spacing: .04em; text-transform: uppercase; }
.logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; font-weight: 800; font-size: 1.1rem;
  color: #fff; background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; margin-top: .5rem; }
.navlabel { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); padding: 14px 10px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500; }
.sidebar nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 #818cf8; }
.me { display: flex; align-items: center; gap: .5rem; border-top: 1px solid rgba(148, 163, 184, .15); padding-top: 14px; }
.mecard { flex: 1; display: flex; align-items: center; gap: .65rem; padding: 6px; border-radius: var(--radius-sm); color: inherit; min-width: 0; }
.mecard:hover, .mecard.active { background: var(--sidebar-active); text-decoration: none; }
.mecard strong { display: block; color: #fff; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }
.mecard small { display: block; color: var(--sidebar-muted); font-size: .75rem; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: #312e81; color: #e0e7ff; font-weight: 700; font-size: .85rem; }
.avatar.sm { width: 28px; height: 28px; font-size: .78rem; } .avatar.lg { width: 48px; height: 48px; font-size: 1.15rem; }
.iconbtn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 0;
  background: transparent; color: var(--sidebar-muted); cursor: pointer; }
.iconbtn:hover { background: var(--sidebar-active); color: #fff; }

.page { padding: 28px 32px 48px; max-width: 1280px; width: 100%; min-width: 0; }
.narrow { max-width: 560px; margin: 0 auto; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.sub { color: var(--muted); margin: .3rem 0 0; }
.back { display: inline-block; color: var(--muted); margin-bottom: .75rem; font-size: .9em; }
.userhead { display: flex; align-items: center; gap: 1rem; }
.userhead .sub { display: flex; flex-wrap: wrap; gap: .4rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-side { display: grid; grid-template-columns: minmax(0, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-side.wide-left { grid-template-columns: minmax(0, 1fr) minmax(0, 360px); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.center { text-align: center; } .card.center h1 { margin-bottom: .5rem; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 14px; }
.cardhead.pad { padding: 18px 20px 0; }
.card.flush > .cardhead:not(.pad) { padding: 18px 20px 0; }
.note { color: var(--muted); font-size: .82rem; margin: 0; padding: 12px 20px; border-top: 1px solid var(--border); }
.card:not(.flush) > .note { padding: 12px 0 0; margin-top: 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi-label { display: block; color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi strong { display: block; font-size: 1.65rem; font-weight: 650; letter-spacing: -.02em; margin: .35rem 0 .15rem; font-variant-numeric: tabular-nums; }
.kpi strong em { font-style: normal; font-size: .55em; color: var(--muted); font-weight: 600; }
.kpi small { color: var(--muted); }

/* ---------- filters & export ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 16px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters label { display: flex; flex-direction: column; gap: 4px; }
.filters label span { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.filters input, .filters select { width: auto; min-width: 160px; }
.export { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 6px 6px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.export-label { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; color: var(--text-2); margin-right: 4px; font-size: .88rem; }
.export-label .icon { width: 16px; height: 16px; color: var(--accent); }

.myexport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 20px 0; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.myexport input { width: auto; min-height: 30px; padding: 4px 8px; }
.myexport + .tablewrap { margin-top: 12px; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field .label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 6px; color: var(--text-2); }
.field .help { display: block; color: var(--muted); margin-top: 5px; font-size: .8rem; }
.field em { display: block; color: var(--danger); font-style: normal; font-size: .82rem; margin-top: 5px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px; min-height: 40px; transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
form.inline { display: flex; align-items: flex-end; gap: 10px; }
form.inline .field { flex: 1; margin-bottom: 0; }

.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600; font-size: .88rem;
  min-height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:hover, button:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-ghost-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: .8rem; }
.btn-wide { width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.card:not(.flush) th:first-child, .card:not(.flush) td:first-child { padding-left: 4px; }
.card:not(.flush) th { background: transparent; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; width: 1%; }
td.actions form { margin: 0; }
td.empty { text-align: center; color: var(--muted); padding: 32px 14px; }
td.empty:hover { background: transparent; }

.badge { display: inline-block; min-width: 34px; text-align: center; padding: 2px 8px; border-radius: 6px; font-size: .74rem; font-weight: 700; letter-spacing: .03em; }
.badge-VS { color: var(--vs); background: var(--vs-soft); }
.badge-PB { color: var(--pb); background: var(--pb-soft); }
.badge-HB { color: var(--hb); background: var(--hb-soft); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.off { color: var(--muted); }
.userlink { display: flex; align-items: center; gap: .65rem; color: var(--text); }
.userlink strong { display: block; } .userlink small { display: block; color: var(--muted); font-size: .78rem; }
.link { font-size: .85rem; font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 14px; border-top: 1px solid var(--border); }

.dangerzone { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 14px 0 0; margin-top: 14px; border-top: 1px solid var(--border); }
.dangerzone strong { display: block; } .dangerzone small { display: block; color: var(--muted); }
.dangerzone form { margin: 0; }

/* ---------- toasts ---------- */
.toasts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.toast { display: flex; align-items: flex-start; gap: .6rem; padding: 11px 14px; border-radius: var(--radius-sm); font-size: .9rem;
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); margin-bottom: 14px; }
.toasts .toast { margin-bottom: 0; }
.toast span { color: var(--text); }
.toast.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.toast.warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

/* ---------- auth ---------- */
body.guest { min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg); }
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .toasts { width: 100%; max-width: 420px; }
.authcard { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .08); }
.authbrand { padding: 0; margin-bottom: 24px; color: var(--text); }
.authbrand small { color: var(--muted); }
.authcard h1 { font-size: 1.35rem; } .authcard .sub { margin-bottom: 20px; }
.authfoot { display: flex; align-items: center; justify-content: center; gap: .4rem; margin: 18px 0 0; color: var(--muted); font-size: .8rem; }
.authfoot .icon { width: 14px; height: 14px; }
.steps { padding-left: 1.2rem; margin: 12px 0; color: var(--text-2); } .steps li { margin-bottom: .3rem; }
.qr { background: #fff; padding: 12px; border-radius: 10px; width: fit-content; margin: 16px auto; border: 1px solid var(--border); }
.qr svg { display: block; width: 200px; height: 200px; }
.secret { display: block; word-break: break-all; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; margin: 6px 0 14px; }
details { margin-bottom: 16px; } summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .88rem; }
.codes { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.codes code { display: block; padding: 10px; text-align: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; letter-spacing: .06em; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  body.app { display: block; }
  .sidebar { position: sticky; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  .sidebar nav { order: 3; flex-basis: 100%; flex-direction: row; overflow-x: auto; margin: 0; padding-bottom: 2px; }
  .sidebar nav a { white-space: nowrap; padding: 7px 10px; }
  .navlabel { display: none; }
  .me { margin-left: auto; border: 0; padding: 0; }
  .mecard small { display: none; }
  .page { padding: 20px 16px 40px; }
  .grid-side, .grid-side.wide-left { grid-template-columns: minmax(0, 1fr); }
  .pagehead { align-items: flex-start; }
  .filters input, .filters select { min-width: 0; }
  .filters label { flex: 1 1 140px; }
}
