/* ===== MT5 vDealer — modern UI ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", "Courier New", monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --accent: #f28540;
  --accent-hover: #ff9a5a;
  --accent-muted: rgba(242, 133, 64, 0.15);
  --success: #3ecf8e;
  --danger: #ef5f67;
  --bg: #0b0f14;
  --bg-elevated: #121820;
  --surface: #161d27;
  --surface-2: #1c2532;
  --border: #2a3544;
  --border-strong: #3a4a5c;
  --text: #e8eef6;
  --text-muted: #8b9bb0;
  --text-disabled: #5a6a7e;
  --input-bg: #0e141c;
  --titlebar: #0f1620;
  --row-hover: rgba(242, 133, 64, 0.08);
  --row-selected: #f28540;
  --switch-off: #3a4656;
}

body.theme-light {
  --bg: #e8edf3;
  --bg-elevated: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4f8;
  --border: #d5dde8;
  --border-strong: #b8c4d4;
  --text: #1a2332;
  --text-muted: #5a6a7e;
  --text-disabled: #9aabbd;
  --input-bg: #ffffff;
  --titlebar: #ffffff;
  --shadow: 0 8px 28px rgba(20, 40, 70, 0.12);
  --row-hover: rgba(242, 133, 64, 0.1);
  --switch-off: #c5ced9;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ===== App shell ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--titlebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.app-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #e05a2b);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-lang-select {
  width: 112px;
  padding: 5px 28px 5px 8px;
  background-color: var(--surface);
  font-size: 11px;
}

.header-dealer-select {
  min-width: 160px;
  width: auto;
}

.admin-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.admin-panel {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.admin-panel[hidden] { display: none; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.admin-table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--border);
}

/* Two stacked sticky rows: titles, then the per-column filters.
   The title row keeps a fixed height so the filter row can offset by it. */
.admin-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 34px;
  padding-top: 6px;
  padding-bottom: 6px;
  box-sizing: border-box;
  background: var(--surface);
}

.admin-table thead .admin-filter-row th {
  top: 34px;
  z-index: 1;
  height: auto;
  padding: 4px 6px;
}

.admin-table tbody tr.filtered-out { display: none; }

.admin-table td.admin-actions {
  white-space: nowrap;
}

.admin-table td.admin-actions .btn + .btn {
  margin-left: 6px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  padding: 12px;
  align-items: end;
}

.app-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

/* ===== Cards / panels ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.card-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.card-body {
  padding: 12px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.card-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ===== Loading state ===== */
.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
}

.loading-overlay[hidden] { display: none; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-version {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-disabled);
  font-variant-numeric: tabular-nums;
}

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(242, 133, 64, 0.18), transparent),
    var(--bg);
}

.login-card {
  width: min(390px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-card-header {
  padding: 28px 28px 8px;
  text-align: center;
}

.login-card-header h1 {
  font-size: 20px;
  font-weight: 700;
  margin-top: 12px;
}

.login-card-header p {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 13px;
}

.login-card-body {
  padding: 20px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-page-tools {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-tool-select {
  width: 118px;
  padding-top: 6px;
  padding-bottom: 6px;
  background-color: var(--surface);
}

.login-message {
  min-height: 20px;
  padding: 0 2px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.login-message.is-error { color: var(--danger); }
.login-message.is-success { color: var(--success); }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===== Form controls ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.input-sm { padding: 6px 8px; }
.input-xs { padding: 3px 6px; font-size: 11px; }
.select.input-xs { padding-right: 20px; background-position: right 6px center; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b9bb0' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.textarea {
  resize: none;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.checkbox-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--input-bg);
  position: relative;
  flex-shrink: 0;
}

.checkbox.checked .checkbox-box {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox.checked .checkbox-box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  user-select: none;
  white-space: nowrap;
}

.btn:hover:not(.disabled) {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.btn:active:not(.disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(.disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--danger);
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 11px; }

.btn.disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* ===== Switch ===== */
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--switch-off);
  border-radius: 999px;
  transition: 0.15s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

.switch-label {
  font-weight: 600;
  font-size: 12px;
}

/* ===== Data table ===== */
.grid-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.data-table tbody tr:hover {
  background: var(--row-hover);
}

.data-table tbody tr.selected {
  background: var(--row-selected) !important;
  color: #fff;
}

.data-table tbody tr.rule-new td.col-name::after,
.data-table tbody tr.rule-dirty td.col-name::after {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  vertical-align: 1px;
}

.data-table tbody tr.rule-new td.col-name::after {
  content: "NEW";
  color: var(--accent);
  background: var(--accent-muted);
}

.data-table tbody tr.rule-dirty:not(.rule-new) td.col-name::after {
  content: "UNSAVED";
  color: var(--danger);
  background: rgba(239, 95, 103, 0.12);
}

.rules-empty td {
  padding: 28px 12px !important;
  color: var(--text-muted);
  text-align: center;
  white-space: normal !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.badge-on {
  background: rgba(62, 207, 142, 0.15);
  border-color: rgba(62, 207, 142, 0.35);
  color: var(--success);
}

.badge-off {
  background: rgba(239, 95, 103, 0.12);
  border-color: rgba(239, 95, 103, 0.3);
  color: var(--danger);
}

tr.selected .badge-on,
tr.selected .badge-off {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

/* ===== Rules side panel ===== */
.side-panel .grid-wrap {
  flex: 1 1 auto;
  min-height: 200px;
}

.rules-table th.col-drag,
.rules-table td.col-drag {
  width: 24px;
  padding-left: 8px;
  padding-right: 0;
}

.rules-table th.col-on,
.rules-table td.col-on { width: 54px; }

.rules-table th.col-weight,
.rules-table td.col-weight {
  width: 62px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rules-table td.col-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}

/* The whole row is a drag source, so text selection must not swallow the press. */
.rules-table tbody tr {
  user-select: none;
  cursor: grab;
}

.rules-table tbody tr.rules-empty { cursor: default; }

.drag-handle {
  display: block;
  color: var(--text-disabled);
  letter-spacing: -1px;
  line-height: 1;
}

.data-table tbody tr:hover .drag-handle { color: var(--text-muted); }
tr.selected .drag-handle { color: rgba(255, 255, 255, 0.75); }

.data-table tbody tr.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.data-table tbody tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.data-table tbody tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }

/* Preview of the pending position while the move is being confirmed. */
.data-table tbody tr.rule-moving td {
  background: var(--accent-muted);
  box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent);
}

.grid-hint {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-disabled);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== Connection block ===== */
.conn-body { flex: 0 0 auto; }

.conn-grid {
  display: grid;
  gap: 8px;
}

.conn-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

/* ===== Settings sheet ===== */
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.edit-status {
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.edit-status.status-clean {
  color: var(--text-muted);
}

.edit-status.status-new,
.edit-status.status-dirty {
  color: var(--accent);
  border-color: rgba(242, 133, 64, 0.35);
  background: var(--accent-muted);
}

.edit-status.status-saving {
  color: var(--text);
  animation: status-pulse 0.8s ease-in-out infinite alternate;
}

.edit-status.status-error {
  color: var(--danger);
  border-color: rgba(239, 95, 103, 0.35);
  background: rgba(239, 95, 103, 0.1);
}

@keyframes status-pulse {
  to { opacity: 0.55; }
}

.settings-actions {
  display: flex;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
}

.settings-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 20px;
}

.settings-card.editor-empty .settings-scroll {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Rule management dialogs ===== */
.rule-dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.rule-dialog::backdrop {
  background: rgba(4, 8, 12, 0.68);
  backdrop-filter: blur(2px);
}

.rule-dialog-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.rule-dialog-card h2 {
  font-size: 15px;
  font-weight: 700;
}

.rule-dialog-card p {
  color: var(--text-muted);
  line-height: 1.55;
}

.rule-dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; }

/* Rule name, type and state stay in view while the sheet scrolls. */
#section-general {
  position: sticky;
  top: 0;
  z-index: 4;
  padding-top: 4px;
  isolation: isolate;
  background: var(--surface) !important;
  box-shadow:
    0 -8px 0 8px var(--surface),
    0 6px 10px -8px rgba(0, 0, 0, 0.55);
}

/* Experiment: switching a section off removes it instead of greying it out.
   Wins over the display rules of the blocks it is applied to. */
.is-hidden { display: none !important; }

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.general-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1.6fr) repeat(3, minmax(120px, 1fr));
  gap: 14px;
  align-items: start;
}

.weight-view {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 30px;
}

.weight-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.weight-note { font-size: 11px; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.tab-headers {
  display: flex;
  gap: 4px;
  padding: 8px 8px 0;
  flex-shrink: 0;
  overflow-x: auto;
}

.tab-header {
  appearance: none;
  background: transparent;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border: 1px solid transparent;
  border-bottom: none;
  user-select: none;
  white-space: nowrap;
}

.tab-header:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab-header.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 1px 0 var(--surface);
}

.tab-client {
  position: relative;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px;
  overflow: hidden;
  display: flex;
}

.subtabs .tab-header {
  padding: 5px 8px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.subtabs .tab-header.active {
  background: var(--accent-muted);
  border-color: rgba(242, 133, 64, 0.35);
  color: var(--accent);
  box-shadow: none;
}

.subtab-panel {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  overflow: auto;
  padding: 6px;
}

/* ===== Cron value grid ===== */
.cron-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 4px;
}

.cron-cell {
  appearance: none;
  color: var(--text);
  font-family: inherit;
  text-align: center;
  padding: 6px 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.cron-cell:hover {
  border-color: var(--accent);
}

.cron-cell.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* ===== Saved schedule entries ===== */
.cron-entries {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  gap: 8px;
  min-height: 96px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
}

.cron-entry {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 190px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 11px;
  cursor: pointer;
}

.cron-entry:hover { border-color: var(--accent); }

.cron-entry.selected {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.cron-entry-row {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.cron-entry-label {
  color: var(--text-muted);
  white-space: nowrap;
}

.cron-entry-value {
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cron-empty {
  flex: 1;
  padding: 10px;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
}

/* ===== Checklist ===== */
.checklist {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 2px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}

.check-item:hover {
  background: var(--row-hover);
}

.check-item-box {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  position: relative;
  flex-shrink: 0;
}

.check-item.checked .check-item-box {
  background: var(--accent);
  border-color: var(--accent);
}

.check-item.checked .check-item-box::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check-item-label {
  font-size: 11px;
}

/* ===== Spin edit ===== */
.spinedit {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  overflow: hidden;
}

.spinedit input {
  border: none;
  background: transparent;
  padding: 6px 8px;
  outline: none;
  width: calc(100% - 22px);
  min-width: 0;
  color: var(--text);
}

.spinedit.is-decimal input {
  font-variant-numeric: tabular-nums;
}

.spinedit input[readonly] {
  cursor: default;
  color: var(--text-muted);
}

.spinedit:focus-within {
  border-color: var(--accent);
}

.field-hint {
  margin-left: 6px;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.spin-btns {
  display: flex;
  flex-direction: column;
  width: 22px;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}

.spin-up,
.spin-down {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: 8px;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  user-select: none;
}

.spin-up { border-bottom: 1px solid var(--border); }
.spin-up:hover,
.spin-down:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

/* ===== Misc layout helpers ===== */
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-muted); }
.toolbar-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-disabled);
  display: inline-block;
}

.status-dot.on {
  background: var(--success);
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.6);
}

/* Markup carries the most controls, so it gets the extra room. */
.exec-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.78fr) minmax(330px, 1.55fr) minmax(230px, 0.78fr);
  gap: 12px;
  align-items: start;
}

.exec-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.exec-panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.exec-panel-title:not(:first-child) {
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.exec-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto) auto;
  align-items: center;
  gap: 8px;
}

.exec-field .field-label { min-width: 0; }

.exec-input {
  width: 140px;
  min-width: 0;
}

.exec-field-wide { grid-template-columns: minmax(0, 1fr) auto; }

.exec-pair {
  display: flex;
  align-items: center;
  gap: 6px;
  grid-column: 1 / -1;
}

.exec-pair .spinedit {
  flex: 1;
  min-width: 0;
}

.exec-mode-value {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.exec-mode-value .spinedit {
  width: auto;
}

.exec-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.exec-plus {
  font-size: 10px;
  white-space: nowrap;
}

.exec-addon {
  display: none;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.addons-visible .exec-addon {
  display: flex;
}

/* Reserve room for the longest caption so toggling never moves the switch. */
.exec-addon .switch-label {
  min-width: 52px;
}

.override-disabled {
  opacity: 0.45;
  cursor: not-allowed !important;
}

.checkbox.override-disabled {
  pointer-events: none;
}

.spinedit:has(input:disabled) {
  opacity: 0.45;
  pointer-events: none;
}

.spinedit input:disabled {
  cursor: not-allowed;
}

/* Kept in DOM for the delay-distribution generator; not shown for now. */
.exec-delay-stats.is-parked { display: none !important; }

.delay-grid,
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.delay-grid .spinedit,
.stats-row .spinedit,
.stats-box .input {
  width: 100%;
}

.request-layout {
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) minmax(150px, 0.7fr) minmax(260px, 1.5fr);
  gap: 12px;
  align-items: stretch;
}

.request-list-field { min-width: 0; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.list-actions { display: flex; gap: 4px; }

.btn-xs {
  padding: 2px 8px;
  font-size: 10px;
  line-height: 1.6;
}

.request-checklist {
  width: 100%;
  height: 220px;
}

.request-criteria {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.request-volume-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.request-ip-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  align-items: center;
  gap: 12px;
}

.request-ip-row .switch-label { white-space: nowrap; }

.request-ip-field.ip-off #txtIpAddress {
  opacity: 0.5;
}

.user-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.stats-box .input {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* ===== Time section ===== */
.master-switch .switch-label { font-size: 13px; }

.time-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: opacity 0.15s;
}

.section-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: opacity 0.15s;
}

/* State follows the switches even before scripts run. */
#section-time:has(#timeFilterToggle:not(:checked)) .time-body,
#timeBody:has(#limitsToggle:not(:checked)) .date-range,
#section-user:has(#userFilterToggle:not(:checked)) .section-body,
#section-orders:has(#ordersFilterToggle:not(:checked)) .section-body {
  opacity: 0.45;
  pointer-events: none;
}

.time-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.time-toolbar .switch-row { padding-bottom: 8px; }

.date-range {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: opacity 0.15s;
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.date-sep {
  color: var(--text-muted);
  padding-bottom: 7px;
}

input.datetime {
  width: 190px;
  color-scheme: dark;
  font-variant-numeric: tabular-nums;
}

body.theme-light input.datetime { color-scheme: light; }

input.datetime::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.6;
}

input.datetime::-webkit-calendar-picker-indicator:hover { opacity: 1; }

.input:disabled,
.select:disabled {
  background: var(--surface-2);
  color: var(--text-disabled);
  cursor: not-allowed;
}

.switch input:disabled + .slider {
  opacity: 0.5;
  cursor: not-allowed;
}

.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.time-middle {
  display: flex;
  gap: 8px;
  height: 180px;
  min-height: 140px;
}

.time-middle .tabs {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.time-middle .tab-headers {
  background: var(--surface-2);
  padding: 6px;
}

.time-middle .tab-client {
  border-top: none;
  padding: 0;
  background: transparent;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

/* Responsive */
@media (max-width: 1280px) {
  .app-body {
    grid-template-columns: 320px minmax(0, 1fr);
  }
  .general-grid {
    grid-template-columns: minmax(180px, 1fr) repeat(2, minmax(110px, auto));
  }
  .request-layout {
    grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr);
  }
  .request-criteria { grid-column: 1 / -1; }
  .exec-layout {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; }
  .app-body {
    grid-template-columns: 1fr;
    height: auto;
  }
  .card { min-height: 280px; }
  .general-grid { grid-template-columns: 1fr 1fr; }
  .user-fields { grid-template-columns: 1fr 1fr; }
  .request-layout { grid-template-columns: 1fr 1fr; }
  .exec-layout { grid-template-columns: 1fr; }
  .settings-scroll { overflow-y: visible; }
}

@media (max-width: 520px) {
  .login-page {
    place-items: start center;
    padding: 82px 16px 20px;
  }
  .login-page-tools {
    top: 16px;
    right: 16px;
  }
  .login-card-header { padding-left: 20px; padding-right: 20px; }
  .login-card-body { padding-left: 20px; padding-right: 20px; }
}
