:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #182026;
  --muted: #66737d;
  --line: #dbe1e5;
  --brand: #167052;
  --brand-dark: #10563f;
  --accent: #d7a52b;
  --danger: #b43b3b;
  --info: #316b96;
  --shadow: 0 18px 50px rgba(18, 34, 43, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button, input, select { min-height: 40px; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.danger-text { color: var(--danger); }

.icon { width: 18px; height: 18px; stroke-width: 1.9; flex: 0 0 auto; }
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: wait; opacity: .6; transform: none; }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #e6c4c4; }
.btn-icon { width: 38px; padding: 0; }
.icon-link { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; }

.field { display: grid; gap: 7px; }
.field label { font-weight: 650; color: #334049; }
.field input, .field select {
  width: 100%; border: 1px solid #cbd3d8; border-radius: 6px; background: white;
  color: var(--text); padding: 0 12px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22,112,82,.12); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.message { min-height: 20px; margin: 12px 0 0; color: var(--danger); }

.public-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(90deg, rgba(22,112,82,.06) 1px, transparent 1px),
    linear-gradient(rgba(22,112,82,.06) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}
.public-head, .public-foot { width: min(1080px, calc(100% - 40px)); margin: 0 auto; }
.public-head { height: 72px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 780; font-size: 17px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px;
  background: var(--brand); color: white;
}
.public-main { display: grid; place-items: center; padding: 36px 20px 72px; }
.query-tool {
  width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 34px;
}
.query-tool h1 { font-size: 28px; line-height: 1.2; margin: 0 0 9px; }
.query-tool > p { color: var(--muted); margin: 0 0 26px; line-height: 1.7; }
.token-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.result { border-top: 1px solid var(--line); margin-top: 26px; padding-top: 25px; }
.result-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); }
.code-line { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 17px 0; }
.code-value { font: 750 34px/1 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.result-detail { display: grid; gap: 7px; color: var(--muted); }
.public-foot { padding: 22px 0; color: var(--muted); font-size: 12px; border-top: 1px solid rgba(102,115,125,.2); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(420px, 100%); }
.login-box .brand { margin-bottom: 24px; }
.login-panel { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.login-panel h1 { margin: 0 0 22px; font-size: 23px; }
.login-panel form { display: grid; gap: 16px; }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { background: #17262b; color: white; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 4px 8px 22px; }
.nav { display: grid; gap: 4px; }
.nav button {
  border: 0; background: transparent; color: #bfcbcf; border-radius: 6px; padding: 0 11px;
  display: flex; align-items: center; gap: 11px; text-align: left; font-weight: 620;
}
.nav button:hover, .nav button.active { background: #253a40; color: white; }
.sidebar-bottom { position: absolute; left: 14px; right: 14px; bottom: 18px; }
.admin-main { min-width: 0; }
.topbar {
  height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
  background: white; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; margin: 0; }
.admin-user { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.content { padding: 28px; max-width: 1500px; }
.section { display: none; }
.section.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 20px; }
.section-head h2 { margin: 0 0 5px; font-size: 23px; }
.section-head p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 28px; }
.stat { background: white; padding: 20px; min-height: 110px; }
.stat-label { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 28px; font-weight: 760; margin-top: 13px; }
.panel { background: white; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 22px; }
.panel-head { padding: 17px 19px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-body { padding: 19px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 12px 15px; border-bottom: 1px solid #e8ecef; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 700; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 680; background: #e7f3ee; color: var(--brand-dark); }
.badge.off { background: #edf0f2; color: var(--muted); }
.badge.error { background: #f8e8e8; color: var(--danger); }
.actions { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.actions .btn { min-height: 34px; padding: 0 10px; font-size: 12px; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(12,22,26,.55); z-index: 20; display: grid; place-items: center; padding: 20px; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: white; border-radius: 8px; box-shadow: var(--shadow); }
.modal-head { padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; margin: 0; }
.modal-body { padding: 20px; }
.secret-box { background: #eff6f3; border: 1px solid #bbd9ce; padding: 14px; border-radius: 6px; font: 650 15px/1.5 ui-monospace, monospace; overflow-wrap: anywhere; margin: 14px 0; }
.qr { display: block; width: 220px; max-width: 100%; margin: 0 auto 15px; }
.toast { position: fixed; right: 22px; bottom: 22px; background: #17262b; color: white; padding: 12px 16px; border-radius: 6px; box-shadow: var(--shadow); z-index: 40; max-width: 380px; }

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding-inline: 10px; }
  .sidebar .brand span, .nav span, .sidebar-bottom span { display: none; }
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .nav button, .sidebar-bottom button { justify-content: center; width: 100%; padding: 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .public-head, .public-foot { width: calc(100% - 28px); }
  .query-tool { padding: 24px 20px; }
  .query-tool h1 { font-size: 24px; }
  .token-row { grid-template-columns: 1fr; }
  .token-row .btn { width: 100%; }
  .code-value { font-size: 28px; }
  .admin-shell { display: block; padding-bottom: 64px; }
  .sidebar { position: fixed; z-index: 10; inset: auto 0 0 0; width: auto; height: 64px; padding: 7px; }
  .sidebar .brand, .sidebar-bottom { display: none; }
  .nav { display: flex; justify-content: space-around; height: 100%; }
  .nav button { width: 52px; min-height: 48px; }
  .topbar { padding: 0 16px; }
  .admin-user span { display: none; }
  .content { padding: 20px 14px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head .btn { width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { min-height: 96px; padding: 15px; }
  .stat-value { font-size: 23px; }
  .form-grid { grid-template-columns: 1fr; }
}
