:root {
  color-scheme: dark;
  --bg0: #080a0f;
  --bg1: #0f1219;
  --surface: rgba(22, 27, 38, 0.92);
  --surface2: #12161f;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f3f4f8;
  --muted: #9aa3b5;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.14);
  --accent-hover: #2dd4a0;
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --input-h: 44px;
  --btn-h: 44px;
  --max-w: 1080px;
  --max-w-narrow: 440px;
  --font: "SF Pro Display", "PingFang SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg0);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(52, 211, 153, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(59, 130, 246, 0.08), transparent),
    linear-gradient(180deg, var(--bg1), var(--bg0));
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ── Login ── */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-card {
  width: min(var(--max-w-narrow), 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
  display: grid;
  gap: 20px;
}

.login-brand {
  text-align: center;
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #059669);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 8px 24px rgba(52, 211, 153, 0.25);
}

.login-brand h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.login-brand p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

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

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

.field input,
.field textarea,
.input,
.textarea {
  width: 100%;
  height: var(--input-h);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea,
.textarea {
  height: auto;
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.input:focus,
.textarea:focus {
  outline: none;
  border-color: rgba(52, 211, 153, 0.5);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 1.2em;
  text-align: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-h);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: #1a2030;
}

.btn:active:not(:disabled) { transform: scale(0.98); }

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

.btn.primary {
  background: linear-gradient(135deg, #059669, #047857);
  border-color: transparent;
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #10b981, #059669);
}

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

.btn.danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
  background: var(--danger-dim);
}

.btn.sm {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.btn-block { width: 100%; }

/* ── App shell ── */
.shell {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 28px 20px 48px;
  display: grid;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-brand .brand-mark {
  width: 42px;
  height: 42px;
  margin: 0;
  font-size: 18px;
  border-radius: 11px;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  display: grid;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  font-size: 16px;
  font-weight: 600;
}

.panel-desc {
  margin-top: -8px;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid .field-full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--input-h);
  padding: 0 4px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th,
.table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.02);
}

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

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

.table code {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 8px;
  border-radius: 6px;
}

.table .input-inline {
  width: 100px;
  height: 34px;
  padding: 0 10px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.cell-stack {
  display: grid;
  gap: 4px;
}

.cell-hint {
  font-size: 11px;
  color: var(--muted);
}

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

/* ── Status / badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge.ok {
  color: var(--accent);
  background: var(--accent-dim);
}

.badge.bad {
  color: var(--danger);
  background: var(--danger-dim);
}

.result-box {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  min-height: 48px;
  display: flex;
  align-items: center;
}

.result-box.ok {
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.result-box.bad {
  color: var(--danger);
  background: var(--danger-dim);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.result-box.empty {
  color: var(--muted);
  background: var(--surface2);
  border: 1px dashed var(--border);
}

/* ── Steps list ── */
.steps {
  list-style: none;
  display: grid;
  gap: 12px;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  align-items: start;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.steps strong { color: var(--text); font-weight: 600; }

/* ── Log ── */
.log {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  max-height: 240px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
}

/* ── Toast ── */
.toast-wrap {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toast-in 0.25s ease;
}

.toast.ok { border-color: rgba(52, 211, 153, 0.35); color: var(--accent); }
.toast.err { border-color: rgba(248, 113, 113, 0.35); color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── User balance ── */
.balance-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.12), rgba(5, 150, 105, 0.06));
  border: 1px solid rgba(52, 211, 153, 0.22);
}

.balance-info { display: grid; gap: 6px; }

.balance-label {
  font-size: 13px;
  color: var(--muted);
}

.balance-value {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.balance-value .unit {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}

.balance-meta {
  text-align: right;
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.amount-plus { color: var(--accent); font-weight: 600; }
.amount-minus { color: var(--danger); font-weight: 600; }

@media (max-width: 640px) {
  .balance-card { flex-direction: column; align-items: stretch; text-align: center; }
  .balance-meta { text-align: center; }
  .login-card { padding: 28px 20px 24px; }
  .topbar { flex-direction: column; align-items: stretch; text-align: center; }
  .topbar-brand { justify-content: center; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; }
}
