/*
 * ChatXP Authority Theme
 *
 * Positioning: Professional Research & Academic Platform
 * Based on GitHub's Primer design system with authority/trust emphasis.
 * Primary: #4a7dbd (Muted Blue)
 *
 * Loaded after bootstrap.min.css in base.html.
 *
 * === Color Semantics (do NOT use semantic colors decoratively) ===
 *
 *   Green  (success)   → Active states, successful completion, healthy
 *   Red    (danger)    → Errors, destructive actions, failures
 *   Amber  (warning)   → Warnings, caution-needed actions (e.g. anonymize)
 *   Blue   (primary)   → Brand, interactive elements, elevated roles
 *   Gray   (secondary) → Neutral, inactive, disabled, standard roles
 *   Dark   (dark)      → Highest authority (Super Admin), navbar, footer
 *
 * === Role Badge Guide ===
 *
 *   Super Admin       → bg-dark      (highest authority)
 *   PI / Admin        → bg-secondary (neutral, standard)
 *   Designer / Coord  → bg-primary   (brand, elevated)
 *   Researcher / Asst → bg-secondary (neutral, standard)
 *
 * === Status Badge Guide ===
 *
 *   active    → bg-success   (green = running/healthy)
 *   completed → bg-success   (green = successfully finished)
 *   draft     → bg-secondary (gray = not yet started)
 *   paused    → bg-secondary (gray = temporarily inactive)
 *   archived  → bg-secondary (gray = inactive)
 *   abandoned → bg-danger    (red = failed/dropped)
 */

/* ========== Core Palette ========== */

:root {
  --bs-primary: #4a7dbd;
  --bs-primary-rgb: 74, 125, 189;
  --bs-secondary: #6e7781;
  --bs-secondary-rgb: 110, 119, 129;
  --bs-success: #2da44e;
  --bs-success-rgb: 45, 164, 78;
  --bs-warning: #bf8700;
  --bs-warning-rgb: 191, 135, 0;
  --bs-danger: #cf222e;
  --bs-danger-rgb: 207, 34, 46;
  --bs-info: #528baf;
  --bs-info-rgb: 82, 139, 175;

  --bs-body-color: #1f2328;
  --bs-body-color-rgb: 31, 35, 40;
  --bs-border-color: #d1d9e0;
  --bs-link-color: #4a7dbd;
  --bs-link-hover-color: #3b6499;
}

/* ========== Typography Scale (Perfect Fifth — 1.5 ratio) ========== */

h1, .h1 { font-size: 2.488rem; font-weight: 600; letter-spacing: -0.02em; }
h2, .h2 { font-size: 2.074rem; font-weight: 600; letter-spacing: -0.01em; }
h3, .h3 { font-size: 1.728rem; font-weight: 600; }
h4, .h4 { font-size: 1.44rem;  font-weight: 600; }
h5, .h5 { font-size: 1.2rem;   font-weight: 600; }
h6, .h6 { font-size: 1rem;     font-weight: 600; }

/* ========== Body Text ========== */

body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1f2328;
  line-height: 1.6;
}

code, pre, kbd, .font-monospace {
  font-family: 'IBM Plex Mono', SFMono-Regular, Menlo, monospace;
}

.text-muted {
  color: #656d76 !important;
}

/* ========== Links ========== */

a {
  color: #4a7dbd;
}

a:hover {
  color: #3b6499;
}

/* ========== Navbar & Footer ========== */

.bg-dark {
  background-color: #1f2328 !important;
}

.navbar-dark .navbar-brand,
.navbar-dark .nav-link {
  color: rgba(255, 255, 255, 0.85);
}

.navbar-dark .nav-link:hover,
.navbar-dark .nav-link.active {
  color: #fff;
}

/* ========== Buttons ========== */

.btn-primary {
  --bs-btn-bg: #4a7dbd;
  --bs-btn-border-color: #4a7dbd;
  --bs-btn-hover-bg: #3b6499;
  --bs-btn-hover-border-color: #3b6499;
  --bs-btn-active-bg: #2f5580;
  --bs-btn-active-border-color: #2f5580;
}

.btn-success {
  --bs-btn-bg: #2da44e;
  --bs-btn-border-color: #2da44e;
  --bs-btn-hover-bg: #248c3e;
  --bs-btn-hover-border-color: #248c3e;
  --bs-btn-active-bg: #1c7430;
  --bs-btn-active-border-color: #1c7430;
}

.btn-warning {
  --bs-btn-bg: #bf8700;
  --bs-btn-border-color: #bf8700;
  --bs-btn-color: #fff;
  --bs-btn-hover-bg: #a67500;
  --bs-btn-hover-border-color: #a67500;
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #8c6300;
  --bs-btn-active-border-color: #8c6300;
  --bs-btn-active-color: #fff;
}

.btn-danger {
  --bs-btn-bg: #cf222e;
  --bs-btn-border-color: #cf222e;
  --bs-btn-hover-bg: #b01c25;
  --bs-btn-hover-border-color: #b01c25;
  --bs-btn-active-bg: #92151d;
  --bs-btn-active-border-color: #92151d;
}

.btn-info {
  --bs-btn-bg: #528baf;
  --bs-btn-border-color: #528baf;
  --bs-btn-color: #fff;
  --bs-btn-hover-bg: #457698;
  --bs-btn-hover-border-color: #457698;
  --bs-btn-hover-color: #fff;
}

/* Outline variants */
.btn-outline-primary {
  --bs-btn-color: #4a7dbd;
  --bs-btn-border-color: #4a7dbd;
  --bs-btn-hover-bg: #4a7dbd;
  --bs-btn-hover-border-color: #4a7dbd;
  --bs-btn-active-bg: #3b6499;
  --bs-btn-active-border-color: #3b6499;
}

.btn-outline-success {
  --bs-btn-color: #2da44e;
  --bs-btn-border-color: #2da44e;
  --bs-btn-hover-bg: #2da44e;
  --bs-btn-hover-border-color: #2da44e;
}

.btn-outline-danger {
  --bs-btn-color: #cf222e;
  --bs-btn-border-color: #cf222e;
  --bs-btn-hover-bg: #cf222e;
  --bs-btn-hover-border-color: #cf222e;
}

.btn-outline-secondary {
  --bs-btn-color: #6e7781;
  --bs-btn-border-color: #d1d9e0;
  --bs-btn-hover-bg: #f6f8fa;
  --bs-btn-hover-border-color: #d1d9e0;
  --bs-btn-hover-color: #1f2328;
  --bs-btn-active-bg: #eaeef2;
  --bs-btn-active-border-color: #d1d9e0;
  --bs-btn-active-color: #1f2328;
}

/* ========== Badges ========== */

.badge.bg-primary   { background-color: #4a7dbd !important; }
.badge.bg-success   { background-color: #2da44e !important; }
.badge.bg-warning   { background-color: #bf8700 !important; color: #fff !important; }
.badge.bg-danger    { background-color: #cf222e !important; }
.badge.bg-info      { background-color: #528baf !important; color: #fff !important; }
.badge.bg-secondary { background-color: #6e7781 !important; }
.badge.bg-dark      { background-color: #32383f !important; }

/* ========== Cards ========== */

.card {
  border-color: #d1d9e0;
}

.card-header {
  background-color: #f6f8fa;
  border-bottom-color: #d1d9e0;
}

.card-footer {
  background-color: #f6f8fa;
  border-top-color: #d1d9e0;
}

/* Danger zone card keeps its red accent */
.card.border-danger {
  border-color: #cf222e !important;
}

.card.border-danger .card-header.bg-danger {
  background-color: #cf222e !important;
}

/* ========== Tables ========== */

.table {
  --bs-table-hover-bg: #f6f8fa;
  --bs-table-border-color: #d1d9e0;
}

.table thead th {
  border-bottom-color: #d1d9e0;
  color: #656d76;
  font-weight: 600;
  font-size: 0.875rem;
}

/* ========== Alerts ========== */

.alert-info {
  --bs-alert-bg: #f0f7ff;
  --bs-alert-color: #1f2328;
  --bs-alert-border-color: #b6d4fe;
}

.alert-warning {
  --bs-alert-bg: #fff8e1;
  --bs-alert-color: #1f2328;
  --bs-alert-border-color: #ffe082;
}

.alert-success {
  --bs-alert-bg: #f0fff4;
  --bs-alert-color: #1f2328;
  --bs-alert-border-color: #a3d9a5;
}

.alert-danger {
  --bs-alert-bg: #fff5f5;
  --bs-alert-color: #1f2328;
  --bs-alert-border-color: #f5c6cb;
}

.alert-secondary {
  --bs-alert-bg: #f6f8fa;
  --bs-alert-color: #1f2328;
  --bs-alert-border-color: #d1d9e0;
}

/* ========== Forms ========== */

.form-control:focus,
.form-select:focus {
  border-color: #4a7dbd;
  box-shadow: 0 0 0 0.2rem rgba(74, 125, 189, 0.25);
}

/* ========== Dropdown ========== */

.dropdown-menu {
  border-color: #d1d9e0;
  box-shadow: 0 4px 12px rgba(31, 35, 40, 0.12);
}

.dropdown-item:hover,
.dropdown-item:focus {
  background-color: #f6f8fa;
}

/* ========== Modals ========== */

.modal-content {
  border-color: #d1d9e0;
}

/* ========== Breadcrumbs ========== */

.breadcrumb-item a {
  color: #4a7dbd;
}

.breadcrumb-item.active {
  color: #656d76;
}

/* ========== Subject-Facing Study Layout ========== */

.study-container {
  max-width: 700px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.study-header {
  text-align: center;
  margin-bottom: 2rem;
}

.study-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 2rem;
}

/* Mobile: reduce study container padding */
@media (max-width: 576px) {
  .study-container { padding: 1rem 0.5rem; }
  .study-card { padding: 1.25rem; border-radius: 0; box-shadow: none; }
  .study-header { margin-bottom: 1rem; }
}

/* ========== Progress Steps ========== */

.progress-steps {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 2rem;
  font-size: 0.875rem;
}

.progress-step {
  display: flex;
  align-items: center;
  color: var(--bs-secondary);
  white-space: nowrap;
}

.progress-step.active {
  color: var(--bs-primary);
  font-weight: 500;
}

.progress-step.completed {
  color: var(--bs-success);
}

.progress-step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e9ecef;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.5rem;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.progress-step.active .progress-step-number {
  background: var(--bs-primary);
  color: #fff;
}

.progress-step.completed .progress-step-number {
  background: var(--bs-success);
  color: #fff;
}

.progress-connector {
  width: 40px;
  height: 2px;
  background: #e9ecef;
  margin: 0 0.5rem;
  flex-shrink: 0;
}

.progress-connector.done,
.progress-step.completed + .progress-connector {
  background: var(--bs-success);
}

/* Compact variant: tighter spacing for 7-step within-subjects */
.progress-steps-compact .progress-connector {
  width: 20px;
  margin: 0 0.25rem;
}

.progress-steps-compact .progress-step-number {
  margin-right: 0.25rem;
}

/* Responsive: hide labels on small screens, show only numbered circles */
@media (max-width: 575.98px) {
  .progress-step-label {
    display: none;
  }
  .progress-step-number {
    margin-right: 0;
  }
  .progress-connector {
    width: 16px;
    margin: 0 0.15rem;
  }
  .progress-steps-compact .progress-connector {
    width: 12px;
    margin: 0 0.1rem;
  }
}

/* Mid-size: hide labels on compact (7-step) only */
@media (min-width: 576px) and (max-width: 767.98px) {
  .progress-steps-compact .progress-step-label {
    display: none;
  }
  .progress-steps-compact .progress-step-number {
    margin-right: 0;
  }
}

/* ========== Questionnaire Components ========== */

.question-item {
  margin-bottom: 1rem;
  padding: 1.25rem;
  background: #f9fafb;
  border-radius: 0.75rem;
  border: 1px solid #f0f1f3;
}

.question-item:last-child {
  margin-bottom: 0;
}

/* --- Likert scale --- */
.likert-scale {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.likert-option {
  flex: 1;
  text-align: center;
}

.likert-option label {
  display: block;
  font-size: 0.82rem;
  color: var(--bs-secondary-color, #6c757d);
  margin-top: 0.25rem;
  cursor: pointer;
}

/* Custom radio circles for Likert */
.likert-option input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid #ced4da;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: inline-block;
  vertical-align: middle;
}

.likert-option input[type="radio"]:hover {
  border-color: var(--bs-primary, #0d6efd);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

.likert-option input[type="radio"]:checked {
  border-color: var(--bs-primary, #0d6efd);
  background: var(--bs-primary, #0d6efd);
  box-shadow: inset 0 0 0 3px #fff;
}

/* Likert endpoint labels (mobile-only, generated by JS) */
.likert-endpoints { display: none; }

/* --- Star rating --- */
.star-rating-group {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.star-rating-group input[type="radio"] {
  display: none;
}

.star-rating-group label {
  font-size: 2rem;
  color: #d1d5db;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.1s ease;
  line-height: 1;
  user-select: none;
}

.star-rating-group label.active {
  color: #f59e0b;
}

.star-rating-group label.hover {
  color: #fbbf24;
}

.star-rating-group label.hover-scale {
  transform: scale(1.15);
}

/* --- Mobile: single-row Likert with numbers only --- */
@media (max-width: 576px) {
  .likert-scale {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 0.25rem;
  }
  .likert-option { flex: 1; min-width: 0; }
  .likert-option input[type="radio"] { width: 2.25rem; height: 2.25rem; }
  .likert-option label { font-size: 0.72rem; padding: 0.1rem 0; line-height: 1.2; }
  .likert-desc { display: none; }

  /* 10-point: two rows of 5 */
  .likert-scale[data-scale-size="10"] { flex-wrap: wrap; justify-content: center; gap: 0.35rem; }
  .likert-scale[data-scale-size="10"] .likert-option { flex: 0 0 calc(20% - 0.35rem); }

  /* 7-point: tighter label font */
  .likert-scale[data-scale-size="7"] .likert-option label { font-size: 0.65rem; }

  /* Likert endpoint labels below scale */
  .likert-endpoints {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    color: var(--bs-secondary-color, #6c757d);
  }
  .likert-endpoint { max-width: 45%; }
  .likert-endpoint-line {
    width: 1px; height: 8px;
    background: var(--bs-secondary-color, #6c757d);
    margin: 0 auto 2px;
  }
  .likert-endpoint-min { text-align: left; }
  .likert-endpoint-min .likert-endpoint-line { margin: 0 0 2px 50%; }
  .likert-endpoint-max { text-align: right; }
  .likert-endpoint-max .likert-endpoint-line { margin: 0 50% 2px 0; }
}

/* ========== Preview Banner (subject-facing) ========== */

.preview-banner {
  background: var(--bs-alert-bg, #fff8e1);
  color: var(--bs-body-color);
  border-bottom: 1px solid var(--bs-alert-border-color, #ffe082);
  padding: 0.75rem 1rem;
  text-align: center;
  font-weight: 500;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.preview-banner a {
  color: var(--bs-primary);
}

body.preview-mode {
  padding-top: 50px;
}

/* Safe area insets for notched devices (study pages) */
@supports (padding: env(safe-area-inset-top)) {
  .preview-banner { padding-top: calc(0.75rem + env(safe-area-inset-top)); }
  body.preview-mode { padding-top: calc(50px + env(safe-area-inset-top)); }
  .study-container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* ========== Utility Classes ========== */

.cursor-pointer { cursor: pointer; }
.cursor-grab    { cursor: grab; }

/* ========== Component Helpers ========== */

.playback-messages {
  min-height: 400px;
  max-height: 600px;
  overflow-y: auto;
}

.qr-code {
  max-width: 250px;
}

.subject-link {
  max-width: 180px;
}

/* ========== Spacing Scale (8px base) ========== */
/*
 * Level 1:  0.25rem  (4px)   → Tight inline spacing
 * Level 2:  0.5rem   (8px)   → Related element gaps
 * Level 3:  1rem     (16px)  → Default paragraph/component gaps
 * Level 4:  1.5rem   (24px)  → Section sub-gaps (mb-4 in Bootstrap)
 * Level 5:  2rem     (32px)  → Section gaps
 * Level 6:  3rem     (48px)  → Major section dividers (mt-5 / mb-5)
 *
 * Convention: Use mb-4 (24px) between cards/sections within a page.
 *             Use mt-4 (24px) for main container top margin.
 *             Use mt-5/mb-5 (48px) for page-level dividers (footer).
 */
