/* Settings Page Layout - CoPlanner Integration */
.settings-layout {
  display: flex;
  gap: 2rem;
  min-height: calc(100vh - 200px);
}

.settings-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bs-card-bg, #fff);
  border-radius: var(--bs-border-radius, 0.5rem);
  padding: 1.5rem;
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
  height: fit-content;
  position: sticky;
  top: 1rem;
}

.settings-content {
  flex: 1;
  min-width: 0;
}

/* Settings Navigation */
.settings-nav-category {
  margin-bottom: 2rem;
}

.settings-nav-category:last-child {
  margin-bottom: 0;
}

.settings-nav-category-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bs-secondary, #6c757d);
  margin-bottom: 0.75rem;
  padding-left: 0.75rem;
}

.settings-nav-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.settings-nav-link {
  display: flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  color: var(--bs-body-color, #212529);
  text-decoration: none;
  border-radius: var(--bs-border-radius-sm, 0.25rem);
  font-size: 0.9375rem;
  transition: all 0.2s ease;
}

.settings-nav-link:hover {
  background-color: var(--bs-light, #f8f9fa);
  color: var(--bs-primary, #0d6efd);
}

.settings-nav-link.active {
  background-color: var(--bs-primary, #0d6efd);
  color: #fff;
  font-weight: 500;
}

.settings-nav-link i {
  margin-right: 0.75rem;
  font-size: 1.125rem;
  width: 1.25rem;
  text-align: center;
}

/* Settings Cards */
.settings-card {
  background: var(--bs-card-bg, #fff);
  border-radius: var(--bs-border-radius, 0.5rem);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.settings-card:last-child {
  margin-bottom: 0;
}

.settings-section-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.settings-section-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--bs-heading-color, #212529);
}

.settings-section-header p {
  margin: 0;
  color: var(--bs-secondary, #6c757d);
  font-size: 0.9375rem;
}

/* Form Styling */
.settings-card .form-group {
  margin-bottom: 1.5rem;
}

.settings-card .form-group:last-child {
  margin-bottom: 0;
}

.settings-card label {
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: block;
}

.settings-card .help-text {
  font-size: 0.875rem;
  color: var(--bs-secondary, #6c757d);
  margin-top: 0.25rem;
  display: block;
}

/* Action Buttons */
.settings-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.settings-actions .btn {
  min-width: 120px;
}

/* Responsive Design */
@media (max-width: 992px) {
  .settings-layout {
    flex-direction: column;
  }
  
  .settings-sidebar {
    width: 100%;
    position: static;
    margin-bottom: 2rem;
  }
}

/* Background Job Progress */
.progress-container {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bs-light, #f8f9fa);
  border-radius: var(--bs-border-radius, 0.5rem);
}

.progress {
  height: 1.5rem;
  margin-bottom: 0.5rem;
}

.progress-message {
  font-size: 0.875rem;
  color: var(--bs-secondary, #6c757d);
  text-align: center;
}

/* Dark theme overrides for settings sidebar and layout */
body.dark-theme .settings-sidebar {
  background: #1f2225 !important;
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3) !important;
}

body.dark-theme .settings-sidebar .nav-link {
  color: #e0e0e0 !important;
}

body.dark-theme .settings-sidebar .nav-link:hover {
  background-color: #343a40 !important;
  color: #fff !important;
}

body.dark-theme .settings-sidebar .nav-link.active {
  background-color: #4a90e2 !important;
  color: #fff !important;
}

body.dark-theme .progress-container {
  background: #2d3436 !important;
}

/* CRM Framework Toggles (SPIN / MEDDIC settings pages) ----------------------
 * Dedicated, larger, green-when-active enable switches for "Enable SPIN
 * Selling framework" / "Enable MEDDIC qualification framework". Scoped to
 * .cp-framework-toggle only, so no other .form-switch in the app is
 * affected by the sizing or color override.
 */
.cp-framework-toggle {
  transform: scale(1.6);
  transform-origin: center;
  margin: 0.5rem 0.6rem;
  cursor: pointer;
}

.cp-framework-toggle:checked {
  background-color: #198754; /* Bootstrap "success" green = framework active */
  border-color: #198754;
}

/* Explicit grey for the OFF state, so "enabled = green" / "disabled = grey"
 * reads clearly at a glance (module toggles on the Organization page, and
 * any other .cp-framework-toggle switch that isn't checked). */
.cp-framework-toggle:not(:checked) {
  background-color: #adb5bd;
  border-color: #adb5bd;
}

.cp-framework-toggle:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Greyed-out state for the tabbed question editor (SPIN) / stage-gate
 * threshold editor (MEDDIC) while their framework toggle is OFF.
 *
 * Deliberately uses ONLY opacity — never `pointer-events: none` — because
 * the admin must still be able to add/edit/remove questions or change
 * thresholds while the framework itself is disabled. The grey-out is a
 * purely visual "currently inactive" status signal, not a field lock.
 */
.cp-framework-disabled {
  opacity: 0.45;
  transition: opacity 0.2s ease-in-out;
}

/* TIA run report modal: wider than Bootstrap's modal-xl (1140px) on large screens.
 * Doubled class beats .modal-xl's own --bs-modal-width at the same breakpoint. */
@media (min-width: 1200px) {
  .modal-dialog.cp-tia-report-dialog { --bs-modal-width: min(1280px, 95vw); }
}
@media (min-width: 1400px) {
  .modal-dialog.cp-tia-report-dialog { --bs-modal-width: min(1400px, 95vw); }
}

/* Auto-matched TIA codes list (Timesheet Entry Logs banner, run report Routing
 * tab, per-run history). A container-query grid, not a viewport one: the list
 * sits in a narrow column on the logs tab but in a wide modal in the report, at
 * the same viewport width. Stacks below 56rem, five aligned columns above: the
 * fixed columns, gaps and row padding take 47.5rem, so 56rem leaves the Purchase
 * Order column at least 8.5rem. */
.cp-tia-matches {
  container-type: inline-size;
}

.cp-tia-matches__head {
  display: none;
}

.cp-tia-matches__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  min-height: 3rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--bs-info-border-subtle);
}

.cp-tia-matches__code { grid-column: 1 / -1; min-width: 0; }

/* Bootstrap's .badge is nowrap; long TIA codes must wrap inside their own cell. */
.cp-tia-matches__badge {
  max-width: 100%;
  font-size: 0.8rem;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
}
.cp-tia-matches__po { grid-column: 1 / -1; min-width: 0; }
.cp-tia-matches__num { grid-column: 1 / -1; font-variant-numeric: tabular-nums; color: var(--bs-secondary-color); }
.cp-tia-matches__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-start; }
.cp-tia-matches__stat-label { display: inline; }

@container (min-width: 56rem) {
  .cp-tia-matches__head,
  .cp-tia-matches__row {
    display: grid;
    grid-template-columns: minmax(14rem, 2.2fr) minmax(0, 2fr) 4.5rem 5.5rem 19rem;
    gap: 0.75rem;
  }
  .cp-tia-matches__head {
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--bs-secondary-color);
  }
  .cp-tia-matches__code,
  .cp-tia-matches__po,
  .cp-tia-matches__num,
  .cp-tia-matches__actions { grid-column: auto; grid-row: auto; }
  .cp-tia-matches__num { text-align: right; }
  .cp-tia-matches__actions { justify-content: flex-end; }
  .cp-tia-matches__stat-label { display: none; }
}

/* A scaled .cp-framework-toggle inside a flex row: no float / negative margin,
 * room on both sides for the 1.6x scale, label and help text start after it. */
.cp-switch-row .cp-framework-toggle {
  float: none;
  flex-shrink: 0;
  margin: 0.25rem 1.1rem 0.25rem 0.75rem;
}

/* Coloured left edge of the run report's Overview rows ("Needs attention" and the
 * auto-matched info row): Bootstrap has no border-start-<tone> utility. */
.list-group-item.border-start-danger { border-left-color: var(--bs-danger) !important; }
.list-group-item.border-start-warning { border-left-color: var(--bs-warning) !important; }
.list-group-item.border-start-info { border-left-color: var(--bs-info) !important; }
body.dark-theme .list-group-item.border-start-danger { border-left-color: var(--bs-danger) !important; }
body.dark-theme .list-group-item.border-start-warning { border-left-color: var(--bs-warning) !important; }
body.dark-theme .list-group-item.border-start-info { border-left-color: var(--bs-info) !important; }
