:root {
  --bg: #0f1419;
  --panel: #1a222d;
  --border: #2d3a4d;
  --text: #e8eef5;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --danger: #f87171;
  --ok: #4ade80;
  --warn: #fbbf24;
  /* “Open simulated position” — action panel vs read-only position views */
  --order-surface: #141c28;
  --order-border: rgba(61, 139, 253, 0.45);
  --order-glow: rgba(61, 139, 253, 0.12);
  font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.env-switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 0.6rem;
}

.env-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.env-btn:last-child {
  border-right: none;
}

.env-btn.active {
  background: rgba(61, 139, 253, 0.18);
  color: var(--text);
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  max-width: 52rem;
}

.layout {
  min-height: calc(100vh - 5rem);
}

.main-content {
  padding: 1rem 1.5rem 2rem;
  max-width: 120rem;
}

.app-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1rem;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.55rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(61, 139, 253, 0.08);
}

.tab-panel {
  display: none;
}

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

.omnibus-block {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.omnibus-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
}

.omnibus-block h2,
.omnibus-tab-funding h2,
.funding-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.omnibus-asset-caption {
  margin: 0 0 0.5rem;
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1.35;
}

.omnibus-buffer-control {
  display: flex;
  gap: 0.45rem;
  align-items: flex-end;
  margin-bottom: 0.6rem;
}

.omnibus-buffer-control label {
  flex: 1;
  min-width: 0;
}

.omnibus-buffer-control input {
  width: 100%;
}

.danger-action {
  color: var(--danger) !important;
  border-color: rgba(248, 113, 113, 0.45) !important;
}

.omnibus-table-wrap {
  overflow-x: auto;
  margin-bottom: 0.65rem;
}

.omnibus-section .omnibus-table-wrap {
  max-width: 100%;
}

.omnibus-section .ledger-details {
  margin-top: 0.95rem;
}

.omnibus-asset-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.62rem;
}

.omnibus-asset-table th,
.omnibus-asset-table td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.3rem;
  text-align: right;
}

.omnibus-asset-table th:first-child,
.omnibus-asset-table td:first-child {
  text-align: left;
}

.omnibus-asset-table th {
  color: var(--muted);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.2);
}

.omnibus-asset-table tr.long .side {
  color: var(--ok);
}

.omnibus-asset-table tr.short .side {
  color: var(--danger);
}

.omnibus-asset-table tr.flat .side {
  color: var(--muted);
}

.omnibus-tab-funding {
  margin-bottom: 1.1rem;
}

.funding-panel .funding-controls {
  margin-bottom: 0.5rem;
}

.funding-panel #fundingEventView {
  font-size: 0.72rem;
  overflow-x: auto;
}

.funding-panel #fundingEventView table {
  font-size: 0.68rem;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.stat span:first-child {
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.live-feed-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.live-feed {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  min-width: 11rem;
}

.live-feed-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.live-feed-price {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ok);
}

.live-feed-meta {
  font-size: 0.65rem;
  margin-top: 0.15rem;
}

.sync-check {
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.sync-check input {
  min-width: auto;
}

.summary-section {
  margin-bottom: 1rem;
}

.summary-section h2 {
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
}

.staging-perp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-top: 0.35rem;
}

.staging-perp-table th,
.staging-perp-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.staging-perp-table th {
  color: var(--muted);
  font-weight: 600;
}

.staging-perp-table tr.long .side {
  color: var(--ok);
}

.staging-perp-table tr.short .side {
  color: var(--danger);
}

.staging-perp-table .neg {
  color: var(--danger);
}

.staging-perp-table .pos {
  color: var(--ok);
}

.positions-source-hint {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.summary-table th,
.summary-table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.summary-table th:first-child,
.summary-table td:first-child,
.summary-table th:nth-child(2),
.summary-table td:nth-child(2),
.summary-table th:nth-child(4),
.summary-table td:nth-child(4) {
  text-align: left;
}

.summary-table .summary-net-pos {
  text-align: left;
  max-width: 14rem;
  white-space: normal;
  line-height: 1.35;
  font-size: 0.72rem;
}

.summary-table tbody tr {
  cursor: pointer;
}

.summary-table tbody tr:hover {
  background: rgba(61, 139, 253, 0.08);
}

.summary-table tbody tr.selected {
  background: rgba(61, 139, 253, 0.15);
}

.summary-table tfoot tr {
  cursor: default;
}

.summary-table tfoot tr:hover {
  background: transparent;
}

.summary-table .summary-totals-row {
  background: rgba(61, 139, 253, 0.1);
  font-weight: 600;
}

.summary-table .summary-totals-row td {
  border-bottom: none;
}

.summary-table .sel-arrow {
  width: 1.5rem;
  color: var(--accent);
}

.summary-table .neg {
  color: var(--danger);
}

.summary-table .pos {
  color: var(--ok);
}

.summary-table .danger {
  color: var(--danger);
  font-weight: 600;
}

.funding-panel {
  margin-bottom: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.ledger-details {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  overflow: visible;
}

/* Open ledger stacks above the next card so wide tables aren’t visually buried */
.ledger-details[open] {
  position: relative;
  z-index: 1;
}

.ledger-details > summary {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  list-style: none;
  list-style-type: none;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 7px 7px 0 0;
}

.ledger-details:not([open]) > summary {
  border-radius: 7px;
}

.ledger-details > summary::-webkit-details-marker,
.ledger-details > summary::marker {
  display: none;
}

/* Prominent chevron (rotates when open) */
.ledger-details > summary::after {
  content: '';
  display: block;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: auto;
  flex-shrink: 0;
  border-right: 3px solid var(--accent);
  border-bottom: 3px solid var(--accent);
  transform: translate(0, -0.12em) rotate(45deg);
  opacity: 1;
}

.ledger-details[open] > summary::after {
  transform: translate(0, 0.12em) rotate(-135deg);
}

.ledger-details-body {
  padding: 0.5rem 0.65rem 0.75rem;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.ledger-details-body table {
  min-width: 36rem;
}

.ledger-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.ledger-filters button {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.ledger-filters button.active {
  background: rgba(61, 139, 253, 0.2);
  border-color: var(--accent);
  color: var(--text);
}

.funding-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.9rem;
  align-items: flex-end;
  margin-bottom: 0.6rem;
}

.danger-text {
  color: var(--danger);
}

.user-radios {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.user-radios legend {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 0.25rem;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}

.radio-pill input {
  min-width: auto;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
}

input,
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  min-width: 7rem;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.45rem 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.user-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin-bottom: 1.25rem;
}

.user-detail-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.2rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
}

.user-panel h2,
.user-detail-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.section-title {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.metric {
  background: var(--bg);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.metric .k {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
}

.metric .v {
  font-size: 1rem;
  font-weight: 600;
}

.metric.danger .v {
  color: var(--danger);
}

.metric.ok .v {
  color: var(--ok);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th,
td {
  text-align: right;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 500;
}

tr.long td.side {
  color: var(--ok);
}

tr.short td.side {
  color: var(--danger);
}

.btn-close,
.btn-close-position {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
  white-space: nowrap;
}

.btn-close:hover:not(:disabled),
.btn-close-position:hover:not(:disabled) {
  background: rgba(251, 191, 36, 0.25);
  border-color: var(--warn);
}

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

.order-result {
  margin-top: 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--order-border);
  font-size: 0.75rem;
  min-height: 1.25rem;
}

.order-result:empty {
  display: none;
}

.order-result--error {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
}

.order-result--success {
  color: var(--ok);
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.08);
}

.user-detail-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
}

.user-detail-card-header h2 {
  margin: 0;
}

.user-detail-tabs {
  margin: 0.65rem 0 0.75rem;
}

.user-detail-tabs .tab-btn {
  font-size: 0.72rem;
  padding: 0.42rem 0.7rem;
}

.user-detail-tab-panels {
  margin-top: 0.25rem;
}

.user-tab-panel {
  display: none;
  padding-top: 0.15rem;
}

.user-tab-panel.active {
  display: block;
}

.user-tab-panel .tab-source-hint {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
}

.user-detail-card .metrics {
  margin-bottom: 0.75rem;
}

.user-detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn-user-action {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.btn-user-action:hover {
  transform: translateY(-1px);
}

.btn-user-action:active {
  transform: translateY(0);
}

.btn-user-action--order {
  background: var(--accent);
  color: #0a0e14;
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-user-action--order:hover {
  background: #5a9dff;
}

.btn-user-action--transfer {
  background: rgba(61, 139, 253, 0.12);
  color: var(--accent);
  border-color: var(--order-border);
}

.btn-user-action--transfer:hover {
  background: rgba(61, 139, 253, 0.22);
  border-color: var(--accent);
}

.btn-user-action--key {
  background: rgba(167, 139, 250, 0.12);
  color: #c4b5fd;
  border-color: rgba(167, 139, 250, 0.45);
}

.btn-user-action--key:hover {
  background: rgba(167, 139, 250, 0.22);
  border-color: #c4b5fd;
}

.users-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.users-section-header h2 {
  margin: 0;
}

.key-hint {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.8rem;
}

.btn-cancel-order {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  white-space: nowrap;
}

.btn-cancel-order:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.28);
  border-color: var(--danger);
}

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

.transfer-dialog {
  border: 1px solid var(--order-border);
  border-radius: 10px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  max-width: 22rem;
  width: calc(100% - 2rem);
}

.transfer-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.transfer-form {
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.transfer-form h2 {
  margin: 0;
  font-size: 1rem;
}

.transfer-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.transfer-form input,
.transfer-form select {
  font-size: 0.8rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-width: min(24rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  position: relative;
  pointer-events: auto;
  padding: 0.7rem 2rem 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(165deg, var(--order-surface) 0%, var(--panel) 100%);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.28s ease;
}

.toast--out {
  animation: toast-out 0.28s ease forwards;
}

.toast--fill {
  border-left: 4px solid var(--ok);
}

.toast--info {
  border-left: 4px solid var(--accent);
}

.toast--warn {
  border-left: 4px solid var(--warn);
}

.toast-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.toast--fill .toast-title {
  color: var(--ok);
}

.toast--warn .toast-title {
  color: var(--warn);
}

.toast-body {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text);
}

.toast-close {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.toast-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(1rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(1rem);
  }
}

/* —— Order scripts (modal) —— */
.order-scripts-dialog {
  border: 1px solid var(--order-border);
  border-radius: 12px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  max-width: min(64rem, calc(100vw - 1.5rem));
  width: calc(100% - 1.5rem);
  max-height: calc(100vh - 2rem);
  overflow: hidden;
}

.order-scripts-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.order-scripts-dialog-inner {
  padding: 1rem 1.1rem 1.15rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.scripts-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.scripts-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.scripts-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  color: var(--accent);
}

.scripts-lead {
  margin: 0;
  max-width: 40rem;
  font-size: 0.82rem;
}

.scripts-layout {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 800px) {
  .scripts-layout {
    grid-template-columns: 1fr;
  }
}

.scripts-list-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  min-height: 12rem;
  max-height: min(60vh, 32rem);
  overflow: auto;
}

.scripts-list {
  display: flex;
  flex-direction: column;
  padding: 0.35rem;
  gap: 0.25rem;
}

.script-list-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.script-list-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.script-list-item.active {
  background: rgba(61, 139, 253, 0.12);
  border-color: var(--order-border);
  color: var(--accent);
}

.script-list-item .script-list-meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.scripts-editor-pane {
  min-width: 0;
}

.script-editor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.script-editor-top {
  display: grid;
  grid-template-columns: 1.4fr minmax(8rem, 11rem) minmax(8rem, 11rem);
  gap: 0.75rem;
}

@media (max-width: 900px) {
  .script-editor-top {
    grid-template-columns: 1fr;
  }
}

.script-editor label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.script-editor input,
.script-editor select,
.script-editor textarea {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}

.script-notes-field textarea {
  resize: vertical;
  min-height: 2.5rem;
}

.script-steps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.script-steps-header h3,
.script-run-box h3 {
  margin: 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.script-steps {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.script-step-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 0.65rem 0.75rem;
}

.script-step-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.script-step-card-head strong {
  font-size: 0.8rem;
}

.script-step-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.5rem 0.65rem;
}

.script-step-grid label.span-2 {
  grid-column: span 2;
}

.script-step-reduce {
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem !important;
  margin-top: 0.55rem;
  color: var(--text);
  font-size: 0.8rem;
}

.script-step-actions {
  display: flex;
  gap: 0.35rem;
}

.script-step-actions button {
  font-size: 0.7rem;
  padding: 0.25rem 0.45rem;
}

.script-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

.btn-danger-outline {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.55);
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: rgba(248, 113, 113, 0.12);
}

.script-run-box {
  margin-top: 0.35rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.script-run-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem;
  margin: 0.55rem 0 0.65rem;
}

.script-run-controls label {
  min-width: 9rem;
}

.script-run-log {
  margin: 0;
  min-height: 6rem;
  max-height: 16rem;
  overflow: auto;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b0f14;
  color: #c8d0da;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
}

.script-run-log:empty::before {
  content: 'Run log appears here…';
  color: var(--muted);
}

.script-log-line {
  display: block;
  margin: 0 0 0.2rem;
  word-break: break-word;
}

.script-log-ts {
  color: var(--muted);
}

.script-log-line--error,
.script-log-line--error .script-log-msg {
  color: var(--danger);
}

.script-log-details {
  display: inline;
  margin-left: 0.15rem;
}

.script-log-details > summary {
  display: inline;
  cursor: pointer;
  color: var(--accent);
  list-style: none;
  user-select: none;
}

.script-log-details > summary::-webkit-details-marker {
  display: none;
}

.script-log-details > summary::before {
  content: '▸ ';
  color: var(--accent);
}

.script-log-details[open] > summary::before {
  content: '▾ ';
}

.script-log-details-body {
  display: block;
  margin: 0.35rem 0 0.45rem 0.85rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: #c8d0da;
  white-space: pre-wrap;
  font: inherit;
  overflow: auto;
  max-height: 14rem;
}

.scripts-csv-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.scripts-file-hint {
  margin: 0;
  font-size: 0.82rem;
}

.scripts-file-hint code {
  font-size: 0.78rem;
}

.scripts-file-editor {
  width: 100%;
  min-height: min(55vh, 28rem);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #c8d0da;
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  tab-size: 2;
}

.scripts-file-editor:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.scripts-file-status {
  font-size: 0.78rem;
  align-self: center;
}

.scripts-file-status.is-error {
  color: var(--danger);
}

.scripts-file-status.is-ok {
  color: var(--ok);
}
