:root {
  --bg:        #fafaf7;
  --fg:        #1a1a1a;
  --muted:     #6b7280;
  --accent:    #2563eb;
  --border:    #e5e7eb;
  --warn-bg:   #fef3c7;
  --warn-fg:   #78350f;
  --error-bg:  #fee2e2;
  --error-fg:  #7f1d1d;
  --ok-bg:     #d1fae5;
  --ok-fg:     #064e3b;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

header .brand {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--fg);
  text-decoration: none;
}

header nav { display: flex; gap: 1rem; }
header nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
}
header nav a:hover { text-decoration: underline; }

header .btn-sync {
  background: white;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  width: auto;
}
header .btn-sync:hover { background: #f3f4f6; }
header .btn-sync:disabled {
  opacity: 0.55;
  cursor: progress;
}

main {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

h1 { margin-top: 0.25rem; font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin-top: 1.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
th { background: #f3f4f6; font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }

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

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
}
.badge.channel-text  { background: #ddd6fe; color: #4c1d95; }
.badge.channel-email { background: #bbf7d0; color: #14532d; }
.badge.channel-sms   { background: #fde68a; color: #78350f; }
.badge.channel-voice { background: #fbcfe8; color: #831843; }

.badge.status-parsing      { background: #e5e7eb; color: #374151; }
.badge.status-needs_info   { background: var(--warn-bg);  color: var(--warn-fg); }
.badge.status-complete     { background: var(--ok-bg);    color: var(--ok-fg); }
.badge.status-unparseable  { background: var(--error-bg); color: var(--error-fg); }
.badge.status-approved     { background: #dbeafe; color: #1e40af; }
.badge.status-rejected     { background: #f3f4f6; color: #6b7280; }
.badge.status-executed     { background: #d1fae5; color: #065f46; }

.status-summary {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.5rem;
}

/* Detail page */
.back-link {
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 0.75rem;
  align-items: start;
}
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-source pre.raw-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  max-height: 60vh;
  overflow: auto;
}
.detail-source h2 { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.detail-form .form-field {
  display: block;
  margin-bottom: 0.85rem;
}
.detail-form .form-field input[type="text"],
.detail-form .form-field textarea,
.detail-form .form-field select {
  width: 100%;
  font-family: inherit;
  font-size: 0.92rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  margin-top: 0.25rem;
}
.detail-form .form-field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
.detail-form .field-label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-weight: 500;
  font-size: 0.9rem;
}
.detail-form .req-marker { color: #b91c1c; }
.detail-form .field-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.detail-form .field-note {
  display: block;
  font-size: 0.82rem;
  color: var(--warn-fg);
  background: var(--warn-bg);
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  border-left: 3px solid #d97706;
  margin: 0.3rem 0 0.4rem;
  line-height: 1.35;
}
.detail-form .field-note strong { font-weight: 600; }
.detail-form .value-description {
  display: block;
  font-size: 0.82rem;
  color: var(--ok-fg);
  background: var(--ok-bg);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.25rem;
  font-weight: 500;
  width: fit-content;
}
.detail-form .hint-marker {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 500;
}
.detail-form .missing-marker {
  background: var(--error-bg);
  color: var(--error-fg);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 500;
}

/* Field state borders */
.detail-form .form-field.field-missing input,
.detail-form .form-field.field-missing textarea,
.detail-form .form-field.field-missing select {
  border-color: #dc2626;
  background: #fef2f2;
}
.detail-form .form-field.field-low-conf input,
.detail-form .form-field.field-low-conf textarea,
.detail-form .form-field.field-low-conf select {
  border-color: #d97706;
  background: #fffbeb;
}

.alert {
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.alert-warn      { background: var(--warn-bg);  color: var(--warn-fg); }
.alert-warn-soft { background: #fffbeb;          color: #78350f; }
.alert-error     { background: var(--error-bg); color: var(--error-fg); }

.form-buttons { margin-top: 0.75rem; }
.approve-form { margin-top: 1rem; }
.btn-save     { background: var(--accent); }
.btn-approve  { background: #047857; }
.btn-approve:hover:not([disabled]) { background: #065f46; }
.btn-approve[disabled] { background: #94a3b8; cursor: not-allowed; }
.btn-reject   { background: #b91c1c; margin-top: 0.5rem; }
.btn-reject:hover { background: #991b1b; }
.btn-ask-customer { background: #6b7280; margin-top: 1rem; }
.btn-ask-customer[disabled] { background: #cbd5e1; cursor: not-allowed; color: #475569; }

/* Execution status card */
.exec-status-card {
  background: white;
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}
.exec-status-card.status-queued    { border-left-color: #6b7280; }
.exec-status-card.status-running   { border-left-color: var(--accent); }
.exec-status-card.status-succeeded { border-left-color: #047857; }
.exec-status-card.status-failed    { border-left-color: #b91c1c; }
.exec-status-card h2 { margin-top: 0; font-size: 1.2rem; }
.exec-status-card table { margin-top: 0.5rem; max-width: 700px; }
.exec-status-card th { width: 200px; }
.exec-status-card td code { font-size: 0.9rem; }

pre.error-trace {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  color: #7f1d1d;
}

/* Lab page */
.lab-form fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
}
.lab-form legend { font-weight: 500; padding: 0 0.25rem; }
.lab-form .model-pick {
  display: block;
  font-weight: 400;
  margin: 0.35rem 0;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
}
.lab-form .model-pick:hover { background: white; }
.lab-form .model-pick input[type="checkbox"] { margin-right: 0.5rem; }

.lab-summary {
  margin: 1rem 0 1.5rem;
}
.lab-summary td.num,
.lab-summary th:nth-child(n+4) { text-align: right; font-variant-numeric: tabular-nums; }

.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.lab-card {
  background: white;
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 6px;
  padding: 0.85rem 1rem;
}
.lab-card.status-complete    { border-left-color: #047857; }
.lab-card.status-needs_info  { border-left-color: #d97706; }
.lab-card.status-unparseable { border-left-color: #b91c1c; }
.lab-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.lab-card header h3 { margin: 0; font-size: 1rem; }
.lab-card dl.kv {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0.15rem 0.75rem;
  margin: 0.25rem 0 0.75rem;
  font-size: 0.85rem;
}
.lab-card dl.kv dt { color: var(--muted); }
.lab-card pre.spec-json {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  max-height: 40vh;
  overflow: auto;
}
.lab-card details { font-size: 0.85rem; margin-top: 0.5rem; }
.lab-card details summary { cursor: pointer; color: var(--accent); }

/* --- Phase F: resolution badges + cascade chain + banners --- */

.alert-info { background: #dbeafe; color: #1e40af; }

.match-badge {
  background: #d1fae5;
  color: #065f46;
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
}
.ambig-badge {
  background: #fef3c7;
  color: #78350f;
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Field-state borders for resolved / ambiguous */
.detail-form .form-field.field-resolved input,
.detail-form .form-field.field-resolved textarea,
.detail-form .form-field.field-resolved select {
  border-color: #047857;
  background: #f0fdf4;
}
.detail-form .form-field.field-ambiguous input,
.detail-form .form-field.field-ambiguous textarea,
.detail-form .form-field.field-ambiguous select {
  border-color: #d97706;
  background: #fffbeb;
}

/* Candidate-pick row */
.candidate-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
  align-items: center;
}
.candidate-list .muted {
  margin-right: 0.5rem;
  font-size: 0.8rem;
}
.candidate-pick {
  display: inline-block;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
}
.btn-candidate {
  background: white;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  width: auto;
}
.btn-candidate:hover { background: var(--accent); color: white; }

/* Cascade chain */
.cascade-chain {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}
.cascade-chain h3 { margin-top: 0; font-size: 1rem; }
.cascade-chain h4 {
  font-size: 0.92rem;
  margin: 0.85rem 0 0.4rem;
  color: #1e40af;
}
.cascade-steps {
  margin: 0.5rem 0 1rem 1.25rem;
  padding: 0;
}
.cascade-steps li {
  margin: 0.25rem 0;
  font-size: 0.92rem;
}

.prereq-form {
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}
.prereq-form .form-field { margin-bottom: 0.5rem; }

form {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  display: grid;
  gap: 0.75rem;
}
label {
  display: block;
  font-size: 0.92rem;
  color: var(--fg);
  font-weight: 500;
}
input[type="text"], textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  background: var(--bg);
  margin-top: 0.25rem;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  width: max-content;
}
button:hover { background: #1d4ed8; }


/* ----------------------------------------------------------------- */
/* Polish I, Phase C: tag-bubble picker                              */
/* ----------------------------------------------------------------- */

.tag-picker {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.tag-bubbles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 1px;
}
.tag-bubbles:empty { display: none; }

.tag-bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem 0.25rem 0.6rem;
  background: var(--ok-bg);
  color: var(--ok-fg);
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.3;
  /* Allow long labels (e.g., jobsite name + full address) to wrap
     inside the bubble rather than overflow the container */
  max-width: 100%;
}
.tag-bubble .tag-text {
  font-weight: 500;
  white-space: normal;
  word-break: break-word;
}
.tag-bubble .tag-qty {
  background: rgba(255, 255, 255, 0.6);
  color: inherit;
  border: none;
  padding: 0.05rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  width: auto;
  cursor: pointer;
}
.tag-bubble .tag-qty:hover { background: white; }
.tag-bubble .tag-x {
  background: transparent;
  color: inherit;
  border: none;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  width: 1.1rem;
  opacity: 0.7;
}
.tag-bubble .tag-x:hover {
  opacity: 1;
  background: transparent;
}

.tag-search-wrap {
  position: relative;
  width: 100%;
}
.tag-search {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.92rem;
  background: transparent;
}
.tag-search:focus {
  outline: none;
  border-color: var(--accent);
  background: #f9fafb;
}

.tag-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 0.25rem 0;
  list-style: none;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
}
.tag-dropdown.hidden { display: none; }
.tag-dropdown li {
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.tag-dropdown li.active,
.tag-dropdown li:hover {
  background: #f3f4f6;
}
.tag-dropdown li.tag-empty {
  color: var(--muted);
  font-style: italic;
  cursor: default;
}

/* Once a tag-picker has a bubble, the resolution badges + candidate
   buttons are no longer informative — the bubble itself shows the
   selection. Hide them. JS toggles `.picker-has-value` on the
   parent <label> when the bubble count crosses zero. */
.form-field.picker-has-value .ambig-badge,
.form-field.picker-has-value .missing-marker,
.form-field.picker-has-value .candidate-list {
  display: none;
}


/* ----------------------------------------------------------------- */
/* Polish I, Phase D: cascade wizard layout                          */
/* ----------------------------------------------------------------- */

.wizard-step {
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  overflow: hidden;
}

.wizard-step > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  background: #f9fafb;
  border-bottom: 1px solid transparent;
}
.wizard-step > summary::-webkit-details-marker { display: none; }
.wizard-step > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.15s;
}
.wizard-step[open] > summary::after { transform: rotate(180deg); }
.wizard-step[open] > summary { border-bottom-color: var(--border); }
.wizard-step .step-num {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.85rem;
  margin-right: 0.4rem;
}

.wizard-step-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}
.wizard-step-current > summary { background: #eff6ff; }
.wizard-step-done > summary {
  background: var(--ok-bg);
  color: var(--ok-fg);
}
.wizard-step-done strong { color: inherit; }
.wizard-step-locked > summary {
  background: #f3f4f6;
  color: var(--muted);
}

.wizard-step > details:not(.step-result-payload),
.wizard-step > .wizard-step-form,
.wizard-step > .execute-form,
.wizard-step > .alert,
.wizard-step > p {
  padding: 0;
  margin: 0;
}

.wizard-step .wizard-step-form,
.wizard-step .execute-form {
  padding: 0.9rem;
}
.wizard-step .alert,
.wizard-step > p {
  padding: 0.75rem 0.9rem;
}

/* Locked steps: visible but uneditable. fieldset[disabled] handles
   most of this natively; we just dim it visually. */
.wizard-step .wizard-step-form fieldset[disabled] {
  border: none;
  padding: 0;
  margin: 0;
  opacity: 0.55;
  pointer-events: none;
}
.wizard-step .wizard-step-form fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.wizard-step .step-result-payload {
  margin-top: 0.5rem;
}
.wizard-step .step-result-payload pre {
  background: rgba(0, 0, 0, 0.04);
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  overflow-x: auto;
}

.cascade-history {
  list-style: decimal inside;
  padding: 0;
  margin: 0.75rem 0;
}
.cascade-history li {
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
}
.cascade-history li:last-child { border-bottom: none; }


/* ----------------------------------------------------------------- */
/* Polish K: inline sub-modal layout for create_reservation          */
/* ----------------------------------------------------------------- */

.resv-section {
  margin: 1.25rem 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.resv-section:first-of-type { border-top: none; padding-top: 0; }

.resv-section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.resv-section-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.resv-section.is-disabled {
  opacity: 0.45;
  pointer-events: none;
  /* Visual cue that the section is gated on an upstream selection */
  background: repeating-linear-gradient(
    -45deg,
    transparent 0,
    transparent 12px,
    rgba(0, 0, 0, 0.025) 12px,
    rgba(0, 0, 0, 0.025) 24px
  );
}

.btn-create-new {
  margin-left: auto;
  background: white;
  color: var(--accent);
  border: 1px dashed var(--accent);
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  width: auto;
}
.btn-create-new:hover {
  background: #eff6ff;
}

.inline-create-form {
  display: inline;
  margin-left: auto;
}
.inline-action-form { display: inline; }

/* tag-picker dropdown source-mode (call-off items picker) */
.tag-dropdown-select {
  margin-left: 0.4rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
}
.tag-dropdown-select:disabled {
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}
.tag-dropdown-select option.is-called-off {
  color: #9ca3af;
  font-style: italic;
  background: #f9fafb;
}

.auto-cascade-toggle {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  padding: 0.6rem 0.85rem;
  background: #f0f9ff;            /* faint blue tint */
  border: 1px solid #bae6fd;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.auto-cascade-toggle input[type="checkbox"] {
  flex: 0 0 auto;
}
.auto-cascade-toggle .muted {
  font-size: 0.85rem;
}

.sub-modal {
  margin-top: 0.6rem;
  padding: 0.85rem 1rem 1rem;
  background: #fefce8;            /* warm yellow tint to read as a sub-form */
  border: 2px solid #facc15;
  border-radius: 6px;
}
.sub-modal-customer { background: #eff6ff; border-color: var(--accent); }
.sub-modal-jobsite  { background: #f0fdf4; border-color: #16a34a; }

.sub-modal-header {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
.sub-modal-form { margin-bottom: 0.75rem; }

.sub-modal-footer {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

/* Inline execute: while a sub-modal is running its workflow, lock
   user input and show a spinner overlay so it's clear the system
   is busy without the user navigating away. */
.sub-modal {
  position: relative;
}
.sub-modal.is-executing > * {
  pointer-events: none;
  opacity: 0.55;
}
.sub-modal.is-executing::after {
  content: "Running in Rentalman…";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: rgba(255, 255, 255, 0.55);
  color: #1f2937;
  font-weight: 600;
  font-size: 0.95rem;
  pointer-events: auto;
  border-radius: 6px;
}
.sub-modal.is-executing::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(31, 41, 55, 0.18);
  border-top-color: #1f2937;
  border-radius: 50%;
  animation: sub-modal-spin 0.7s linear infinite;
  pointer-events: none;
  z-index: 1;
  /* sit just above the dimmed text label */
  transform: translateY(-22px);
}
@keyframes sub-modal-spin {
  to { transform: translateY(-22px) rotate(360deg); }
}

/* Failure banner shown inline in the sub-modal after a failed
   inline execute, so the reviewer doesn't have to chase the
   /executions/ page. */
.sub-modal-error {
  margin-top: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  color: #991b1b;
  font-size: 0.9rem;
}

.cascade-trail {
  margin-top: 1.5rem;
  padding: 0.5rem 0.75rem;
  background: #f9fafb;
  border-radius: 4px;
  font-size: 0.85rem;
}
.cascade-trail summary { cursor: pointer; color: var(--muted); }

/* ---- Environment banner ---- */
.env-banner {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 1rem;
  letter-spacing: 0.05em;
}
.env-banner--sandbox {
  background: #f3f4f6;
  color: #6b7280;
}
.env-banner--production {
  background: #991b1b;
  color: white;
  font-size: 0.9rem;
  padding: 0.35rem 1rem;
}

/* ---- Header right cluster (user + logout) ---- */
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.header-user {
  font-size: 0.85rem;
  color: var(--muted);
}
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
}
.btn-logout:hover { background: #f3f4f6; }

/* ---- Login page ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.login-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.4rem;
  text-align: center;
}
.login-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  margin-top: 1rem;
}
.login-card input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
}
.login-card .btn-primary {
  width: 100%;
  margin-top: 1.5rem;
}
.alert--error {
  background: var(--error-bg);
  color: var(--error-fg);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ---- Admin user table ---- */
.user-form label { display: block; font-size: 0.85rem; font-weight: 500; margin: 0.75rem 0 0.2rem; }
.user-form input, .user-form select { width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; }
.users-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.users-table th, .users-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
.users-table th { font-weight: 600; background: #f9fafb; }
.row--inactive { opacity: 0.5; }
.btn-sm { font-size: 0.8rem; padding: 0.25rem 0.6rem; background: white; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.btn-sm:hover { background: #f3f4f6; }
.btn-primary { background: var(--accent); color: white; border: none; border-radius: 4px; padding: 0.6rem 1.2rem; font-size: 0.95rem; font-weight: 500; cursor: pointer; }
.btn-primary:hover { background: #1d4ed8; }

/* ===== Phase 2 — Kanban + agents ===== */
.kanban-page { max-width: 100%; padding: 1rem 1.5rem; }
.kanban-page__header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.kanban-page__header h1 { margin: 0; }
.kanban-filters { display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap; }
.kanban-filters label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: #555; }
.kanban-filters input { padding: 0.4rem 0.55rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; }

.kanban-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; align-items: start; }
.kanban-column { background: #f4f5f7; border-radius: 6px; padding: 0.75rem; min-height: 200px; }
.kanban-column__title { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.75rem 0; display: flex; justify-content: space-between; align-items: center; color: #333; }
.kanban-column__count { background: #e5e7eb; border-radius: 99px; padding: 0.1rem 0.6rem; font-size: 0.75rem; color: #555; font-weight: 500; }
.kanban-column__cards { display: flex; flex-direction: column; gap: 0.6rem; }
.kanban-column__empty { color: #999; font-size: 0.85rem; text-align: center; padding: 1rem 0; }

.kanban-card { background: white; border: 1px solid var(--border); border-radius: 5px; padding: 0.75rem; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.kanban-card__header { display: flex; justify-content: space-between; align-items: start; gap: 0.5rem; margin-bottom: 0.4rem; }
.kanban-card__title { font-weight: 500; font-size: 0.9rem; color: var(--accent); text-decoration: none; }
.kanban-card__title:hover { text-decoration: underline; }
.kanban-card__flag { cursor: help; font-size: 1rem; }
.kanban-card__customer { font-size: 0.85rem; font-weight: 500; color: #333; margin-bottom: 0.3rem; }
.kanban-card__intake { font-size: 0.8rem; color: #666; margin: 0 0 0.6rem 0; line-height: 1.35; max-height: 4em; overflow: hidden; }
.kanban-card__badges { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.kanban-card--rejected { opacity: 0.65; }

.user-badge { display: inline-flex; align-items: center; gap: 0.25rem; background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 99px; padding: 0.1rem 0.55rem; font-size: 0.72rem; color: #444; max-width: 12em; }
.user-badge__icon { font-size: 0.85rem; }
.user-badge__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-badge--agent { background: #fef3c7; border-color: #fcd34d; }

/* Agents admin */
.admin-page { max-width: 800px; padding: 1rem 1.5rem; }
.admin-page__header h1 { margin: 0; }
.admin-page__header .muted { font-size: 0.9rem; color: #666; max-width: 60ch; }
.agent-form { background: white; border: 1px solid var(--border); border-radius: 5px; padding: 0.85rem; margin-bottom: 0.75rem; }
.agent-form__row { display: flex; gap: 1rem; align-items: end; }
.agent-form__avatar-input { width: 3.5rem; text-align: center; font-size: 1.4rem; padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; }
.agent-form__main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
.agent-form__main label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: #555; }
.agent-form__main input { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; }
.agent-form__identity { grid-column: span 2; font-size: 0.78rem; color: #888; }
.agent-form__identity code { background: #f3f4f6; padding: 0.1rem 0.35rem; border-radius: 3px; }

@media (max-width: 1100px) {
  .kanban-board { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .kanban-board { grid-template-columns: 1fr; }
}
