/* ================================================================
   ColorFlow Utility Classes
   Replaces inline style= attributes with reusable classes.
   Load after design-system.css in header.php.
   Dependencies: variables.css, design-system.css
   ================================================================ */

/* ================================================================
   1. SPACING
   ================================================================ */

/* Margin-top */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 5px; }
.mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 15px; }
.mt-4 { margin-top: 20px; }
.mt-5 { margin-top: 25px; }

/* Margin-bottom */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.mb-6 { margin-bottom: 1.5rem; }

/* Margin */
.m-0  { margin: 0; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding */
.p-0 { padding: 0; }
.p-2 { padding: 0.25rem; }
.p-3 { padding: 0.5rem; }
.p-4 { padding: 0.75rem; }
.p-5 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-4 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-3 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-4 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.pb-4 { padding-bottom: 0.75rem; }

/* Gap */
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }


/* ================================================================
   2. TYPOGRAPHY
   ================================================================ */

.text-xs   { font-size: var(--font-size-xs); }
.text-sm   { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-md   { font-size: var(--font-size-md); }
.text-lg   { font-size: var(--font-size-lg); }

.fw-normal { font-weight: 400; }
.fw-600    { font-weight: 600; }
.fw-bold   { font-weight: 700; }

.text-muted   { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-error   { color: var(--color-error); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }
.text-uppercase { text-transform: uppercase; letter-spacing: 0.5px; }

.cf-mono { font-family: 'Courier New', monospace; font-size: var(--font-size-xs); }


/* ================================================================
   3. SIZING
   ================================================================ */

.w-full   { width: 100%; }
.w-auto   { width: auto; }
.max-w-sm { max-width: 600px; }
.max-w-md { max-width: 800px; }
.max-w-lg { max-width: 1000px; }
.max-w-xl { max-width: 1100px; }


/* ================================================================
   4. DISPLAY & LAYOUT
   ================================================================ */

.d-flex         { display: flex; }
.d-inline-flex  { display: inline-flex; }
.d-grid         { display: grid; }
.d-block        { display: block; }
.d-inline-block { display: inline-block; }
.d-none         { display: none; }
.flex-wrap    { flex-wrap: wrap; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.items-end    { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end  { justify-content: flex-end; }
.justify-center { justify-content: center; }
.flex-1       { flex: 1; }
.overflow-x-auto { overflow-x: auto; }
.whitespace-nowrap { white-space: nowrap; }
.cursor-pointer { cursor: pointer; }
.valign-bottom  { vertical-align: bottom; }
.valign-top     { vertical-align: top; }
.word-break     { word-wrap: break-word; overflow-wrap: break-word; }

/* Table header accent bands (used in turnaround/review reports) */
.cf-th-lde { background: var(--color-info-bg, #e3f2fd); }
.cf-th-sbe { background: var(--color-danger-light, #fce4ec); }

/* QTX file data — fiber content percent field width */
.cf-fiber-pct { flex: 0 0 80px; }

/* QTX file data — viewing condition submit name label */
.cf-viewing-label { min-width: 150px; }

/* Static report image — responsive with border */
.cf-report-image {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border-light, #ddd);
  border-radius: var(--radius-sm);
}

/* QTX upload — file field min-width */
.cf-qtx-upload-field { min-width: 250px; }

/* Color selection grid — wider cards */
.cf-color-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Table input — min-width for inline text fields */
.cf-input-wide { min-width: 150px; }


/* ================================================================
   5. COMPOSITE COMPONENTS
   ================================================================ */

/* Filter bar — wraps a form filter section */
.cf-filter-bar {
  padding: 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  margin-bottom: 16px;
}

/* Filter grid — flex-wrap layout for filter fields */
.cf-filter-bar .cf-filter-grid {
  margin-bottom: 0;
}

/* Info bar — light grey contextual strip (Target ID, Color, Status) */
.cf-info-bar {
  background: var(--surface-1);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  line-height: 1.6;
}

.cf-info-bar strong {
  color: var(--color-text-primary);
  font-weight: 600;
}

.cf-info-bar .cf-info-sep {
  display: inline-block;
  margin: 0 0.5rem;
  color: var(--border-strong);
}

/* Page header — flex-between with title + actions */
.cf-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.cf-page-header h3 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--color-text-primary);
}

/* Fieldset + legend — grouped form sections */
.cf-fieldset {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--surface-0);
}

.cf-legend {
  font-family: var(--font-heading);
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-primary);
  padding: 0 0.5rem;
}

/* Form section — borderless fieldset used as section divider */
.cf-form-section {
  border: none;
  padding: 0;
  margin: 0 0 1.25rem 0;
}

.cf-form-section-title {
  font-weight: 600;
  font-size: var(--font-size-md);
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.5rem;
  width: 100%;
}

/* Comment thread item */
.cf-comment {
  border-left: 3px solid var(--border-default);
  padding: 0.625rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-0);
}
.cf-comment--success { border-left-color: var(--color-success); }
.cf-comment--info    { border-left-color: var(--color-info); }
.cf-comment--warning { border-left-color: var(--color-warning); }

/* Color checkbox card — selectable color item in a grid */
.cf-color-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s;
}
.cf-color-check:hover { border-color: var(--color-primary); }

/* Form grid — responsive 2-column layout */
.cf-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  row-gap: var(--form-field-gap);
  column-gap: var(--form-col-gap);
}

/* Form grid — auto-fit responsive layout (wraps based on content width) */
.cf-form-grid--auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  row-gap: var(--form-field-gap);
  column-gap: var(--form-col-gap);
}

/* Inputs & selects inside form grids fill their cell */
.cf-form-grid .cf-input,
.cf-form-grid .cf-select,
.cf-form-grid--auto .cf-input,
.cf-form-grid--auto .cf-select {
  width: 100%;
}

@media (max-width: 640px) {
  .cf-form-grid,
  .cf-form-grid--auto {
    grid-template-columns: 1fr;
  }
}

/* Form field — label + input pair inside form grid */
.cf-form-field {
  display: flex;
  flex-direction: column;
}

.cf-form-field label {
  font-weight: 600;
  font-size: var(--font-size-sm);
  line-height: 1.2;
  color: var(--color-text-secondary);
  margin-bottom: var(--form-label-gap);
}

/* Form field spanning full grid width (inside cf-form-grid) */
.cf-form-field--full {
  grid-column: 1 / -1;
}

.cf-form-field .cf-input,
.cf-form-field .cf-select,
.cf-form-field input,
.cf-form-field select,
.cf-form-field textarea {
  width: 100%;
}

/* Alert — error box */
.cf-alert-error {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-danger-light);
  background: var(--color-danger-light);
  border-radius: var(--radius-md);
  color: var(--color-danger);
  font-size: var(--font-size-base);
}

.cf-alert-error strong {
  color: var(--color-danger);
}

.cf-alert-error ul {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}

/* Alert — info */
.cf-alert-info {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-info-bg);
  background: var(--color-info-bg);
  border-radius: var(--radius-md);
  color: var(--color-info);
  font-size: var(--font-size-base);
}

/* Alert — warning */
.cf-alert-warning {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-warning-light);
  background: var(--color-warning-light);
  border-radius: var(--radius-md);
  color: var(--color-warning);
  font-size: var(--font-size-base);
}

/* Alert — success */
.cf-alert-success {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-success-light);
  background: var(--color-success-light);
  border-radius: var(--radius-md);
  color: var(--color-success);
  font-size: var(--font-size-base);
}

/* Inline form validation error text */
.cf-error {
  display: block;
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  margin-bottom: 3px;
}

/* Button row — flex-end gap for form action buttons */
.cf-btn-row {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* Color swatch preview */
.cf-swatch {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  vertical-align: middle;
}

/* File input */
.cf-file-input {
  padding: 0.4rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  background: var(--surface-0);
}

/* Upload box */
.cf-upload-box {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.cf-upload-box h4 {
  margin: 0 0 0.75rem;
  font-family: var(--font-heading);
  font-size: var(--font-size-md);
  font-weight: 600;
}


/* Form grid — 2-column layout with max-width */
.cf-form-grid--2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .cf-form-grid--2col {
    grid-template-columns: 1fr;
  }
}

/* Textarea — styled to match cf-input */
.cf-textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  background: var(--surface-0);
  color: var(--color-text-primary);
  width: 100%;
  resize: vertical;
  transition: border-color 0.15s;
}

.cf-textarea:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-light);
}

/* Label — standalone class (mirrors .cf-form-field label) */
.cf-label {
  font-weight: 600;
  font-size: var(--font-size-sm);
  line-height: 1.2;
  color: var(--color-text-secondary);
  margin-bottom: var(--form-label-gap);
  display: block;
}

/* Alert — generic danger style */
.cf-alert-danger {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-danger);
  background: var(--color-danger-light, #fff5f5);
  border-radius: var(--radius-md);
  color: var(--color-danger);
  font-size: var(--font-size-base);
}

/* Text break — long word wrap */
.text-break {
  word-break: break-all;
  overflow-wrap: break-word;
}


/* ================================================================
   6. ADDITIONAL COMPONENTS
   ================================================================ */

/* Form group — alias for cf-form-field (used in auto-generated views) */
.cf-form-group {
  display: flex;
  flex-direction: column;
}

.cf-form-group label,
.cf-form-group .cf-label {
  font-weight: 600;
  font-size: var(--font-size-sm);
  line-height: 1.2;
  color: var(--color-text-secondary);
  margin-bottom: var(--form-label-gap);
}

.cf-form-group .cf-input,
.cf-form-group .cf-select,
.cf-form-group input,
.cf-form-group select,
.cf-form-group textarea {
  width: 100%;
}

/* Color swatch — inline color preview (larger than cf-swatch) */
.cf-color-swatch {
  display: inline-block;
  width: 32px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  vertical-align: middle;
  flex-shrink: 0;
}

/* Chart grid — side-by-side chart layout */
.cf-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .cf-chart-grid {
    grid-template-columns: 1fr;
  }
}

/* Chart container — canvas wrapper with fixed height */
.cf-chart-container {
  position: relative;
  height: 400px;
  width: 100%;
}

.cf-chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Code block — preformatted text display */
.cf-code-block {
  background: var(--surface-1);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  font-family: 'Courier New', monospace;
  font-size: var(--font-size-xs);
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.5;
}

/* Thumbnail — image preview with constrained size */
.cf-thumb {
  max-width: 200px;
  height: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

/* Checkbox list — scrollable bordered container for checkbox groups */
.cf-checkbox-list {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  max-height: 250px;
  overflow-y: auto;
  background: var(--surface-0);
}

/* Checkbox item — individual checkbox label inside cf-checkbox-list */
.cf-checkbox-item {
  display: block;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius-xs);
  font-size: var(--font-size-base);
  transition: background 0.1s;
}

.cf-checkbox-item:hover {
  background: var(--surface-1);
}

.cf-checkbox-item input[type="checkbox"] {
  margin-right: 0.5rem;
  vertical-align: middle;
}


/* Section label — uppercase muted heading */
.cf-section-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Full-width grid span (alias for cf-form-field--full) */
.cf-grid-full {
  grid-column: 1 / -1;
}

/* Margin-top extended */
.mt-5 { margin-top: 25px; }

/* Margin-bottom extended */
.mb-7 { margin-bottom: 2rem; }
.mb-8 { margin-bottom: 2.5rem; }


/* ================================================================
   7. RESPONSIVE OVERRIDES
   ================================================================ */

@media (max-width: 768px) {
  .cf-page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .cf-btn-row {
    flex-wrap: wrap;
  }
}

/* Collapsible filter toggle — visible on mobile only */
.cf-filter-collapse-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface-0);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  font-weight: 600;
  cursor: pointer;
  color: var(--color-text-primary);
  transition: background var(--duration-fast) ease;
  margin-bottom: 10px;
}

.cf-filter-collapse-toggle:hover {
  background: var(--surface-2);
}

/* ================================================================
   8. PAGE-ENTER ANIMATIONS & MICRO-INTERACTIONS
   ================================================================ */

/* Keyframes — gentle fade + rise */
@keyframes cfFadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Apply staggered entrance to key design system elements */
.cf-card,
.cf-filter-bar,
.cf-info-bar,
.cf-page-header,
.cf-alert-info,
.cf-alert-warning,
.cf-alert-error,
.cf-alert-success {
  animation: cfFadeInUp 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Stagger: 2nd element +60ms, 3rd +120ms, etc */
.cf-card:nth-child(2),
.cf-filter-bar ~ .cf-card:first-of-type { animation-delay: 60ms; }
.cf-card:nth-child(3) { animation-delay: 120ms; }
.cf-card:nth-child(4) { animation-delay: 180ms; }
.cf-card:nth-child(5) { animation-delay: 240ms; }
.cf-card:nth-child(n+6) { animation-delay: 280ms; }

/* Table containers — slight delay after cards */
.cf-table {
  animation: cfFadeInUp 0.3s cubic-bezier(0.22, 1, 0.36, 1) 80ms both;
}

/* Card hover lift — subtle depth on interaction */
.cf-card {
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.cf-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Button hover micro-animation — slight scale */
.but {
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 100ms ease;
}

.but:active:not(:disabled) {
  transform: scale(0.97);
}

/* Badge pulse on first appearance */
@keyframes cfBadgePop {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.cf-badge {
  animation: cfBadgePop 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Smooth row hover transitions for tables */
.cf-table tbody tr {
  transition: background-color 120ms ease;
}

/* Link underline animation */
.cf-card a:not(.but):not([class*="but-"]) {
  text-decoration: none;
  background-image: linear-gradient(var(--color-orange-light), var(--color-orange-light));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 200ms ease;
}

.cf-card a:not(.but):not([class*="but-"]):hover {
  background-size: 100% 1px;
}

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cf-card,
  .cf-filter-bar,
  .cf-info-bar,
  .cf-page-header,
  .cf-alert-info,
  .cf-alert-warning,
  .cf-alert-error,
  .cf-alert-success,
  .cf-table,
  .cf-badge {
    animation: none;
  }

  .cf-card:hover {
    box-shadow: none;
  }

  .but:active:not(:disabled) {
    transform: none;
  }

  .cf-card a:not(.but):not([class*="but-"]) {
    background-image: none;
    text-decoration: underline;
  }
}
