:root {
  color-scheme: light;
  --ink: #151b23;
  --muted: #647183;
  --soft: #8793a3;
  --page: #f4f7fa;
  --surface: #ffffff;
  --subtle: #f8fafc;
  --line: #d9e1ea;
  --line-strong: #c8d2dd;
  --teal: #13756f;
  --teal-strong: #0f5f5a;
  --blue: #244f84;
  --amber: #906000;
  --red: #a9342a;
  --shadow: 0 18px 44px rgba(27, 39, 51, .08);
  --shadow-soft: 0 8px 20px rgba(27, 39, 51, .05);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
}

body[data-session="signed-out"] .role-tabs,
body[data-session="signed-out"] .session,
body[data-session="signed-out"] .console-shell {
  display: none;
}

body[data-session="signed-in"] #authPanel {
  display: none;
}

h1, h2, p, dl, dd {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(230px, auto);
  align-items: center;
  gap: 22px;
  min-height: 72px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: #132232;
  color: white;
  font-weight: 820;
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1;
}

.brand small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.role-tabs,
.section-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f6;
}

.role-tab,
.section-tab {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 760;
  white-space: nowrap;
}

.role-tab.active,
.section-tab.active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: var(--shadow-soft);
}

.session {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.button.primary:hover {
  border-color: var(--teal-strong);
  background: var(--teal-strong);
  color: white;
}

.button.secondary {
  background: #f8fafc;
}

.button.danger {
  border-color: #ecc6c1;
  background: #fffafa;
  color: var(--red);
}

.button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.button.full {
  width: 100%;
}

main {
  min-height: calc(100vh - 72px);
}

.auth-screen {
  width: min(1120px, calc(100vw - 40px));
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  align-items: center;
  gap: 64px;
  margin: 0 auto;
  padding: 56px 0;
}

.auth-copy {
  max-width: 640px;
}

.eyebrow {
  color: var(--amber);
  font-size: 12px;
  font-weight: 840;
  letter-spacing: 0;
  text-transform: uppercase;
}

.auth-copy h1 {
  margin-top: 12px;
  font-size: 64px;
  line-height: 1;
  letter-spacing: 0;
}

.auth-copy p:not(.eyebrow) {
  max-width: 560px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.45;
}

.console-shell {
  width: min(1232px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 28px;
  margin-bottom: 20px;
}

.view-head h1 {
  margin-top: 6px;
  font-size: 40px;
  line-height: 1.05;
  letter-spacing: 0;
}

.inline-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.inline-stats span {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.inline-stats strong {
  color: var(--blue);
  font-size: 18px;
  text-transform: none;
}

.section-tabs {
  margin-bottom: 18px;
}

.section-panel {
  display: none;
}

.section-panel.active {
  display: block;
}

.split-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, .82fr);
  gap: 18px;
  align-items: start;
}

.three-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.narrow-panel {
  max-width: 720px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin-top: 5px;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.panel-copy {
  max-width: 520px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.request-panel {
  display: grid;
  gap: 16px;
}

.request-panel .panel-head {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(19, 117, 111, .13);
}

.choice-row,
.check-grid,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.choice-row {
  margin-top: 14px;
}

.check-grid {
  display: grid;
  align-items: stretch;
  margin-bottom: 16px;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--subtle);
}

.choice input {
  width: auto;
  min-height: auto;
}

.auth-card .button.full {
  margin-top: 18px;
}

.advanced,
.receipt-details,
.raw-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--subtle);
}

.advanced summary,
.receipt-details summary,
.raw-details summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  color: var(--ink);
  font-weight: 780;
  cursor: pointer;
}

.advanced .field-grid {
  padding: 0 12px 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #e7f5f2;
  color: var(--teal);
  font-size: 12px;
  font-weight: 820;
  white-space: nowrap;
}

.pill.muted {
  background: #eef2f6;
  color: var(--muted);
}

.result-panel {
  min-height: 560px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 22px;
  background: var(--subtle);
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.empty-state.large {
  min-height: 420px;
}

.result-output {
  display: grid;
  gap: 16px;
}

.answer-box {
  min-height: 170px;
  border-radius: 8px;
  padding: 18px;
  background: #121f2c;
  color: #eef5f8;
}

.answer-box p {
  white-space: pre-wrap;
  line-height: 1.55;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.receipt-grid article {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--subtle);
}

.receipt-grid span {
  display: block;
  color: var(--soft);
  font-size: 12px;
  font-weight: 820;
  text-transform: uppercase;
}

.receipt-grid strong {
  display: block;
  margin-top: 7px;
  color: var(--blue);
  font-size: 22px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.receipt-details dl,
.ledger-panel dl {
  display: grid;
  border-top: 1px solid var(--line);
}

.receipt-details dl div,
.ledger-panel dl div {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.receipt-details dl div:first-child,
.ledger-panel dl div:first-child {
  border-top: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
  text-transform: uppercase;
}

dd {
  min-width: 0;
  color: var(--ink);
  font-weight: 720;
  overflow-wrap: anywhere;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #101826;
  color: #e7eef6;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
}

.secret {
  min-height: 44px;
  margin: 12px 0 0;
  border-radius: 8px;
  color: #f5d067;
}

.secret:empty {
  display: none;
}

.output {
  min-height: 160px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.inline-form + .stack-list,
.secret + .stack-list {
  margin-top: 16px;
}

.stack-list,
.key-list,
.depth-list {
  display: grid;
  gap: 10px;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--subtle);
}

.list-row strong,
.list-row span,
.list-row small {
  display: block;
}

.list-row strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.list-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.list-row small {
  margin-top: 5px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.row-actions,
.price-pair {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.price-pair span {
  margin-top: 0;
  white-space: nowrap;
}

.table {
  width: 100%;
  overflow-x: auto;
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 840;
  text-transform: uppercase;
}

.ledger-panel dl {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.ledger-panel dd {
  text-align: right;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(21, 28, 36, .32);
}

dialog::backdrop {
  background: rgba(21, 28, 36, .46);
}

.modal {
  display: grid;
  gap: 16px;
  padding: 22px;
  background: var(--surface);
}

.modal .panel-head {
  margin-bottom: 0;
}

.modal-actions {
  justify-content: flex-end;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  padding: 13px 15px;
  background: #111a24;
  color: white;
  box-shadow: 0 16px 42px rgba(17, 26, 36, .22);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .role-tabs,
  .session {
    justify-content: flex-start;
  }

  .auth-screen,
  .split-workspace,
  .three-grid {
    grid-template-columns: 1fr;
  }

  .auth-screen {
    align-items: start;
    gap: 28px;
    padding-top: 36px;
  }

  .auth-copy h1 {
    font-size: 48px;
  }

  .view-head {
    display: grid;
    align-items: start;
  }

  .inline-stats {
    justify-content: flex-start;
  }

  .result-panel {
    min-height: auto;
  }
}

@media (max-width: 700px) {
  .topbar {
    padding: 12px 16px;
  }

  .role-tabs,
  .section-tabs {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .auth-screen,
  .console-shell {
    width: min(100vw - 28px, 1232px);
  }

  .auth-copy h1,
  .view-head h1 {
    font-size: 36px;
  }

  .auth-copy p:not(.eyebrow) {
    font-size: 17px;
  }

  .field-grid,
  .receipt-grid,
  .inline-form,
  .list-row {
    grid-template-columns: 1fr;
  }

  .inline-stats {
    display: grid;
  }

  .panel {
    padding: 18px;
  }

  .panel-head {
    display: grid;
  }

  .empty-state.large {
    min-height: 260px;
  }

  .receipt-details dl div,
  .ledger-panel dl div {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .ledger-panel dd,
  .row-actions,
  .price-pair {
    justify-items: start;
    text-align: left;
  }
}
