/* ── Reset & base ───────────────────────────────────────────────── */
body {
  margin: 0;
  background: #f4f6f8;
  color: #111827;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 80rem;
  margin: 0 auto;
  padding: 2rem;
  padding: 2rem max(2rem, env(safe-area-inset-left)) 2rem
    max(2rem, env(safe-area-inset-right));
  padding-top: max(2rem, env(safe-area-inset-top));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

h1 {
  margin: 0 0 1.5rem;
  font-size: 1.75rem;
  font-weight: 700;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.shell {
  line-height: 1.5;
}

/* ── Layout ────────────────────────────────────────────────────── */
.columns {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 2px rgb(0 0 0 / 4%);
}

.card.dark {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  border-color: #334155;
  color: #f1f5f9;
}

.card.dark .muted {
  color: #64748b;
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: #e5e5e5;
  color: #666;
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

.badge.green {
  background: #dcfce7;
  color: #166534;
}

.badge.purple {
  background: #ede9fe;
  color: #5b21b6;
}

/* ── ISS / stat values ─────────────────────────────────────────── */
.stats {
  display: flex;
  gap: 1.5rem;
}

.label {
  display: block;
  color: #94a3b8;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.value {
  color: #60a5fa;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

.value.placeholder {
  color: #475569;
}

/* ── Text helpers ──────────────────────────────────────────────── */
.muted {
  margin: 0;
  color: #999;
  font-style: italic;
}

.muted.small {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.workflow-desc,
.export-desc {
  margin-bottom: 0.75rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── Trades table ──────────────────────────────────────────────── */
.trades-table,
table {
  width: 100%;
  border-collapse: collapse;
}

.trades-table th {
  padding: 0.4rem 0;
  border-bottom: 1px solid #eee;
  color: #666;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
}

.trades-table td {
  padding: 0.4rem 0;
  border-bottom: 1px solid #f5f5f5;
  font-size: 0.8rem;
}

.buy {
  color: #16a34a;
  font-weight: 500;
}

.sell {
  color: #dc2626;
  font-weight: 500;
}

.placeholder-row {
  color: #ccc;
}

/* ── Input labels ──────────────────────────────────────────────── */
.input-label {
  display: block;
  margin-bottom: 0.3rem;
  color: #666;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.events-label {
  margin-top: 0.75rem;
}

/* ── Webhook ───────────────────────────────────────────────────── */
.webhook-row,
.form-row {
  display: flex;
  gap: 0.5rem;
}

.webhook-row {
  margin-bottom: 0.5rem;
}

.key-input,
input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #111827;
  font-family: inherit;
  font-size: 0.85rem;
}

.key-input {
  background: #fafafa;
  border-color: #d1d5db;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

.key-input.used {
  background: #f0fdf4;
  border-color: #16a34a;
  border-width: 2px;
  color: #166534;
}

.hint {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
}

.hint.warning {
  color: #b45309;
}

.hint.success {
  color: #166534;
}

.events {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.event {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
  background: #f8fafc;
  font-size: 0.8rem;
}

.event .time {
  color: #64748b;
}

/* ── Progress / Jobs ───────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  margin-bottom: 0.5rem;
  border-radius: 3px;
  background: #e5e5e5;
  overflow: hidden;
}

.fill {
  height: 100%;
  background: #0066cc;
  transition: width 0.3s;
}

.progress-text {
  margin: 0 0 0.5rem;
  color: #666;
  font-size: 0.8rem;
}

/* ── Workflow steps ────────────────────────────────────────────── */
.steps {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  background: #f5f5f5;
  font-size: 0.8rem;
}

.step.completed {
  background: #dcfce7;
}

.step.running {
  background: #dbeafe;
}

.step.failed {
  background: #fee2e2;
}

.icon {
  width: 1.2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  text-align: center;
}

/* ── Buttons ───────────────────────────────────────────────────── */
button {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 4px;
  background: #0066cc;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

button:hover:not(:disabled) {
  background: #0055aa;
}

button:disabled {
  background: #999;
  cursor: not-allowed;
}

button.small {
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
}

button.secondary {
  background: #666;
}

button.danger {
  background: #dc2626;
}

/* ── Users table ───────────────────────────────────────────────── */
.form-row {
  margin-bottom: 1rem;
}

th,
td {
  padding: 0.6rem;
  border-bottom: 1px solid #eee;
  text-align: left;
}

th {
  color: #555;
  font-weight: 600;
  font-size: 0.85rem;
}

.editing {
  background: #f0f9ff;
}

.table-wrap {
  overflow-x: auto;
}

.action-cell {
  position: relative;
  display: inline-flex;
  gap: 0.5rem;
  white-space: nowrap;
}

.popover {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  display: flex;
  gap: 0.5rem;
  margin-top: 4px;
  padding: 0.5rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}

/* ── Auth card ─────────────────────────────────────────────────── */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.75rem;
}

.tab {
  flex: 1;
  padding: 0.35rem;
  background: #f5f5f5;
  border: 1px solid #e2e8f0;
  color: #555;
  font-size: 0.8rem;
  cursor: pointer;
}

.tab:hover:not(.active) {
  background: #e2e8f0;
  color: #1e293b;
}

.tab:first-child {
  border-radius: 5px 0 0 5px;
}

.tab:last-child {
  border-radius: 0 5px 5px 0;
}

.tab.active {
  background: #0066cc;
  color: white;
  border-color: #0066cc;
}

.card form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card form input {
  flex: unset;
  width: 100%;
  box-sizing: border-box;
}

.card form button[type="submit"] {
  align-self: flex-start;
}

.auth-user {
  margin-bottom: 0.5rem;
}

.auth-user .label {
  font-size: 0.7rem;
  color: #94a3b8;
  display: block;
}

.auth-user .value {
  font-size: 0.9rem;
  font-weight: 500;
  color: #111827;
}

.token-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.6rem;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  padding: 0.3rem 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.meta-key {
  font-weight: 500;
  color: #666;
  min-width: 2.5rem;
}

.auth-actions {
  display: flex;
  gap: 0.5rem;
}

/* ── Cache card ────────────────────────────────────────────────── */
.cache-stats {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

/* ── MCP card ──────────────────────────────────────────────────── */
.mcp-card {
}

.mcp-desc {
  font-size: 0.85rem;
  color: #555;
  margin: 0 0 0.75rem;
}

.code-block {
  background: #0f172a;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.code-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: #64748b;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.code-block pre {
  margin: 0;
  overflow-x: auto;
}

.code-block code {
  color: #e2e8f0;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.mcp-tools {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mcp-tool {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  padding: 0.6rem 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

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

.tool-desc {
  color: #666;
  font-size: 0.75rem;
}

.tool-badge {
  font-size: 0.6rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: #dcfce7;
  color: #166534;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 700px) {
  main {
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .columns {
    flex-direction: column;
  }

  .col {
    width: 100%;
  }

  .card {
    padding: 1rem;
  }

  .stats {
    gap: 1rem;
    flex-wrap: wrap;
  }

  .value {
    font-size: 0.95rem;
  }

  .webhook-row {
    flex-wrap: wrap;
  }

  .key-input {
    flex: 1 1 100%;
    font-size: 0.8rem;
  }

  .form-row {
    flex-wrap: wrap;
  }

  .form-row input,
  .form-row button {
    flex: 1 1 100%;
  }

  table {
    font-size: 0.85rem;
  }

  th,
  td {
    padding: 0.5rem 0.25rem;
  }

  .action-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .popover {
    position: fixed;
    top: 50%;
    right: auto;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .trades-table {
    font-size: 0.8rem;
  }

  .code-block code {
    font-size: 0.7rem;
  }
}

/* ── App layout & nav ──────────────────────────────────────────── */
.app-nav {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: inherit;
}
