:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-alt: #f0f4f7;
  --border: #d9e0e7;
  --text: #16202a;
  --muted: #647383;
  --accent: #0f8b8d;
  --accent-dark: #09696b;
  --accent-soft: #dff4f2;
  --warn: #996100;
  --warn-soft: #fff2cc;
  --danger: #a83232;
  --danger-soft: #fde8e8;
  --success: #137a3f;
  --success-soft: #def7e8;
  --shadow: 0 10px 24px rgba(22, 32, 42, 0.05);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
}

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

.app-shell {
  width: min(1360px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) 40px;
  gap: 14px;
  align-items: center;
  padding: 16px 0 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--text);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0;
}

.brand-title,
.brand-subtitle {
  display: block;
}

.brand-title {
  font-weight: 800;
  font-size: 18px;
}

.brand-subtitle {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.api-pill {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
}

.api-pill b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.workspace {
  padding-bottom: 28px;
}

.warning-band,
.message,
.panel,
.metric {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.warning-band {
  margin: 4px 0 12px;
  padding: 10px 12px;
  color: var(--warn);
  background: var(--warn-soft);
  font-size: 14px;
}

.message {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.message.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.message.success {
  color: var(--success);
  background: var(--success-soft);
}

.diagnostics-panel {
  margin-bottom: 12px;
}

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

.diagnostic-item,
.diagnostic-error {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.diagnostic-item span,
.diagnostic-item b,
.diagnostic-error b,
.diagnostic-error span,
.diagnostic-error small {
  display: block;
}

.diagnostic-item span,
.diagnostic-error small {
  color: var(--muted);
  font-size: 12px;
}

.diagnostic-item b,
.diagnostic-error span {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12px;
}

.diagnostic-errors {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.diagnostic-error {
  border-color: #efb3b3;
  background: var(--danger-soft);
  color: var(--danger);
}

.diagnostic-body {
  max-height: 120px;
  margin: 8px 0 0;
  overflow: auto;
  padding: 9px;
  border-radius: var(--radius);
  background: #101820;
  color: #e8f1f2;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  min-height: 82px;
  padding: 12px;
}

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

.metric b {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.25;
}

.metric.good {
  border-color: #9bd8bb;
  background: var(--success-soft);
}

.metric.warn {
  border-color: #e7c66e;
  background: var(--warn-soft);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 12px;
}

.panel {
  padding: 14px;
}

.signing-panel {
  margin-bottom: 12px;
}

.signing-grid {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.signing-grid .wide {
  min-width: 0;
}

.signing-grid textarea {
  min-height: 86px;
  resize: vertical;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

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

.weights {
  display: grid;
  gap: 9px;
}

.weight-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 72px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.weight-row b {
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
}

.weight-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-alt);
}

.weight-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.vote-list {
  display: grid;
  gap: 8px;
}

.vote-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.vote-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.vote-row b,
.vote-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vote-row small {
  margin-top: 3px;
  color: var(--muted);
}

.vote-row i,
.status-badge {
  align-self: start;
  padding: 4px 7px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}

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

.compact-form {
  margin-top: 12px;
}

.form-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.form-grid input,
.form-grid select {
  height: 38px;
  padding: 0 10px;
}

.form-grid textarea {
  min-height: 148px;
  resize: vertical;
  padding: 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.wide,
.primary-button,
.secondary-button {
  grid-column: 1 / -1;
}

.primary-button,
.secondary-button {
  height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}

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

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: #a9dbd8;
}

.empty-state {
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 14px;
}

.empty-state.error-state {
  display: grid;
  gap: 5px;
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #efb3b3;
}

.empty-state.error-state small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.empty-state.compact {
  margin-top: 12px;
  padding: 10px;
}

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

.detail-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.detail-item span,
.detail-item b {
  display: block;
}

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

.detail-item b {
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12px;
}

.json-block {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #101820;
  color: #e8f1f2;
}

.json-block pre {
  max-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

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

.option-cell {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.option-cell span,
.option-cell b {
  display: block;
}

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

.option-cell b {
  margin-top: 5px;
  font-family: var(--mono);
}

.button-row {
  display: grid;
  margin-top: 12px;
}

.loading-shell {
  display: grid;
  place-items: center;
}

.loading-panel {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.loader {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 1040px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1360px);
  }

  .topbar {
    grid-template-columns: 1fr 40px;
  }

  .api-pill {
    grid-column: 1 / -1;
    justify-self: stretch;
    order: 3;
  }

  .dashboard-grid,
  .diagnostics-grid,
  .form-grid,
  .signing-grid,
  .detail-grid,
  .tally-grid {
    grid-template-columns: 1fr;
  }
}
