/* ===================================================================
   Protocol Builder Wizard — Sidebar, Step Nav, Mode Toggle
   =================================================================== */

/* --- Mode Toggle (Wizard / Advanced) --- */

.pb-mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 6px;
  background: var(--light-bg, #f5f5f5);
  border-radius: 8px;
  width: fit-content;
}

.pb-mode-toggle button {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary, #666);
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.pb-mode-toggle button.active {
  background: var(--primary, #1a7a6d);
  color: white;
}

.pb-mode-toggle button:hover:not(.active) {
  background: var(--border, #e0e0e0);
}

/* --- Wizard Step Containers --- */

[data-pb-step] {
  display: none;
}

/* In advanced mode, all visible steps show */
body.pb-mode-advanced [data-pb-step] {
  display: block;
}

/* In wizard mode, only active step shows (controlled by JS) */

/* --- Step Navigation Bar (Next/Back) --- */

.pb-step-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-top: 24px;
  border-top: 1px solid var(--border, #e0e0e0);
}

.pb-step-counter {
  font-size: 13px;
  color: var(--text-secondary, #999);
  font-weight: 500;
}

.pb-nav-back,
.pb-nav-next {
  min-width: 100px;
}

/* Hide step nav in advanced mode */
body.pb-mode-advanced .pb-step-nav {
  display: none;
}

/* --- Inline "Guideline" chip on guideline-only section headers --- */

.guideline-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  background: #edf8f6;
  color: #1a7a6d;
  border: 1px solid #c2e4dc;
  vertical-align: middle;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .guideline-tag {
    background: rgba(140, 217, 192, 0.12);
    color: #8CD9C0;
    border-color: rgba(140, 217, 192, 0.25);
  }
}
:root[data-theme="dark"] .guideline-tag {
  background: rgba(140, 217, 192, 0.12);
  color: #8CD9C0;
  border-color: rgba(140, 217, 192, 0.25);
}

/* Field-level variant — smaller chip placed inline next to a field label
   to flag a single control (vs the section-level chip on the h2). */
.guideline-tag--field {
  font-size: 10px;
  padding: 1px 6px;
  margin-left: 6px;
  letter-spacing: 0.04em;
}

/* --- Per-tier fort_start summary (read-only mirror, shown atop Fortification step) --- */

.fort-start-summary {
  margin: 0 0 12px 0;
}
.fort-start-table {
  width: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.fort-start-table th,
.fort-start-table td {
  padding: 4px 12px 4px 0;
  text-align: left;
  color: var(--text-secondary);
}
.fort-start-table th {
  font-weight: 600;
  color: var(--text-primary);
}
:root[data-theme="dark"] .fort-start-table th { color: var(--text-primary); }
:root[data-theme="dark"] .fort-start-table td { color: var(--text-secondary); }

/* --- Post-import scope-choice banner (rendered inside #validationMessage) --- */

.import-choice-banner {
  background: #edf8f6;
  border: 1px solid #1a7a6d;
  border-radius: 8px;
  padding: 16px 20px;
  margin: 12px 0;
  color: var(--text-primary);
}
.import-choice-banner p { margin: 0 0 10px 0; }
.import-choice-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
:root[data-theme="dark"] .import-choice-banner {
  background: rgba(140, 217, 192, 0.08);
  border-color: #8CD9C0;
  color: var(--text-primary);
}

/* --- Sidebar scope tag (Feeding Tool / Full Guideline) --- */

.pb-sidebar-scope-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 12px 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: #edf8f6;
  color: #1a7a6d;
  border: 1px solid #c2e4dc;
  width: fit-content;
}
.pb-sidebar-scope-tag svg { flex-shrink: 0; }
.pb-sidebar-scope-tag-label { white-space: nowrap; }

/* Differentiate Full Guideline scope visually (slightly darker tint) */
.pb-sidebar-scope-tag--guideline {
  background: #d6efe8;
  border-color: #a8d5cc;
}

/* Dark theme — preserve readable contrast against the dark sidebar bg */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pb-sidebar-scope-tag {
    background: rgba(140, 217, 192, 0.12);
    color: #8CD9C0;
    border-color: rgba(140, 217, 192, 0.25);
  }
  :root:not([data-theme="light"]) .pb-sidebar-scope-tag--guideline {
    background: rgba(140, 217, 192, 0.2);
    border-color: rgba(140, 217, 192, 0.4);
  }
}
:root[data-theme="dark"] .pb-sidebar-scope-tag {
  background: rgba(140, 217, 192, 0.12);
  color: #8CD9C0;
  border-color: rgba(140, 217, 192, 0.25);
}
:root[data-theme="dark"] .pb-sidebar-scope-tag--guideline {
  background: rgba(140, 217, 192, 0.2);
  border-color: rgba(140, 217, 192, 0.4);
}

/* --- Sidebar Step List --- */

.pb-sidebar-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  border-top: 1px solid #e8ebe9;
  margin-top: 4px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
}

/* Base = light theme. Mirrors .sidebar-nav-item palette in sidebar-nav.css. */
.pb-sidebar-step {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #555;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.pb-sidebar-step:hover {
  background: #f0faf8;
  color: #1a7a6d;
}

.pb-sidebar-step.active {
  background: #edf8f6;
  color: #1a7a6d;
}

.pb-sidebar-step.visited:not(.active) {
  color: #1a7a6d;
}

/* Step number circle */
.pb-sidebar-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(26, 122, 109, 0.12);
  color: #1a7a6d;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.pb-sidebar-step.active .pb-sidebar-step-num {
  background: var(--primary, #1a7a6d);
  color: white;
}

.pb-sidebar-step.visited:not(.active) .pb-sidebar-step-num {
  background: rgba(26, 122, 109, 0.2);
  color: #1a7a6d;
}

/* Dark theme — preserve previous dark-bg appearance.
   Mirrors the override pattern in sidebar-nav.css (lines 184-220, 222-246). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pb-sidebar-steps { border-top-color: rgba(255, 255, 255, 0.1); }
  :root:not([data-theme="light"]) .pb-sidebar-step { color: rgba(255, 255, 255, 0.6); }
  :root:not([data-theme="light"]) .pb-sidebar-step:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
  }
  :root:not([data-theme="light"]) .pb-sidebar-step.active {
    background: rgba(26, 122, 109, 0.3);
    color: white;
  }
  :root:not([data-theme="light"]) .pb-sidebar-step.visited:not(.active) {
    color: rgba(255, 255, 255, 0.8);
  }
  :root:not([data-theme="light"]) .pb-sidebar-step:not(.active) .pb-sidebar-step-num {
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
  }
  :root:not([data-theme="light"]) .pb-sidebar-step.visited:not(.active) .pb-sidebar-step-num {
    background: rgba(26, 122, 109, 0.2);
    color: rgba(255, 255, 255, 0.8);
  }
}

:root[data-theme="dark"] .pb-sidebar-steps { border-top-color: rgba(255, 255, 255, 0.1); }
:root[data-theme="dark"] .pb-sidebar-step { color: rgba(255, 255, 255, 0.6); }
:root[data-theme="dark"] .pb-sidebar-step:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
}
:root[data-theme="dark"] .pb-sidebar-step.active {
  background: rgba(26, 122, 109, 0.3);
  color: white;
}
:root[data-theme="dark"] .pb-sidebar-step.visited:not(.active) {
  color: rgba(255, 255, 255, 0.8);
}
:root[data-theme="dark"] .pb-sidebar-step:not(.active) .pb-sidebar-step-num {
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
}
:root[data-theme="dark"] .pb-sidebar-step.visited:not(.active) .pb-sidebar-step-num {
  background: rgba(26, 122, 109, 0.2);
  color: rgba(255, 255, 255, 0.8);
}

/* Step label */
.pb-sidebar-step-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Completion/Warning badges */
.pb-sidebar-step-badge {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  flex-shrink: 0;
}

.pb-sidebar-step-badge:empty {
  display: none;
}

.badge-complete {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

.badge-warning {
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
  font-size: 8px;
}

.badge-error {
  background: rgba(244, 67, 54, 0.2);
  color: #f44336;
}

/* Step labels always visible — no collapse on mouse-out */

/* --- Step description subtitle (shown in wizard mode) --- */

.pb-step-description {
  font-size: 13px;
  color: var(--text-secondary, #999);
  margin: -8px 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border, #e0e0e0);
}

body.pb-mode-advanced .pb-step-description {
  display: none;
}

/* --- Responsive: sidebar collapses on small screens --- */

@media (max-width: 768px) {
  .pb-sidebar-steps {
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: visible;
    padding: 4px;
    gap: 4px;
  }

  .pb-sidebar-step {
    flex: 0 0 auto;
    padding: 4px 8px;
    font-size: 11px;
  }

  .pb-sidebar-step-label {
    display: none;
  }

  .pb-sidebar-step-num {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
}
