/*
 * TON Sandbox Console — design system
 *
 * Built on the same token system as apps/docs/public/styles.css.
 * All colors, spacing, radii, and typography are CSS custom properties.
 * No one-off values. Light/dark via [data-theme].
 * Interactive targets >= 44px. Visible :focus-visible rings. prefers-reduced-motion respected.
 */

/* --------------------------------------------------------------------------
 * Tokens (shared with docs design system)
 * -------------------------------------------------------------------------- */
:root {
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --text-xs: 0.75rem;
  --text-sm: 0.85rem;
  --text-base: 0.95rem;
  --text-md: 1.05rem;
  --text-lg: 1.25rem;
  --text-xl: 1.6rem;
  --text-2xl: clamp(1.9rem, 3.2vw, 2.9rem);

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;

  --shadow-sm: 0 1px 2px rgba(15, 23, 34, 0.06);
  --shadow-md: 0 8px 28px rgba(15, 23, 34, 0.10);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light theme (default) */
:root,
[data-theme="light"] {
  color-scheme: light;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eef1f6;
  --surface-inset: #f1f4f8;
  --border: #e3e8ef;
  --border-strong: #cfd7e2;
  --text: #0f1722;
  --text-muted: #56616f;
  --text-subtle: #8a94a3;
  --brand: #0f7d5c;
  --brand-strong: #0a5b43;
  --brand-contrast: #ffffff;
  --brand-soft: #e7f4ef;
  --brand-ring: rgba(15, 125, 92, 0.28);
  --accent: #b6462e;
  --link: #0a6b4f;
  --ok: #1f9d6b;
  --ok-soft: #e8f6ef;
  --warn: #c9772a;
  --warn-soft: #fdf3e7;
  --err: #c93a2b;
  --err-soft: #fdecea;
  --info: #2f72c9;
  --info-soft: #ecf3fc;
  --code-bg: #0c1118;
  --code-surface: #11171f;
  --code-border: #1e2733;
  --code-text: #d6e2ee;
  --code-dim: #7f8b9c;
  --skeleton-from: #eef1f6;
  --skeleton-to: #f6f8fa;
}

[data-theme="dark"] {
  color-scheme: dark;
  --surface: #0c1016;
  --surface-2: #11161e;
  --surface-3: #161d27;
  --surface-inset: #131922;
  --border: #222b37;
  --border-strong: #303b4a;
  --text: #e7edf4;
  --text-muted: #9aa7b6;
  --text-subtle: #6b7888;
  --brand: #34c994;
  --brand-strong: #46d6a3;
  --brand-contrast: #042319;
  --brand-soft: rgba(52, 201, 148, 0.13);
  --brand-ring: rgba(52, 201, 148, 0.32);
  --accent: #e8825f;
  --link: #4fd0a0;
  --ok: #46d6a3;
  --ok-soft: rgba(70, 214, 163, 0.12);
  --warn: #e2a154;
  --warn-soft: rgba(226, 161, 84, 0.12);
  --err: #f07060;
  --err-soft: rgba(240, 112, 96, 0.12);
  --info: #6aa8ef;
  --info-soft: rgba(106, 168, 239, 0.12);
  --code-bg: #090d13;
  --code-surface: #0e141c;
  --code-border: #1c2530;
  --code-text: #d6e2ee;
  --code-dim: #7f8b9c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.5);
  --skeleton-from: #161d27;
  --skeleton-to: #11161e;
}

/* --------------------------------------------------------------------------
 * Reset & base
 * -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-inset);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* --------------------------------------------------------------------------
 * Skip link
 * -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -60px;
  z-index: 60;
  padding: var(--space-2) var(--space-4);
  background: var(--brand);
  color: var(--brand-contrast);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: var(--text-sm);
  transition: top 0.16s var(--ease);
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-3);
}

/* --------------------------------------------------------------------------
 * Header / topbar
 * -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px);
}

.topbar-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-brand h1 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.topbar-subtitle {
  margin: 0;
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
 * Badge
 * -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.4;
}

.badge .badge-icon {
  flex-shrink: 0;
  width: 12px;
  height: 12px;
}

.badge.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.badge.err {
  background: var(--err-soft);
  border-color: var(--err);
  color: var(--err);
}

.badge.info {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}

.badge.sandbox {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-strong);
}

/* --------------------------------------------------------------------------
 * Button (.btn)
 * -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease), opacity 0.15s var(--ease);
}

.btn.primary {
  background: var(--brand);
  color: var(--brand-contrast);
  box-shadow: var(--shadow-sm);
}

.btn.primary:hover {
  background: var(--brand-strong);
  box-shadow: var(--shadow-md);
}

.btn.secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn.secondary:hover {
  background: var(--surface-2);
}

.btn.danger {
  background: var(--err);
  color: #fff;
}

.btn.danger:hover {
  opacity: 0.9;
}

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

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.small {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.btn.icon {
  width: 44px;
  padding: 0;
}

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

/* --------------------------------------------------------------------------
 * Input
 * -------------------------------------------------------------------------- */
.input {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.input::placeholder {
  color: var(--text-subtle);
}

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

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-7);
}

textarea.input {
  min-height: 78px;
  resize: vertical;
}

/* --------------------------------------------------------------------------
 * Label
 * -------------------------------------------------------------------------- */
label {
  display: grid;
  gap: var(--space-1);
}

label .label-text {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
}

label .label-hint {
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

/* --------------------------------------------------------------------------
 * Card
 * -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.card--clickable {
  cursor: pointer;
  transition: transform 0.14s var(--ease), border-color 0.14s var(--ease), box-shadow 0.14s var(--ease);
}

.card--clickable:hover {
  transform: translateY(-2px);
  border-color: var(--brand-ring);
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
 * Section
 * -------------------------------------------------------------------------- */
.section {
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--border);
}

.section:last-child {
  border-bottom: 0;
}

.section h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  font-weight: 750;
  letter-spacing: -0.01em;
}

.section h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-base);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
 * Layout utilities
 * -------------------------------------------------------------------------- */
.stack {
  display: grid;
  gap: var(--space-3);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.rows {
  display: grid;
  gap: var(--space-2);
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.row:first-child {
  border-top: 0;
}

/* --------------------------------------------------------------------------
 * Layout: shell (sidebar + content)
 * -------------------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-5) var(--space-5) var(--space-7);
  max-width: 1480px;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
 * Sidebar nav
 * -------------------------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 72px;
  align-self: start;
  display: grid;
  gap: 4px;
}

.sidebar a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.12s var(--ease), background 0.12s var(--ease);
}

.sidebar a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar a.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 700;
  box-shadow: inset 2px 0 0 var(--brand);
}

/* --------------------------------------------------------------------------
 * Code block
 * -------------------------------------------------------------------------- */
.code-block {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
}

.code-block pre {
  margin: 0;
  padding: var(--space-4);
  overflow-x: auto;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.65;
  tab-size: 2;
}

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

/* --------------------------------------------------------------------------
 * Inline code
 * -------------------------------------------------------------------------- */
code:not(.code-block code):not(pre code) {
  padding: 0.12em 0.4em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
 * Skeleton / loading placeholder
 * -------------------------------------------------------------------------- */
.skeleton {
  min-height: 80px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--skeleton-from), var(--skeleton-to), var(--skeleton-from));
  background-size: 200% 100%;
  animation: skeleton-pulse 1.2s infinite;
}

@keyframes skeleton-pulse {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
 * Callout / alert
 * -------------------------------------------------------------------------- */
.callout {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.callout .callout-icon {
  margin-top: 2px;
}

.callout .callout-body {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.callout .callout-body strong {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--text);
}

.callout.info {
  border-left-color: var(--info);
  background: var(--info-soft);
}

.callout.info .callout-icon { color: var(--info); }

.callout.warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.callout.warning .callout-icon { color: var(--warn); }

.callout.error {
  border-left-color: var(--err);
  background: var(--err-soft);
}

.callout.error .callout-icon { color: var(--err); }

.callout.success {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.callout.success .callout-icon { color: var(--ok); }

/* --------------------------------------------------------------------------
 * Empty state
 * -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  display: grid;
  place-items: center;
  color: var(--text-subtle);
}

.empty-state h2 {
  margin: 0;
  font-size: var(--text-md);
  color: var(--text);
}

.empty-state p {
  margin: 0;
  font-size: var(--text-sm);
  max-width: 42ch;
}

/* --------------------------------------------------------------------------
 * Stepper (checklist / progress)
 * -------------------------------------------------------------------------- */
.stepper {
  display: grid;
  gap: var(--space-2);
}

.step {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.step-indicator {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 800;
  line-height: 1;
  transition: background 0.15s var(--ease);
}

.step.pending .step-indicator {
  background: var(--surface-3);
  color: var(--text-subtle);
}

.step.active .step-indicator {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.step.complete .step-indicator {
  background: var(--ok-soft);
  color: var(--ok);
}

.step.error .step-indicator {
  background: var(--err-soft);
  color: var(--err);
}

.step-label {
  font-size: var(--text-sm);
  line-height: 1.4;
  padding-top: 2px;
}

.step.pending .step-label { color: var(--text-subtle); }
.step.active .step-label { color: var(--text); font-weight: 700; }
.step.complete .step-label { color: var(--text-muted); }
.step.error .step-label { color: var(--err); }

/* --------------------------------------------------------------------------
 * Table
 * -------------------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  padding: var(--space-2) var(--space-3);
  border-bottom: 2px solid var(--border);
  text-align: left;
  font-weight: 700;
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.table-row:hover td {
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
 * Toast
 * -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 70;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  max-width: 400px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: toast-in 0.22s var(--ease);
}

.toast.info { border-left: 3px solid var(--info); }
.toast.success { border-left: 3px solid var(--ok); }
.toast.error { border-left: 3px solid var(--err); }

.toast[aria-hidden="true"] {
  display: none;
}

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

/* --------------------------------------------------------------------------
 * Modal / dialog
 * -------------------------------------------------------------------------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 12, 0.5);
  backdrop-filter: blur(3px);
}

.modal {
  width: min(480px, calc(100% - var(--space-6)));
  max-height: 80vh;
  overflow-y: auto;
  padding: var(--space-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: modal-in 0.16s var(--ease);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
 * Meta / utility text
 * -------------------------------------------------------------------------- */
.meta {
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

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

/* --------------------------------------------------------------------------
 * Status indicator dot
 * -------------------------------------------------------------------------- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.err { background: var(--err); }
.status-dot.info { background: var(--info); }

/* --------------------------------------------------------------------------
 * Hidden utility
 * -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
 * Secret reveal box
 * -------------------------------------------------------------------------- */
.secret {
  font-family: var(--font-mono);
  word-break: break-all;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
 * Inline status line
 * -------------------------------------------------------------------------- */
.status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
 * Responsive
 * -------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    padding: var(--space-3) var(--space-4) var(--space-6);
  }

  .sidebar {
    position: static;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: var(--space-2);
    gap: var(--space-1);
  }

  .sidebar a {
    white-space: nowrap;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .grid,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
  }
}
