/* ============================================================
   components.css — Reusable UI Components
   Button source of truth: docs/13 Section 11
   Primary button: --color-accent-orange-cta (#EA580C, 4.63:1 ✓ WCAG AA)
   Secondary button: --color-primary
   ============================================================ */

/* ══ BUTTONS ══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
  height: 44px;
  min-width: 80px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}
.btn:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}
.btn:active { transform: scale(0.98); box-shadow: none; }
.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--color-disabled-bg) !important;
  color: var(--color-disabled-text) !important;
  border-color: var(--color-disabled-border) !important;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
}

/* Primary — docs/13 §11: --color-accent-orange-cta, 4.63:1 ✓ */
.btn-primary {
  background: var(--color-accent-orange-cta);
  color: var(--color-text-on-dark);
  border-color: var(--color-accent-orange-cta);
}
.btn-primary:hover {
  background: var(--color-accent-orange-cta-hover);
  border-color: var(--color-accent-orange-cta-hover);
}
/* Stronger focus ring on orange: use full-opacity primary blue (#050579) */
.btn-primary:focus-visible {
  outline-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(5, 5, 121, 0.2);
}

/* Secondary — docs/13 §11: --color-primary */
.btn-secondary {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  border-color: var(--color-primary);
}
.btn-secondary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

/* Outline — docs/13 §11 */
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline:hover { background: var(--color-surface-alt); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text-primary);
}

/* Sizes */
.btn--sm { height: 36px; padding: 0 var(--space-4); font-size: var(--font-size-xs); min-width: 60px; }
.btn--full-mobile { width: 100%; }
@media (min-width: 480px) { .btn--full-mobile { width: auto; } }

/* Loading spinner in button */
.btn--loading { pointer-events: none; opacity: 0.8; }
.btn--loading::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn--loading::after { animation: none; } }

/* ══ FORM FIELDS ══════════════════════════════════════════ */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-4);
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
@media (min-width: 480px) {
  .form-row { flex-direction: row; }
  .form-field--half { flex: 1; margin-bottom: 0; }
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.form-hint {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-regular);
  color: var(--color-text-muted);
  line-height: var(--line-height-relaxed);
}
.form-required { color: var(--color-error); margin-left: 2px; }

/* Input */
.input {
  height: 44px;
  padding: 0 var(--space-3);
  border: 1.5px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input::placeholder { color: var(--color-text-muted); }
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}
.input--error { border-color: var(--color-error); }
.input--error:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2); }

/* Select chevron */
.input--select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23475569' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-6);
  cursor: pointer;
}

/* Textarea */
.textarea {
  padding: var(--space-3);
  border: 1.5px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  resize: vertical;
  width: 100%;
  min-height: 88px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.textarea::placeholder { color: var(--color-text-muted); }
.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}
.textarea--tall { min-height: 180px; }
.textarea--error { border-color: var(--color-error); }

/* Inline field error */
.form-error {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  font-size: var(--font-size-xs);
  color: var(--color-error);
  padding-top: 2px;
}
.form-error::before { content: '⚠'; flex-shrink: 0; }

/* ══ WORD COUNTER ════════════════════════════════════════ */
.word-counter {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-align: right;
  padding-top: 4px;
}
.word-counter--warn { color: var(--color-warning); font-weight: var(--font-weight-medium); }
.word-counter--over { color: var(--color-error); font-weight: var(--font-weight-medium); }

/* ══ SEGMENTED CONTROL ═══════════════════════════════════ */
.segmented-control {
  display: flex;
  background: var(--color-bg-alt);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 44px;
}
.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.seg-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0 var(--space-2);
  transition: background var(--transition-fast), color var(--transition-fast);
  min-height: 44px;
  user-select: none;
}
.segmented-control input:checked + .seg-label {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
}
.segmented-control input:focus-visible + .seg-label {
  /* Use box-shadow: outline clips inside overflow:hidden container */
  box-shadow: inset 0 0 0 3px var(--color-primary);
}

/* ══ CARD ═══════════════════════════════════════════════ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}
@media (min-width: 768px) { .card { padding: var(--space-5); } }

/* ══ BADGE ══════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1.5;
  border: 1px solid transparent;
}
.badge--info    { background: var(--color-surface-alt); color: var(--color-primary); border-color: var(--color-border); }
.badge--success { background: #F0FDF4; color: var(--color-support-green-text); border-color: #BBF7D0; }
.badge--warn    { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.badge--error   { background: #FEF2F2; color: var(--color-error); border-color: #FECACA; }
.badge--source  { background: var(--color-bg-alt); color: var(--color-text-muted); border-color: var(--color-border); }
.badge--conf-low    { background: #FEF2F2; color: var(--color-error); border-color: #FECACA; }
.badge--conf-medium { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }
.badge--conf-high   { background: #F0FDF4; color: var(--color-support-green-text); border-color: #BBF7D0; }

/* ══ ERROR BANNER (3-part: what / impact / how to fix) ═══ */
.error-banner {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-left: 4px solid var(--color-error);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}
.error-banner__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-error);
  margin-bottom: 4px;
}
.error-banner__impact {
  font-size: var(--font-size-xs);
  color: #7F1D1D;
  margin-bottom: var(--space-2);
  line-height: var(--line-height-relaxed);
}
.error-banner__fix {
  font-size: var(--font-size-xs);
  color: var(--color-error);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ══ SKELETON ═══════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-skeleton-base) 25%,
    var(--color-skeleton-highlight) 50%,
    var(--color-skeleton-base) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--color-skeleton-base); }
}
.skeleton--title { height: 20px; width: 55%; margin-bottom: var(--space-2); }
.skeleton--text  { height: 14px; width: 100%; margin-bottom: var(--space-2); }
.skeleton--w75   { width: 75%; }
.skeleton--card  { height: 88px; width: 100%; margin-bottom: var(--space-3); border-radius: var(--radius-md); }
.skeleton-stack  { display: flex; flex-direction: column; margin-top: var(--space-3); }

/* ══ PROGRESS BAR ═══════════════════════════════════════ */
.progress-bar {
  height: 6px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.progress-bar--lg { height: 10px; }
.progress-bar__fill {
  height: 100%;
  background: var(--color-accent-orange-cta);
  border-radius: var(--radius-pill);
  transition: width var(--transition-slow);
}
.progress-bar__fill--green { background: var(--color-support-green-text); }
.progress-bar__fill--indeterminate {
  width: 40%;
  animation: progress-indeterminate 1.6s ease-in-out infinite;
}
@keyframes progress-indeterminate {
  0%   { margin-left: 0;    width: 0; }
  30%  { margin-left: 0;    width: 60%; }
  70%  { margin-left: 40%;  width: 60%; }
  100% { margin-left: 100%; width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .progress-bar__fill--indeterminate { animation: none; width: 50%; }
}

/* ══ STICKY ACTION BAR ══════════════════════════════════ */
.sticky-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.07);
  z-index: var(--z-sticky);
  padding: var(--space-3) 0;
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  /* Hide all sticky bars by default; only active module's is shown */
  display: none;
}
.module-panel--active .sticky-bar { display: block; }

.sticky-bar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.sticky-bar__secondary {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
  flex-wrap: wrap;
}

/* Keep sticky behavior consistent on desktop */

/* ══ TAB BAR (Module 2) ═════════════════════════════════ */
.tab-bar {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-bar__tab {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-4);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.tab-bar__tab:hover { color: var(--color-primary); }
.tab-bar__tab--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}
.tab-bar__tab:focus-visible {
  box-shadow: inset 0 0 0 3px var(--color-primary);
  outline: none;
}
.tab-panel { display: block; }

/* ══ MODAL ══════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: flex-end; /* bottom sheet on mobile */
  justify-content: center;
}
.modal-backdrop[hidden] {
  display: none !important;
}
@media (min-width: 768px) {
  .modal-backdrop { align-items: center; }
}

.modal-sheet {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: sheet-in var(--transition-normal) ease both;
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-sheet--fullscreen {
  max-height: 100dvh;
  border-radius: 0;
}

@media (min-width: 768px) {
  .modal-sheet {
    border-radius: var(--radius-lg);
    max-width: 480px;
    max-height: 80dvh;
  }
  .modal-sheet--fullscreen {
    max-height: 80dvh;
    border-radius: var(--radius-lg);
  }
  @keyframes sheet-in {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }
}
@media (prefers-reduced-motion: reduce) {
  .modal-sheet { animation: none; }
}

.modal-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}
.modal-sheet__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}
.modal-sheet__close {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-size: 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}
.modal-sheet__close:hover { background: var(--color-surface-alt); }
.modal-sheet__close:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}
.modal-sheet__body {
  padding: var(--space-4);
  flex: 1;
  overflow-y: auto;
}
.modal-sheet__footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: var(--color-surface);
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
}

/* ══ FORM ACCORDION ═════════════════════════════════════ */
.form-accordion {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.form-accordion__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
  list-style: none;
  min-height: 44px;
  background: var(--color-bg-alt);
}
.form-accordion__summary::-webkit-details-marker { display: none; }
.form-accordion__summary:focus-visible {
  box-shadow: inset 0 0 0 3px var(--color-primary);
  outline: none;
}
.form-accordion__hint {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-regular);
  color: var(--color-text-muted);
  margin-left: auto;
}
.form-accordion__body { padding: var(--space-4); background: var(--color-surface); }

/* ══ EXPORT OPTIONS ═════════════════════════════════════ */
.export-options { display: flex; flex-direction: column; gap: var(--space-3); }

.export-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: var(--font-body);
  min-height: 64px;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.export-option:hover {
  border-color: var(--color-primary);
  background: var(--color-bg-alt);
}
.export-option:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}
.export-option__icon { font-size: 24px; flex-shrink: 0; }
.export-option strong { display: block; font-size: var(--font-size-sm); color: var(--color-text-primary); }
.export-option small  { display: block; font-size: var(--font-size-xs); color: var(--color-text-muted); margin-top: 2px; }

/* ══ EXAMPLE BRIEF CONTENT ══════════════════════════════ */
.example-brief { display: flex; flex-direction: column; gap: var(--space-3); }
.example-brief__row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.example-brief__label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.example-brief__value {
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  line-height: var(--line-height-relaxed);
  background: var(--color-bg-alt);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

/* Offer guideline questions */
.offer-guideline-list {
  display: grid;
  gap: 0;
  margin-top: var(--space-2);
}

.offer-guideline-item {
  display: block;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
  background: transparent;
}

.offer-guideline-item__q {
  margin: 0;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

.offer-guideline-item__meta {
  margin: 2px 0 var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.offer-guideline-item .textarea {
  min-height: 72px;
}

.offer-guideline-proof {
  margin: var(--space-2) 0 var(--space-2);
}

.offer-guideline-proof .form-label {
  font-size: var(--font-size-xs);
}

.offer-guideline-proof .form-hint {
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
}

@media (max-width: 767px) {
  .offer-guideline-item {
    padding: var(--space-3) 0;
  }
}
