/* Design tokens + primitives shared by the admin console and the guest page. */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --surface-3: #f1f1ee;
  --border: #e6e5e0;
  --border-strong: #d4d3cc;
  --text: #141413;
  --text-2: #55544f;
  --text-3: #8b8a84;
  --accent: #2563d6;
  --accent-soft: rgba(37, 99, 214, 0.1);
  --primary: #141413;
  --primary-text: #ffffff;
  --good: #128a3e;
  --good-soft: rgba(18, 138, 62, 0.1);
  --warn: #b36b00;
  --warn-soft: rgba(230, 150, 0, 0.13);
  --bad: #cf3434;
  --bad-soft: rgba(207, 52, 52, 0.1);
  --info: #2563d6;
  --info-soft: rgba(37, 99, 214, 0.1);
  --meter-track: #ecebe7;
  --shadow: 0 1px 2px rgba(20, 20, 19, 0.04), 0 4px 16px rgba(20, 20, 19, 0.06);
  --shadow-lg: 0 12px 40px rgba(20, 20, 19, 0.16);
  --radius: 8px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI",
    system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #181817;
    --surface-2: #1d1d1c;
    --surface-3: #252523;
    --border: #2b2b29;
    --border-strong: #3a3a37;
    --text: #f0efec;
    --text-2: #b8b7b0;
    --text-3: #83827c;
    --accent: #5b8ff0;
    --accent-soft: rgba(91, 143, 240, 0.16);
    --primary: #f0efec;
    --primary-text: #141413;
    --good: #3fbf6a;
    --good-soft: rgba(63, 191, 106, 0.14);
    --warn: #e7a83a;
    --warn-soft: rgba(231, 168, 58, 0.15);
    --bad: #f06a6a;
    --bad-soft: rgba(240, 106, 106, 0.15);
    --info: #5b8ff0;
    --info-soft: rgba(91, 143, 240, 0.16);
    --meter-track: #2c2c2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --surface: #181817;
  --surface-2: #1d1d1c;
  --surface-3: #252523;
  --border: #2b2b29;
  --border-strong: #3a3a37;
  --text: #f0efec;
  --text-2: #b8b7b0;
  --text-3: #83827c;
  --accent: #5b8ff0;
  --accent-soft: rgba(91, 143, 240, 0.16);
  --primary: #f0efec;
  --primary-text: #141413;
  --good: #3fbf6a;
  --good-soft: rgba(63, 191, 106, 0.14);
  --warn: #e7a83a;
  --warn-soft: rgba(231, 168, 58, 0.15);
  --bad: #f06a6a;
  --bad-soft: rgba(240, 106, 106, 0.15);
  --info: #5b8ff0;
  --info-soft: rgba(91, 143, 240, 0.16);
  --meter-track: #2c2c2a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] {
  display: none !important;
}
h1,
h2,
h3,
h4,
p {
  margin: 0;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.num {
  font-variant-numeric: tabular-nums;
}
.mono {
  font-family: var(--mono);
  font-size: 12px;
}
.muted {
  color: var(--text-2);
}
.faint {
  color: var(--text-3);
}
.good {
  color: var(--good);
}
.warn {
  color: var(--warn);
}
.bad {
  color: var(--bad);
}
.nowrap {
  white-space: nowrap;
}
.grow {
  flex: 1;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wrap {
  flex-wrap: wrap;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Icons */
.i {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s;
}
.btn:hover:not(:disabled) {
  background: var(--surface-3);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}
.btn.primary:hover:not(:disabled) {
  opacity: 0.88;
  background: var(--primary);
}
.btn.danger {
  color: var(--bad);
}
.btn.danger.solid {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
}
.btn.ghost:hover:not(:disabled) {
  background: var(--surface-3);
}
.btn.sm {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}
.btn.icon {
  width: 32px;
  padding: 0;
}
.btn.icon.sm {
  width: 26px;
}
.btn .spin {
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Form fields */
.input,
.select,
.textarea {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  min-width: 0;
}
.select {
  padding-right: 28px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 14px,
    calc(100% - 10px) 14px;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.select.sm {
  height: 26px;
  padding-left: 8px;
  font-size: 12px;
  background-position:
    calc(100% - 14px) 11px,
    calc(100% - 10px) 11px;
}
.textarea {
  height: auto;
  min-height: 96px;
  padding: 8px 10px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search .i {
  position: absolute;
  left: 9px;
  color: var(--text-3);
  pointer-events: none;
}
.search .input {
  padding-left: 30px;
  width: 240px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.field > span {
  color: var(--text-2);
  font-weight: 500;
}
.field small {
  color: var(--text-3);
  font-size: 12px;
}
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.check input {
  margin: 3px 0 0;
  accent-color: var(--primary);
}

/* Segmented control */
.seg {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  gap: 2px;
}
.seg button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.seg button:hover {
  color: var(--text);
}
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.seg button .count {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}
.badge.plain::before {
  display: none;
}
.badge.good {
  background: var(--good-soft);
  color: var(--good);
}
.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge.bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.badge.info {
  background: var(--info-soft);
  color: var(--info);
}
.tier {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-2);
  white-space: nowrap;
}
.tier.ultra {
  border-color: #c9a227;
  color: #a07c06;
  background: rgba(201, 162, 39, 0.1);
}
:root[data-theme="dark"] .tier.ultra {
  color: #e0bf55;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tier.ultra {
    color: #e0bf55;
  }
}
.tier.free {
  color: var(--text-3);
}

/* Cards, panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.card-head h2,
.card-head h3 {
  font-size: 14px;
  font-weight: 600;
}
.card-body {
  padding: 16px;
}

/* Meter: thin quota bar */
.meter {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: var(--meter-track);
  overflow: hidden;
}
.meter > i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  background: var(--text-2);
}
.meter.good > i {
  background: var(--good);
}
.meter.warn > i {
  background: var(--warn);
}
.meter.bad > i {
  background: var(--bad);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tr:last-child > td {
  border-bottom: 0;
}
.tbl .r {
  text-align: right;
}
.tbl td.num,
.tbl th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tbl tbody tr.clickable {
  cursor: pointer;
}
.tbl tbody tr.clickable:hover > td {
  background: var(--surface-2);
}
.tbl tbody tr.open > td {
  background: var(--surface-2);
}
.tbl tr.detail-row > td {
  padding: 0;
  background: var(--surface-2);
}

/* Toast */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 420px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.error {
  background: var(--bad);
  color: #fff;
}
@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* Empty / loading */
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.skeleton {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface-3);
  font-size: 13px;
  color: var(--text-2);
}
.notice.warn {
  background: var(--warn-soft);
  color: var(--text);
}
.notice.bad {
  background: var(--bad-soft);
  color: var(--text);
}
.notice.info {
  background: var(--info-soft);
  color: var(--text);
}
.notice .i {
  margin-top: 2px;
}
.notice.warn .i {
  color: var(--warn);
}
.notice.bad .i {
  color: var(--bad);
}
.notice.info .i {
  color: var(--info);
}

/* Progress */
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--meter-track);
  overflow: hidden;
  display: flex;
}
.progress > i {
  height: 100%;
  background: var(--good);
}
.progress > i.bad {
  background: var(--bad);
}
.progress > i.warn {
  background: var(--warn);
}
.progress > i.mute {
  background: var(--border-strong);
}
.progress > i.run {
  background: var(--accent);
}

/* Login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login form {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login h1 {
  font-size: 18px;
}
.login .input {
  height: 38px;
}
.login .btn {
  height: 38px;
}
.login .error {
  color: var(--bad);
  font-size: 13px;
  min-height: 1em;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
}
.logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 13px;
  font-weight: 700;
}
