:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --ink: #161719;
  --muted: #6b7078;
  --soft: #8a9099;
  --line: #dfe3e8;
  --line-strong: #c7ced6;
  --panel: #ffffff;
  --panel-subtle: #f9fafb;
  --charcoal: #1a1d21;
  --green: #0b6b58;
  --green-soft: #e7f3ef;
  --blue: #2367b1;
  --blue-soft: #e7eff9;
  --amber: #b46912;
  --amber-soft: #fff4e3;
  --red: #a13c3c;
  --red-soft: #fff0f0;
  --shadow: 0 18px 46px rgba(22, 23, 25, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, #e9edf1 0, #f4f5f7 220px, #f4f5f7 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-view[hidden],
.shell[hidden] {
  display: none;
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.portal-auth {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
  gap: 18px;
  width: min(1040px, 100%);
}

.auth-copy,
.auth-forms {
  display: grid;
  gap: 14px;
}

.auth-copy {
  align-content: center;
  min-height: 420px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.72)),
    linear-gradient(135deg, rgba(11, 107, 88, 0.16), rgba(35, 103, 177, 0.12));
  box-shadow: var(--shadow);
}

.auth-copy p:last-child {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.auth-forms {
  grid-template-columns: 1fr 1fr;
}

.login-panel h1 {
  font-size: 28px;
}

.login-panel small {
  color: var(--muted);
  line-height: 1.5;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 112px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.72)),
    linear-gradient(135deg, rgba(11, 107, 88, 0.16), rgba(35, 103, 177, 0.12));
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--charcoal);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(26, 29, 33, 0.2);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 31px;
  line-height: 1.12;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

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

.portal-user {
  display: grid;
  gap: 2px;
  min-width: 180px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.portal-user strong {
  font-size: 14px;
}

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

.top-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.top-meta span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(22, 23, 25, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: #474d55;
  font-size: 12px;
  font-weight: 700;
}

.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(11, 107, 88, 0.12);
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #545b64;
  font-size: 12px;
  font-weight: 720;
}

.field.small {
  width: 210px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

select {
  height: 44px;
  padding: 0 12px;
}

input {
  height: 46px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 188px;
  max-height: 360px;
  padding: 14px;
  line-height: 1.55;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 95, 159, 0.12);
}

.ghost,
.primary,
.secondary,
.mode,
.plan,
.provider,
.client-row {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 700;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

.primary {
  min-width: 132px;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  box-shadow: 0 12px 24px rgba(11, 107, 88, 0.22);
}

.secondary {
  min-width: 132px;
  border-color: var(--charcoal);
  background: var(--charcoal);
  color: #fff;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 21px;
  line-height: 1;
}

.ghost:hover,
.secondary:hover,
.mode:hover,
.plan:hover,
.provider:hover,
.client-row:hover {
  border-color: var(--line-strong);
  box-shadow: 0 10px 24px rgba(22, 23, 25, 0.08);
}

.primary:hover {
  background: #075d4c;
  transform: translateY(-1px);
}

.dashboard {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  position: relative;
  min-height: 126px;
  align-content: space-between;
  overflow: hidden;
  padding: 18px;
}

.metric::after {
  content: "";
  display: block;
  width: 54px;
  height: 3px;
  margin-top: 15px;
  border-radius: 999px;
  background: var(--line-strong);
}

.metric span,
.metric small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.metric strong {
  display: block;
  min-height: 32px;
  margin: 10px 0 7px;
  font-size: 29px;
  font-weight: 780;
  line-height: 1.1;
  word-break: break-word;
}

.metric.balance {
  border-color: var(--charcoal);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0)),
    var(--charcoal);
  color: #fff;
}

.metric.balance span,
.metric.balance small {
  color: rgba(255, 255, 255, 0.72);
}

.metric.balance::after {
  background: #8ee1c6;
}

.metric:nth-child(2)::after {
  background: var(--blue);
}

.metric:nth-child(3)::after {
  background: var(--amber);
}

.metric:nth-child(4)::after {
  background: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  gap: 16px;
}

.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
  gap: 16px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 32px;
  margin-bottom: 16px;
}

.panel-head span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.panel-head.spaced {
  margin-top: 20px;
}

.commerce-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.commerce-strip div {
  min-height: 92px;
  padding: 15px;
  background: #fff;
}

.commerce-strip span,
.client-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.commerce-strip strong {
  display: block;
  margin-top: 12px;
  font-size: 24px;
  line-height: 1.1;
}

.client-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
}

.client-head h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.client-list,
.api-key-list {
  display: grid;
  gap: 8px;
}

.client-row,
.api-key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  text-align: left;
}

.client-row {
  background: linear-gradient(180deg, #fff, #fbfcfd);
}

.client-row strong,
.api-key-row strong {
  display: block;
  font-size: 14px;
}

.client-row small,
.api-key-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.client-balance {
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 13px;
  font-weight: 820;
}

.api-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.secret-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(180, 105, 18, 0.35);
  border-radius: 8px;
  background: var(--amber-soft);
}

.secret-box[hidden] {
  display: none;
}

.secret-box span {
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
}

.secret-box code {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.api-key-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.order-row {
  align-items: flex-start;
}

.order-actions {
  display: inline-flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.small-action {
  min-width: 0;
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.code-sample {
  min-height: 164px;
  margin: 12px 0 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111418;
  color: #eef3f6;
  padding: 14px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
}

.empty-state {
  min-height: 54px;
  padding: 15px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.composer {
  display: grid;
  gap: 15px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.mode {
  display: grid;
  align-content: center;
  gap: 2px;
  min-height: 62px;
  width: 100%;
  text-align: left;
}

.mode span,
.mode small {
  display: block;
}

.mode span {
  font-size: 14px;
}

.mode small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.mode.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(35, 103, 177, 0.12);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.answer {
  min-height: 132px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.55;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.plan-list,
.provider-list {
  display: grid;
  gap: 10px;
}

.plan,
.provider {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.plan {
  background:
    linear-gradient(180deg, #fff, #fbfcfd);
}

.plan strong,
.provider strong {
  display: block;
  font-size: 14px;
}

.plan small,
.provider small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.provider.degraded {
  border-color: rgba(161, 60, 60, 0.45);
  background: var(--red-soft);
}

.provider.healthy {
  border-color: rgba(23, 120, 90, 0.32);
  background: linear-gradient(180deg, #fff, #fbfdfc);
}

.provider-badge,
.plan-action,
.model-badge,
.ledger-type,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 780;
}

.provider-badge {
  background: var(--green-soft);
  color: var(--green);
}

.provider.degraded .provider-badge {
  background: var(--red-soft);
  color: var(--red);
}

.plan-action {
  background: var(--charcoal);
  color: #fff;
}

.model-badge {
  margin-top: 4px;
  background: var(--panel-subtle);
  color: #545b64;
}

.ledger-type {
  background: var(--panel-subtle);
  color: #545b64;
}

.status-badge.pending {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-badge.paid {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.active {
  background: var(--green-soft);
  color: var(--green);
}

.status-badge.revoked {
  background: var(--red-soft);
  color: var(--red);
}

.tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.table-panel {
  min-width: 0;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  background: #f7f8fa;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fbfcfd;
}

.delta-plus {
  color: var(--green);
  font-weight: 750;
}

.delta-minus {
  color: var(--red);
  font-weight: 750;
}

@media (max-width: 1040px) {
  .metrics,
  .ops-grid,
  .workspace,
  .tables,
  .portal-auth,
  .auth-forms {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100% - 20px, 1440px);
    padding-top: 10px;
  }

  .topbar,
  .header-actions,
  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 16px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .field.small {
    width: 100%;
  }

  h1 {
    font-size: 24px;
  }

  .metrics,
  .mode-grid,
  .commerce-strip {
    grid-template-columns: 1fr;
  }

  .api-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .metric,
  .panel {
    padding: 15px;
  }
}
