/* ── Playground: break out of .site-main constraint ── */

html:has(.tabula-app) .site-main {
  width: 100%;
  max-width: none;
  padding: 0;
}

/* ── Playground app shell ───────────────────────────────────────── */

.tabula-app {
  width: 100%;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  min-height: calc(100vh - 48px);
}

/* ── Topbar ────────────────────────────────────────────────────── */

.topbar {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  animation: reveal 300ms ease-out;
}

.brand {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand .kicker {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}

.brand h1 {
  margin: 1px 0 0;
  font-size: 18px;
  line-height: 1;
}

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.deploy-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.instance-id {
  font-size: 11px;
  color: var(--ink-muted);
}

.version-tag {
  background: var(--accent-bg);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-bg);
  flex-shrink: 0;
}

/* ── Settings drawer ───────────────────────────────────────────── */

.settings-drawer {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}

.settings-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

.settings-grid label {
  flex: 0 1 220px;
}

.settings-io {
  flex: 1 1 300px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-io textarea {
  min-height: 48px;
}

.health-box {
  display: flex;
  align-items: center;
}

/* ── Workspace grid: 2 columns ─────────────────────────────────── */

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 0;
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.panel h2,
.panel h3 {
  margin: 0;
}

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

.panel h3 {
  font-size: 13px;
  color: var(--ink-muted);
}

.panel-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.panel-head.inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

/* ── Code editor ───────────────────────────────────────────────── */

.code-editor {
  flex: 1;
  min-height: 320px;
  white-space: pre;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 4;
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
}

.left-actions {
  display: flex;
  gap: 8px;
}

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

.template-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-2);
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}

.template-chip:hover {
  border-color: var(--accent-dim);
  color: var(--ink);
}

/* ── Right panel: State + Tx builder ───────────────────────────── */

.state-section,
.tx-section {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.section-divider {
  border-top: 1px solid var(--line);
  margin: 2px 0;
}

/* ── Schema state tables ───────────────────────────────────────── */

.schema-table-block {
  margin-bottom: 10px;
}

.schema-table-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.table-name {
  font-weight: 700;
  font-size: 14px;
}

.table-id-badge {
  font-size: 10px;
  color: var(--ink-muted);
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

.schema-table th .col-name {
  display: block;
  font-weight: 600;
  font-size: 12px;
}

.schema-table th .col-type {
  display: block;
  font-weight: 400;
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: lowercase;
}

.row-key-col,
.row-key-cell {
  width: 56px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 11px;
}

/* ── Transaction cards ─────────────────────────────────────────── */

.tx-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  margin-bottom: 8px;
  background: var(--bg-2);
}

.tx-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tx-index {
  font-weight: 700;
  font-size: 12px;
  color: var(--ink-muted);
  min-width: 24px;
}

.tx-card-header select {
  flex: 0 0 auto;
  max-width: 180px;
}

.tx-name {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
}

.tx-params {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  margin-bottom: 6px;
}

.tx-param-field label {
  gap: 1px;
}

.param-name {
  font-weight: 500;
  font-size: 11px;
}

.param-type {
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: lowercase;
}

.tx-meta {
  display: flex;
  gap: 8px;
}

.tx-meta label {
  flex: 1;
}

.sender-input {
  font-size: 10px !important;
}

/* ── Editor tables (flat fallback) ─────────────────────────────── */

.editor-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: auto;
  max-height: 220px;
  background: var(--bg-2);
}

.editor-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

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

.editor-table th {
  position: sticky;
  top: 0;
  background: var(--bg-1);
  font-size: 11px;
}

.editor-table input {
  padding: 5px;
  border-radius: var(--radius-sm);
}

.table-remove {
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--err);
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  transition: background 120ms ease;
}

.table-remove:hover {
  background: var(--err-dim);
}

/* ── Bottom panel: Tabs ────────────────────────────────────────── */

.bottom-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: reveal 300ms ease-out;
}

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

.tab-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-weight: 500;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.tab-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.tab-btn.active {
  border-color: var(--accent-dim);
  background: var(--accent-bg);
  color: var(--accent);
}

.tab-content {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  background: var(--bg-2);
}

/* ── Proof display ─────────────────────────────────────────────── */

.proof-display {
  padding: 10px;
}

.stark-result {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stark-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stark-scheme {
  font-weight: 600;
  font-size: 13px;
}

.stark-stmt-hash {
  font-size: 10px;
  color: var(--ink-muted);
}

.stark-timing {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timing-bar {
  display: flex;
  height: 28px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 500;
}

.timing-prove {
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  min-width: 60px;
}

.timing-verify {
  background: var(--ok-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ok);
  min-width: 60px;
}

.stark-roots {
  display: flex;
  gap: 12px;
}

.root-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.root-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.root-block code {
  font-size: 10px;
  color: var(--ink);
  background: var(--bg-1);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  word-break: break-all;
}

.stark-chips h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--ink-muted);
}

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

.chip-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 11px;
  background: var(--bg-1);
}

.chip-name {
  font-weight: 500;
}

.chip-height {
  color: var(--ink-muted);
  font-size: 10px;
}

.verify-msg {
  font-size: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

/* ── History float ─────────────────────────────────────────────── */

.history-float {
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 50;
  max-width: 320px;
}

.history-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 11px;
  border: 1px solid var(--line);
  background: var(--bg-1);
}

.history-chip.ok {
  border-color: rgba(34, 197, 94, 0.3);
}

.history-chip.err {
  border-color: rgba(239, 68, 68, 0.3);
}

.history-chip strong {
  font-size: 11px;
}

.history-chip span {
  color: var(--ink-muted);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Playground responsive ─────────────────────────────────────── */

@media (max-width: 1024px) {
  .workspace-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .code-editor {
    min-height: 240px;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-center {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
  }

  .history-float {
    display: none;
  }
}
