:root {
  color-scheme: light dark;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #12161c;
  --muted: #5b6573;
  --border: #d8dee8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --accent-weak: #e7eefc;
  --danger: #c0392b;
  --danger-weak: #fdecea;
  --ok: #17845a;
  --shadow: 0 12px 32px rgba(16, 24, 40, 0.09);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #171c24;
    --surface-2: #1f2632;
    --text: #e8edf5;
    --muted: #94a1b5;
    --border: #2b3544;
    --accent: #7aa2ff;
    --accent-text: #0b1220;
    --accent-weak: #1b2942;
    --danger: #ff8d85;
    --danger-weak: #3a1f1e;
    --ok: #57c795;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
}

/* ------------------------------------------------------------- auth page */

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.brand-title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--muted);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.12);
}

.form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input,
select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.form-error {
  color: var(--danger);
  background: var(--danger-weak);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.link-box {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 10px;
}

.link-box > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}

.link-box > summary::-webkit-details-marker {
  display: none;
}

.link-box > summary::before {
  content: "+ ";
}

.link-box[open] > summary::before {
  content: "− ";
}

.footnote {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
}

.btn:hover {
  filter: brightness(1.04);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
}

.btn.danger {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

/* -------------------------------------------------------------- app page */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  margin: 0;
  gap: 10px;
}

.topbar .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 15px;
}

.topbar .brand-title {
  font-size: 16px;
}

.spacer {
  flex: 1;
}

.who {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 20px 64px;
}

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.page-head h1 {
  font-size: 20px;
  font-weight: 650;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.card-title {
  font-weight: 650;
  font-size: 15.5px;
  overflow-wrap: anywhere;
}

.card-sub {
  font-size: 12.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.code-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.code {
  font-family: var(--mono);
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
}

.code.expired {
  color: var(--muted);
}

.code-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.bar {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transition: width 0.9s linear;
}

.bar.low > i {
  background: var(--danger);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 22px;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.empty strong {
  color: var(--text);
  font-size: 16px;
}

/* -------------------------------------------------------------- dialogs */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(480px, calc(100vw - 28px));
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(9, 13, 20, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-body {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-head h2 {
  font-size: 17px;
  font-weight: 650;
}

.dialog-head .close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border-radius: 8px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.recycle-list {
  display: grid;
  gap: 10px;
  max-height: 46vh;
  overflow: auto;
}

.detail-list {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px 16px;
  margin: 0;
  font-size: 14px;
}

.detail-list dt {
  color: var(--muted);
  white-space: nowrap;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-list dd.mono {
  font-size: 13px;
  line-height: 1.5;
}

.recycle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.recycle-item .grow {
  flex: 1;
  min-width: 0;
}

.recycle-item .name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.recycle-item .sub {
  font-size: 12px;
  color: var(--muted);
}

.divider {
  height: 1px;
  background: var(--border);
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 560px) {
  .topbar {
    padding: 10px 14px;
  }

  .who .label {
    display: none;
  }

  .main {
    padding: 20px 14px 56px;
  }

  .page-head h1 {
    font-size: 18px;
  }

  .code {
    font-size: 27px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}
