:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e7ec;
  --text: #0f172a;
  --muted: #5b6577;
  --faint: #8a93a3;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e6f4f2;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.05);
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0f14;
    --surface: #121821;
    --surface-2: #1a222d;
    --border: #253041;
    --text: #e6ebf2;
    --muted: #9aa5b5;
    --faint: #6c788a;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #11302d;
    --ok: #4ade80;
    --ok-soft: #12291b;
    --warn: #fbbf24;
    --warn-soft: #2e2410;
    --bad: #f87171;
    --bad-soft: #321616;
    --info: #93b4ff;
    --info-soft: #172340;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

code,
.mono {
  font-family: var(--mono);
  font-size: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand svg {
  color: var(--accent);
}

.workspace {
  color: var(--muted);
  font-size: 13px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.sandbox-tag {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  font-weight: 600;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.wallet-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
}

.wallet-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.wallet-pill.connected .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

.row {
  display: grid;
  gap: 20px;
}

.row-top {
  grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
}

.row-mid {
  grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.card-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}

@media (max-width: 960px) {
  .row-top,
  .row-mid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 16px;
  }
  .topbar {
    padding: 10px 16px;
    flex-wrap: wrap;
  }
  .workspace {
    display: none;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

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

.btn:active {
  transform: translateY(1px);
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .btn-primary {
    color: #04201d;
  }
}

.btn-danger {
  color: var(--bad);
}

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

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

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

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

.pill-bad {
  background: var(--bad-soft);
  color: var(--bad);
}

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

.pill-muted {
  background: var(--surface-2);
  color: var(--muted);
}

.budget-amount {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 6px 0 12px;
}

.budget-amount strong {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.budget-amount span {
  color: var(--muted);
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.5s ease, background 0.3s;
}

.meter-fill.high {
  background: var(--warn);
}

.meter-fill.full {
  background: var(--bad);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.stat {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
}

.stat b {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 12px;
  color: var(--muted);
}

.shield {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.shield svg {
  flex: none;
  color: var(--accent);
}

.shield p {
  margin: 0;
}

.shield strong {
  color: var(--text);
}

.rules-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 16px;
}

.rules-input {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  line-height: 1.55;
}

.rules-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.rules-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.rules-compiled {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.rules-compiled li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--accent-soft);
  font-size: 13px;
}

.rules-compiled li::before {
  content: '';
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 3px;
  border-radius: 4px;
  background: var(--accent);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.2 11.4 2.8 8l1.1-1.1 2.3 2.3 5.9-5.9 1.1 1.1z'/%3E%3C/svg%3E") center / contain no-repeat;
}

@media (max-width: 760px) {
  .rules-grid {
    grid-template-columns: 1fr;
  }
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preset {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}

.preset:hover {
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
}

.agent-form {
  display: flex;
  gap: 8px;
}

.agent-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.agent-form input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.timeline {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow-y: auto;
}

.timeline:empty::after {
  content: 'Pick a task above and watch the agent shop. Every purchase goes through Leash first.';
  display: block;
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--faint);
}

.step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--muted);
  animation: rise 0.25s ease both;
}

.step-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.step-body {
  min-width: 0;
  padding-top: 2px;
}

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

.decision {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--surface);
  animation: rise 0.25s ease both;
}

.decision.approve {
  border-left-color: var(--ok);
}

.decision.review {
  border-left-color: var(--warn);
}

.decision.block {
  border-left-color: var(--bad);
}

.decision-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.decision-head .amount {
  margin-left: auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.decision p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.decision ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
}

.agent-message {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 13.5px;
  animation: rise 0.25s ease both;
}

.agent-message p {
  margin: 0 0 6px;
}

.agent-message ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.agent-message table {
  width: 100%;
  margin: 6px 0 8px;
  border-collapse: collapse;
  font-size: 12.5px;
}

.agent-message th,
.agent-message td {
  padding: 5px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  text-align: left;
  vertical-align: top;
}

.agent-message th {
  font-weight: 600;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--faint);
  font-size: 13px;
}

.thinking::before {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.approvals {
  display: grid;
  gap: 10px;
}

.approvals:empty::after {
  content: 'Nothing waiting. Purchases over your auto-approve limit will appear here.';
  display: block;
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--faint);
}

.approval {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border));
  background: color-mix(in srgb, var(--warn-soft) 55%, var(--surface));
  animation: rise 0.25s ease both;
}

.approval-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
}

.approval-head .amount {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.approval .meta {
  color: var(--muted);
  font-size: 12.5px;
}

.approval .why {
  margin: 8px 0 10px;
  font-size: 13px;
}

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

.approval-actions .btn-primary {
  flex: 1;
}

.ledger-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ledger-tools input {
  width: 220px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}

#ledger {
  width: 100%;
  --ag-font-family: var(--font);
  --ag-active-color: var(--accent);
  --ag-border-radius: 10px;
  --ag-wrapper-border-radius: 12px;
}

#ledger .ag-cell {
  display: flex;
  align-items: center;
}

#ledger .ag-right-aligned-cell {
  justify-content: flex-end;
}

.ledger-wrap.has-rows .ag-center-cols-viewport,
.ledger-wrap.has-rows .ag-center-cols-container {
  min-height: 0 !important;
}

.cell-stack {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  line-height: 1.35;
  overflow: hidden;
}

.cell-stack strong {
  font-weight: 600;
}

.cell-stack span {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ledger .ag-row {
  cursor: pointer;
}

.risk {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 100%;
}

.risk-bar {
  flex: none;
  width: 48px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.risk-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

@media (max-width: 640px) {
  .card-head {
    flex-wrap: wrap;
  }
  .ledger-tools input {
    width: 100%;
  }
  .ledger-tools {
    width: 100%;
  }
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  width: min(460px, 100vw);
  padding: 24px;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(15, 23, 42, 0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

body.drawer-open .drawer {
  transform: none;
}

body.drawer-open .drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.drawer h2 {
  margin: 4px 0 2px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.drawer section {
  margin-top: 20px;
}

.drawer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-top .eyebrow {
  text-transform: none;
  letter-spacing: 0;
}

.drawer-status {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.drawer-status .card-sub {
  margin: 0;
}

.drawer-summary {
  margin: 6px 0;
}

.drawer-reasons {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.drawer-error {
  color: var(--bad);
}

.checks {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.checks li {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 13px;
}

.checks .mark {
  font-weight: 700;
}

.checks .pass .mark {
  color: var(--ok);
}

.checks .review .mark {
  color: var(--warn);
}

.checks .block .mark {
  color: var(--bad);
}

.checks small {
  display: block;
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 8px 0 0;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

.events {
  list-style: none;
  margin: 8px 0 0;
  padding: 0 0 0 14px;
  border-left: 2px solid var(--border);
  display: grid;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease both;
}

.toast.error {
  background: var(--bad);
  color: #fff;
}

.banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
}

.banner p {
  margin: 0;
  flex: 1;
}

.banner[hidden] {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
