/* Automation simulator tab. Reuses the CRM's tokens and card styles; only the
   pieces that are new to this tab live here. */

.sim-head { margin-bottom: var(--space-3); }
.sim-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; line-height: 1.25; }
.sim-sub { margin: 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; max-width: 680px; }

.sim-controls { margin-bottom: var(--space-3); display: flex; flex-direction: column; gap: 12px; }
.sim-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.sim-field { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.sim-field select, .sim-field input, .sim-num, .sim-sentence select {
  font: inherit; font-size: 13px; font-weight: 500; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
.sim-field select option, .sim-sentence select option { color: #111; }
.sim-field select { max-width: 100%; }
.sim-blurb { margin: 0; flex: 1 1 320px; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.sim-transport .range-toggle { margin: 0; }
.sim-transport #sim-play { min-width: 92px; }
.sim-clock { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--text-faint); }
.sim-clock strong { font-size: 15px; color: var(--text); }
.sim-progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.sim-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.15s linear; }
.sim-options { font-size: 12.5px; }
.sim-notice {
  margin: 0; padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5;
  background: rgba(251, 140, 0, 0.14); border: 1px solid rgba(251, 140, 0, 0.45); color: #ffcc80;
}
.sim-check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); cursor: pointer; }
.sim-seed input { width: 96px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sim-kpis { grid-template-columns: repeat(3, 1fr); margin-bottom: var(--space-3); }
.stat-card .kpi-delta:not(.up):not(.down) { opacity: 0.9; }

.sim-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-3); overflow-x: auto; scrollbar-width: none; }
.sim-tabs::-webkit-scrollbar { display: none; }
.sim-tab {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 10px 14px; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--text-faint); cursor: pointer; white-space: nowrap;
}
.sim-tab:hover { color: var(--text); }
.sim-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sim-empty { padding: 18px 4px; margin: 0; font-size: 13px; line-height: 1.5; }
.is-focus { box-shadow: inset 3px 0 0 var(--m-orange); }

/* ---- Today: queue + feed ---- */
.sim-today { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
.q-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface-2); }
.q-item.q-high { border-left: 3px solid var(--red); }
.q-item.q-medium { border-left: 3px solid var(--amber); }
.q-item.q-opportunity { border-left: 3px solid var(--green); }
.q-item.is-focus { box-shadow: 0 0 0 1px var(--m-orange); }
.q-item.is-new { animation: q-arrive 1.2s ease-out 1; }
.q-new { font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #06202b; background: var(--accent); border-radius: 999px; padding: 2px 8px; }
@keyframes q-arrive { from { box-shadow: 0 0 0 3px rgba(47, 193, 232, 0.55); } to { box-shadow: 0 0 0 0 rgba(47, 193, 232, 0); } }
@media (prefers-reduced-motion: reduce) { .q-item.is-new { animation: none; } }
.q-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.q-name { font-size: 14px; }
.q-mrr { margin-left: auto; font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.q-block { margin-top: 8px; }
.q-block p, .q-block ul { margin: 2px 0 0; font-size: 13px; line-height: 1.5; }
.q-block ul { padding-left: 18px; }
.q-label { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-faint); }
.q-next p { border-left: 3px solid var(--m-orange); padding: 6px 10px; background: var(--surface); border-radius: 6px; }
.q-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.q-actions .form-hint { flex: 1 1 200px; }
.q-done { margin-top: 6px; }
.q-done summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-muted); padding: 6px 0; }
.q-done-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.q-done-row:last-child { border-bottom: none; }
.q-done-outcome { color: var(--text-muted); }
.sim-badge-human { background: rgba(251, 140, 0, 0.22); color: #ffb74d; }

.sim-feed-head { flex-wrap: wrap; }
.sim-feed-head .filter-chips { margin: 0; }
.feed { max-height: 620px; overflow-y: auto; }
.feed-row { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 12.5px; line-height: 1.45; }
.feed-row:last-child { border-bottom: none; }
.feed-day { color: var(--text-faint); font-weight: 600; white-space: nowrap; }
.feed-row.t-flag .feed-text { color: #ffb74d; }
.feed-row.t-human .feed-text { color: var(--green); }
.feed-row.t-outcome .feed-text { color: var(--text); font-weight: 600; }
.feed-row.t-warning .feed-text { color: var(--red); }
.feed-row.t-auto .feed-text { color: var(--text-muted); }

/* ---- Book: weights + table + breakdown ---- */
.sim-book { grid-template-columns: 1fr; }
.sim-weights { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; }
.sim-weight { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; font-size: 12.5px; }
.sim-weight-label { font-weight: 600; color: var(--text-muted); }
.sim-weight-val { font-weight: 700; color: var(--accent); text-align: right; }
.sim-weight input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }

table.sim-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.sim-table th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: 0.02em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.sim-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.sim-table td:first-child { white-space: normal; min-width: 160px; }
#book-body tr { cursor: pointer; }
#book-body tr:hover, #book-body tr:focus { background: var(--surface-2); outline: none; }
table.sim-table tr.is-off td { opacity: 0.5; }
.sim-delta { font-size: 11.5px; margin-left: 4px; }

.sim-breakdown .bd-head { display: flex; gap: 12px; align-items: center; margin: 6px 0 12px; }
.sim-breakdown .bd-head p { margin: 0; font-size: 13px; line-height: 1.5; }
.bd-score { font-size: 20px; padding: 6px 12px; }
.bd-row { margin-bottom: 10px; }
.bd-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
.bd-bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 5px 0 3px; }
.bd-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.bd-row .form-hint { margin: 0; }
.bd-persona { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--border); }
.bd-persona p { margin: 4px 0 0; font-size: 13px; line-height: 1.5; }

/* ---- Playbook builder ---- */
.sim-pb-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: var(--space-3); }
.sim-pb-head .card-title { margin: 0 0 4px; }
.sim-pb-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sim-rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: var(--space-3); }
.sim-rules > * { min-width: 0; }
.sim-rule.is-off { opacity: 0.55; }
.sim-rule-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sim-rule-name {
  flex: 1; min-width: 0; font: inherit; font-size: 14px; font-weight: 650; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px;
}
.sim-rule-name:hover, .sim-rule-name:focus { border-color: var(--border); background: var(--surface-2); outline: none; }
.sim-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.sim-sentence select { max-width: 100%; min-width: 0; }
.sim-sentence .kw { font-size: 11px; font-weight: 800; letter-spacing: 0.05em; color: var(--accent); }
.sim-num { width: 64px; }
.sim-num:disabled, .sim-sentence select:disabled { opacity: 0.45; }
.sim-inline-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.sim-cooldown { font-size: 12px; color: var(--text-faint); }
.sim-rule-plain { margin: 6px 0 0; padding-top: 8px; border-top: 1px dashed var(--border); line-height: 1.5; }

.sim-switch { position: relative; width: 36px; height: 20px; flex: none; cursor: pointer; }
.sim-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.sim-switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); transition: background 0.15s; }
.sim-switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-faint); transition: transform 0.15s, background 0.15s; }
.sim-switch input:checked + span { background: var(--accent-soft); border-color: var(--accent); }
.sim-switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }
.sim-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Results ---- */
.sim-results { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.res-stats { display: flex; gap: 10px; margin: 6px 0 10px; }
.res-stat { flex: 1; min-width: 0; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.res-stat strong { font-size: 20px; line-height: 1.1; }
.res-stat span { font-size: 11.5px; color: var(--text-faint); line-height: 1.35; }
.res-stat.is-good strong { color: var(--green); }
.res-stat.is-warn strong { color: var(--amber); }
.res-stat.is-bad strong { color: var(--red); }
.sim-results .form-hint { line-height: 1.5; }
.res-missed { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.5; }
.res-missed li { margin-bottom: 4px; }
.res-fix { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--accent-2); border-radius: 8px; background: var(--surface-2); }
.res-fix p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.5; }
table.sim-rules-table td:first-child { min-width: 200px; }

@media (max-width: 1024px) {
  .sim-today { grid-template-columns: 1fr; }
  .sim-results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .sim-title { font-size: 20px; }
  .sim-kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .sim-kpis > :last-child { grid-column: 1 / -1; }
  .sim-kpis .stat-card { padding: 12px 12px 8px; }
  .sim-kpis .stat-card .kpi-value { font-size: 21px; }
  .sim-results { grid-template-columns: 1fr; }
  .sim-rules { grid-template-columns: 1fr; }
  .sim-rule-head { flex-wrap: wrap; row-gap: 6px; }
  /* Name takes the row, so the fire count drops to its own line under it. */
  .sim-rule-name { flex: 1 1 60%; }
  .sim-rule-head [data-fires] { order: 3; margin-left: 46px; }
  .sim-clock { margin-left: 0; align-items: flex-start; width: 100%; flex-direction: row; gap: 8px; align-items: baseline; }
  .sim-transport .btn { flex: 1 1 auto; }
  .sim-field { flex-wrap: wrap; width: 100%; }
  .sim-field select { width: 100%; }
  .feed { max-height: 420px; }
  /* Book table on a phone: account, health, last login, status. */
  #book-body td:nth-child(3), #book-body td:nth-child(4), #book-body td:nth-child(6),
  #book-body td:nth-child(7), #book-body td:nth-child(8), #book-body td:nth-child(9),
  .sim-book thead th:nth-child(3), .sim-book thead th:nth-child(4), .sim-book thead th:nth-child(6),
  .sim-book thead th:nth-child(7), .sim-book thead th:nth-child(8), .sim-book thead th:nth-child(9) { display: none; }
  table.sim-table th, table.sim-table td { padding: 8px 6px; }
  table.sim-table td:first-child { min-width: 0; }
}
