:root {
  --bg: #09090b;
  --bg-elevated: #111114;
  --panel: #141417;
  --panel-hover: #1a1a1f;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.12);
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 40px rgba(0, 0, 0, 0.35);
  --page-x: clamp(1rem, 2.5vw, 2rem);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.14), transparent 55%),
    radial-gradient(ellipse 40% 30% at 100% 0%, rgba(99, 102, 241, 0.08), transparent 50%);
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem var(--page-x);
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.82);
  backdrop-filter: blur(12px);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar__logo {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
  flex-shrink: 0;
}

.topbar__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.topbar__sub {
  margin: 0.1rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.main {
  flex: 1;
  width: 100%;
  padding: 1.25rem var(--page-x) 2rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: rgba(20, 20, 23, 0.72);
  box-shadow: var(--shadow);
}

.stat__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat__value {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.tabs {
  display: inline-flex;
  padding: 0.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(17, 17, 20, 0.9);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab:hover { color: var(--text); }

.tab--active {
  color: var(--text);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.card {
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: rgba(20, 20, 23, 0.78);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card + .card { margin-top: 0.85rem; }

.card__inner {
  padding: 1rem var(--page-x);
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem var(--page-x);
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 56rem;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: rgba(255, 255, 255, 0.02);
}

th, td {
  text-align: left;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

tbody tr:last-child td { border-bottom: 0; }

.accounts-row td {
  background: rgba(9, 9, 11, 0.55);
  padding-top: 0.35rem;
  padding-bottom: 1rem;
  border-top: none;
}

tbody tr.accounts-row:hover td {
  background: rgba(9, 9, 11, 0.55);
}

tbody tr:has(+ tr.accounts-row):hover td {
  background: rgba(255, 255, 255, 0.02);
}

.muted { color: var(--text-muted); font-size: 0.875rem; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
}

label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: rgba(9, 9, 11, 0.9);
  color: var(--text);
  margin-bottom: 0.75rem;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: rgba(59, 130, 246, 0.55);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

button {
  border: 0;
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-size: 0.8125rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: transform 0.12s, opacity 0.12s, background 0.12s;
}

button:hover:not(:disabled) { filter: brightness(1.06); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.28);
}

button.btn-sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
}

.actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--off { background: rgba(161, 161, 170, 0.12); color: var(--text-muted); }
.badge--bad { background: var(--danger-soft); color: var(--danger); }

table.tokens-table {
  min-width: 100%;
  table-layout: auto;
}

table.tokens-table th.token-col,
table.tokens-table td.token-cell {
  width: 50%;
  min-width: 20rem;
  max-width: none;
  white-space: normal;
  word-break: break-all;
  vertical-align: top;
}

.token-full {
  display: inline;
  word-break: break-all;
  white-space: normal;
  user-select: all;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: #93c5fd;
  background: transparent;
}

.accounts-panel {
  padding: 0.35rem 0 0.5rem 0.25rem;
}

.accounts-panel__head {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
}

.accounts-panel__empty {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
}

.accounts-table-wrap {
  overflow: auto;
  max-height: min(28rem, 55vh);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
}

.accounts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.accounts-table th,
.accounts-table td {
  padding: 0.45rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.accounts-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--panel);
}

.accounts-table tbody tr:last-child td {
  border-bottom: none;
}

.accounts-table tbody tr:hover td {
  background: var(--panel-hover);
}

.accounts-table tbody tr {
  background: transparent;
}

.accounts-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  color: #93c5fd;
}

.token-reveal {
  margin-bottom: 1rem;
  border-color: rgba(74, 222, 128, 0.35);
  background: var(--ok-soft);
}

.token-reveal__title {
  margin: 0 0 0.35rem;
  font-weight: 600;
  color: var(--ok);
}

.token-reveal__hint {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
}

.token-reveal__value {
  display: block;
  word-break: break-all;
  white-space: normal;
  user-select: all;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.45;
}

.token-reveal__actions {
  margin-top: 0.65rem;
}

.err {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem var(--page-x);
}

.login {
  width: min(20rem, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.login input,
.login button {
  width: 100%;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal {
  width: min(28rem, 100%);
  padding: 1.25rem;
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.warn-box {
  margin: 0.5rem 0;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius);
  background: var(--warn-soft);
  border: 1px solid rgba(251, 191, 36, 0.25);
  color: #fcd34d;
  font-size: 0.8125rem;
}

.token-box {
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.9);
  word-break: break-all;
  margin-bottom: 0.75rem;
}

.empty-cell {
  padding: 2.5rem 1rem !important;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs { width: 100%; justify-content: center; }
}
