/* Page-specific grids and blocks. */

/* ---------- platform dashboard ---------- */
.row-3 { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(0, 1.1fr) minmax(0, .85fr); gap: 14px; }
.row-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

.mode-body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; padding: 16px 18px 18px; }
.mode-switch { display: flex; align-items: center; gap: 12px; }
.mode-btn {
  min-width: 86px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--sunken); color: var(--text-3);
  font-size: 17px; font-weight: 600; letter-spacing: .02em; text-align: center;
}
.mode-btn.on { background: var(--blue-soft); border-color: var(--blue-line); color: #6fa8ff; }
.mode-btn.on.live { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.mode-toggle {
  position: relative; width: 52px; height: 30px; flex-shrink: 0;
  border-radius: 15px; border: 1px solid var(--line-3); background: #2a3448;
}
.mode-toggle::after {
  content: ""; position: absolute; top: 3px; left: 4px; width: 22px; height: 22px;
  border-radius: 50%; background: #dfe6f1;
}
.mode-toggle.live { background: var(--green-2); border-color: var(--green); }
.mode-toggle.live::after { left: auto; right: 4px; }
.otp-block { min-width: 0; padding-left: 16px; border-left: 1px solid var(--line-2); }
.otp-label { margin-bottom: 10px; color: var(--text-2); font-size: 12.5px; }
.otp-block .btn { margin-top: 10px; width: 100%; }
.otp-block .btn-muted { font-size: 14.5px; }
.live-form { margin: 0; }
.mode-caption { margin-top: 12px; color: var(--text-3); font-size: 12px; text-align: center; }
.mode-note { display: flex; align-items: flex-start; gap: 12px; }
.mode-note > .icon { width: 22px; height: 22px; margin-top: 1px; }
.mode-note strong { display: block; font-size: 14.5px; }
.mode-note p { margin-top: 3px; color: var(--text-2); font-size: 13px; }
.mode-note.live > .icon, .mode-note.live strong { color: var(--green-text); }
.mode-note.halt > .icon, .mode-note.halt strong { color: var(--red-text); }
.danger-body { padding: 12px 18px 18px; }
.danger-body p { margin-bottom: 16px; font-size: 13.5px; }
.danger-body form { margin: 0; }
.btn-stop { width: 100%; min-height: 48px; gap: 12px; font-size: 15px; font-weight: 600; }
.btn-stop .sq { width: 16px; height: 16px; border-radius: 3px; background: #fff; }
.paper-state {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--red-line); border-radius: var(--radius-sm); background: rgb(0 0 0 / 18%);
}
.paper-state > .icon { width: 22px; height: 22px; margin-top: 1px; color: var(--blue-text); }
.paper-state strong { display: block; color: var(--text); font-size: 14.5px; }
.card.danger .paper-state p { margin: 3px 0 0; font-size: 13px; }
.danger-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 14px;
  color: var(--red-text); font-size: 13.5px; font-weight: 500;
}
.danger-link .icon { width: 16px; height: 16px; }
.card-head > .icon.pulse { color: var(--green); }
.card-head > .system-badge { margin-left: auto; padding: 4px 11px; font-size: 12.5px; }
.card > .kv { padding: 14px 18px 18px; }
.stop-banner { margin: 14px 18px 0; }

/* broker and stop tables */
.broker-icon { width: 22px; height: 22px; color: var(--text-2); }
.broker-icon.binance { color: var(--brand-binance); }
.stop-table .details-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* narrow containers (e.g. the /admin/system column): single-line cells, details on expand */
.stop-table-wrap { container: stops / inline-size; }
@container stops (min-width: 640px) and (max-width: 899.98px) {
  .stop-table td { white-space: nowrap; }
  .stop-table th, .stop-table td { padding-left: 12px; padding-right: 12px; }
  .stop-table th:first-child, .stop-table td:first-child { padding-left: 18px; }
  .stop-table .col-details { display: none; }
}
.stop-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; margin-bottom: 10px; font-size: 13px; }
.stop-meta div { display: flex; gap: 8px; }
.stop-meta dt { color: var(--text-3); }
.stop-meta dd { color: var(--text); }
.stop-items li { display: flex; align-items: baseline; gap: 10px; font-size: 13.5px; }
.stop-items li .dot { transform: translateY(-1px); }
.stop-items strong { color: var(--text); font-weight: 500; white-space: nowrap; }
.card > .table-wrap:last-child { border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- broker accounts page ---------- */
.brokers-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
.brokers-grid .card-body { padding-top: 16px; }

/* ---------- admin overview ---------- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; align-items: start; }
.overview-main, .overview-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.overview-bottom { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: stretch; }
.overview-bottom > .card { display: flex; flex-direction: column; }
.filters { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.filters .input-wrap { width: 240px; }
.filters .input { min-height: 38px; }
.filters select.input { width: auto; min-width: 170px; }

/* users table: sized by its card (container), so the overview column and the full-width
   /admin/users page each get the densest layout that fits */
.users-card { container: users / inline-size; }
.users-table th, .users-table td { padding-left: 11px; padding-right: 11px; font-size: 13.5px; }
.users-table th { font-size: 12.5px; }
.users-table th.wrap { white-space: normal; line-height: 1.25; }
.users-table th:first-child, .users-table td:first-child { padding-left: 18px; }
.users-table th:last-child, .users-table td:last-child { padding-right: 14px; }
.users-table td { padding-top: 9px; padding-bottom: 9px; }
.users-table .name-cell { font-weight: 500; white-space: nowrap; }
.users-table .name-cell .sub {
  display: none; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-2); font-size: 12.5px; font-weight: 400;
}
.users-table .role-tag {
  display: none; margin-left: 8px; padding: 0 6px; border: 1px solid var(--violet-line); border-radius: 5px;
  background: var(--violet-soft); color: var(--violet-text); font-size: 11px; font-weight: 500; vertical-align: 1px;
}
.users-table .tfa { display: inline-flex; align-items: center; gap: 7px; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
.row-actions form, .row-primary { margin: 0; }
.row-actions .btn-sm { padding-left: 10px; padding-right: 10px; }
.row-actions .btn-icon { width: 28px; }
.self-note { color: var(--text-3); font-size: 13px; font-style: italic; padding-right: 10px; }
.users-card .card-foot { color: var(--text-2); }
@container users (max-width: 1099.98px) {
  .users-table .col-email { display: none; }
  .users-table .name-cell .sub { display: block; }
  .users-table th, .users-table td { padding-left: 9px; padding-right: 9px; font-size: 13px; }
  .users-table .chip { padding: 1px 8px; font-size: 12.5px; }
}
@container users (max-width: 899.98px) {
  .users-table .col-role { display: none; }
  .users-table .role-tag { display: inline-block; }
  .users-table th, .users-table td { padding-left: 8px; padding-right: 8px; }
}
.users-table .menu-primary { display: none; }
@container users (max-width: 639.98px) {
  .users-table .col-optional, .users-table .row-primary { display: none; }
  .users-table .menu-primary { display: block; }
  .users-table .actions-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .users-table .name-cell .sub { max-width: 150px; }
  .users-table th:first-child, .users-table td:first-child { padding-left: 16px; }
}

/* invite card */
.invite-card .card-body { padding-top: 18px; gap: 16px; }
.invite-result {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 14px;
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--sunken);
}
.invite-result .copy-field { background: var(--bg); }
.copy-btn { flex-shrink: 0; color: var(--blue-text); }
.copy-btn.btn-icon { width: 30px; min-height: 30px; }
.copy-btn.is-copied { color: var(--green-text); }
.card-note { display: flex; align-items: flex-start; gap: 8px; color: var(--text-2); font-size: 12.5px; }
.card-note .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--text-3); }

/* global stop card */
.global-stop-card .card-head > .icon { width: 26px; height: 26px; }
.global-stop-card h2 { font-size: 18px; }
.global-stop-card .card-body { padding-top: 10px; }
.global-stop-card .lead { margin-bottom: 18px; font-size: 13.5px; line-height: 1.55; }
.global-stop-card label { color: var(--text); }
.global-stop-card .input.mono::placeholder { font-family: var(--font-sans); }
.global-stop-card .input { background: rgb(8 12 20 / 55%); border-color: var(--red-line); }
.global-stop-card .input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgb(239 68 68 / 25%); }
.global-stop-card .btn-lg { margin-top: 4px; }
.halt-state { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
.card.danger .halt-state p { font-size: 13.5px; }
.card.danger .halt-state strong { color: var(--red-text); }

/* system card */
.system-card { container: system / inline-size; }
.system-card .card-head { flex-wrap: wrap; align-items: center; }
.system-card .card-head > div:not(.card-actions) { flex: 1 1 180px; min-width: 0; }
.system-card .card-head h2 { white-space: normal; }
.uptime { gap: 8px; color: var(--text-2); font-size: 13.5px; white-space: nowrap; }
.uptime [data-live="uptime"] { color: var(--text); }
.system-banner {
  display: flex; align-items: center; gap: 14px; margin: 16px 18px 0; padding: 14px 16px;
  border: 1px solid var(--green-line); border-radius: 10px; background: var(--green-soft);
}
.system-banner > .icon { width: 36px; height: 36px; padding: 8px; border-radius: 50%; background: rgb(34 197 94 / 18%); color: var(--green-text); }
.system-banner strong { display: block; font-size: 15px; font-weight: 600; }
.system-banner span { color: var(--text-2); font-size: 12.5px; }
.system-banner .when-bad, .system-banner:not([data-worker-status="active"]) .when-ok { display: none; }
.system-banner:not([data-worker-status="active"]) .when-bad { display: inline-block; }
.system-banner[data-worker-status="standby"] { border-color: var(--amber-line); background: var(--amber-soft); }
.system-banner[data-worker-status="standby"] > .icon { color: var(--amber-text); background: rgb(245 184 61 / 16%); }
.system-banner[data-worker-status="down"], .system-banner[data-worker-status=""] { border-color: var(--red-line); background: var(--red-soft); }
.system-banner[data-worker-status="down"] > .icon, .system-banner[data-worker-status=""] > .icon { color: var(--red-text); background: rgb(239 68 68 / 16%); }
.system-card > .table-wrap { margin-top: 16px; }
.worker-table td { padding-top: 12px; padding-bottom: 12px; }
.worker-table td.mono { font-size: 13px; }
.worker-table .sub { display: none; color: var(--text-3); font-size: 12px; }
.worker-table th.wrap { white-space: normal; line-height: 1.25; }
@container system (max-width: 459.98px) {
  .worker-table .col-version { display: none; }
  .worker-table .sub { display: block; }
  .worker-table th, .worker-table td { padding-left: 10px; padding-right: 10px; }
  .worker-table th:first-child, .worker-table td:first-child { padding-left: 18px; }
}

/* audit timeline: two lines per entry in narrow cards (action + time, user + IP), one aligned
   row per entry when the card is wide enough */
.audit-card .card-body { container: audit / inline-size; padding-top: 12px; }
.audit-card .card-head { align-items: center; }
.audit-timeline .timeline-item { padding: 7px 0; }
.audit-timeline .timeline-item > .dot { margin-top: 5px; }
.audit-timeline .timeline-item::after { top: 26px; bottom: -5px; }
.audit-timeline .timeline-body {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 12px;
  align-items: baseline; font-size: 13px;
}
.audit-timeline .what { grid-row: 1; grid-column: 1; color: var(--text); font-weight: 500; }
.audit-timeline time { grid-row: 1; grid-column: 2; color: var(--text-2); font-size: 12px; white-space: nowrap; }
.audit-timeline .who { grid-row: 2; grid-column: 1; color: var(--text-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-timeline .ip { grid-row: 2; grid-column: 2; color: var(--text-3); font-size: 11.5px; text-align: right; white-space: nowrap; }
.audit-timeline .target { display: block; overflow: hidden; color: var(--text-3); font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
@container audit (min-width: 560px) {
  .audit-timeline .timeline-body { grid-template-columns: 150px minmax(0, 1fr) minmax(0, 1.2fr) 120px; gap: 4px 14px; }
  .audit-timeline .ip { overflow: hidden; text-overflow: ellipsis; }
  .audit-timeline time, .audit-timeline .who, .audit-timeline .what, .audit-timeline .ip { grid-row: 1; grid-column: auto; }
  .audit-timeline time { order: 1; }
  .audit-timeline .who { order: 2; color: var(--text); font-size: 13px; }
  .audit-timeline .what { order: 3; font-weight: 400; }
  .audit-timeline .ip { order: 4; }
  .audit-timeline .target { display: inline; white-space: normal; overflow-wrap: anywhere; }
}
.timeline-empty { padding: 10px 0; color: var(--text-2); }

/* link page */
.link-card { max-width: 720px; }
.link-card .copy-field { padding-left: 14px; }

/* ---------- responsive ---------- */
@media (max-width: 1279.98px) {
  .brokers-grid { grid-template-columns: minmax(0, 1fr); }
  .row-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .row-3 > :first-child { grid-column: 1 / -1; }
  .row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-bottom { grid-template-columns: minmax(0, 1fr); }
  .overview-grid { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 1023.98px) {
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .filters { width: 100%; margin-left: 0; }
  .filters .input-wrap { flex: 1; width: auto; }
}
@media (max-width: 639.98px) {
  .row-3, .row-4 { grid-template-columns: minmax(0, 1fr); }
  .mode-body { grid-template-columns: minmax(0, 1fr); }
  .otp-block { padding: 14px 0 0; border-left: 0; border-top: 1px solid var(--line-2); }
  .mode-switch { justify-content: center; }
  .card-head { flex-wrap: wrap; }
  .card-head > .icon + div { flex: 1 1 160px; min-width: 0; }
  .card-head h2 { white-space: normal; }
  .table .col-optional { display: none; }
  .table th, .table td { padding-left: 10px; padding-right: 10px; }
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .table .cell-icon { gap: 8px; }
  .table td .chip { padding: 2px 8px; font-size: 12px; }
  .filters { flex-wrap: wrap; }
  .filters .input-wrap { flex: 1 1 100%; }
  .filters select.input { flex: 1; }
  .users-table th:first-child, .users-table td:first-child { padding-left: 16px; }
}
