/* ==========================================================================
   Joint Health Guide — Flare Tracker (tool-specific styles)
   Builds on the tokens in assets/styles.css.
   ========================================================================== */

.ft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
}

.ft-card > h2:first-child,
.ft-section-head h2 {
  margin-top: 0;
}

.ft-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.ft-section-head h2 {
  margin-bottom: 0;
}

/* ---------- Form ---------- */
.ft-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4) var(--sp-5);
}

.ft-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}

.ft-field > label,
.ft-fieldset > legend {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.ft-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
}

.ft-inline label {
  font-weight: 600;
  color: var(--muted);
}

.ft-fieldset {
  border: 0;
  padding: 0;
  margin: var(--sp-5) 0 0;
  min-width: 0;
}

.ft-grid .ft-fieldset {
  margin: 0;
}

.ft-fieldset > legend {
  padding: 0;
  margin-bottom: var(--sp-2);
}

.ft-form input[type="date"],
.ft-form input[type="number"],
.ft-form select,
.ft-form textarea,
.ft-inline select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #cbd5e0;
  border-radius: var(--radius-sm);
  padding: 0.55em 0.7em;
  width: 100%;
  min-height: 44px;
}

.ft-inline select {
  width: auto;
}

.ft-form textarea {
  resize: vertical;
  min-height: 80px;
}

.ft-form input[type="range"] {
  width: 100%;
  accent-color: var(--green);
  min-height: 44px;
  margin: 0;
}

select:focus-visible,
textarea:focus-visible,
label:focus-visible,
.ft-check input:focus-visible + span,
.ft-segmented input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.ft-out {
  font-weight: 800;
  color: var(--link);
  margin-left: var(--sp-2);
}

.ft-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.ft-fieldset .ft-hint {
  margin-bottom: var(--sp-2);
}

/* Checkbox pills */
.ft-checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.ft-check {
  position: relative;
  cursor: pointer;
}

.ft-check input,
.ft-segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.ft-check span,
.ft-segmented span {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 40px;
  padding: 0.4em 0.9em;
  border: 1px solid #cbd5e0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ft-check span:hover,
.ft-segmented span:hover {
  border-color: var(--green);
  background: var(--green-tint);
}

.ft-check input:checked + span {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--link);
}

.ft-check input:checked + span::before {
  content: "✓";
  font-weight: 800;
}

.ft-tags input:checked + span {
  background: var(--amber-tint);
  border-color: var(--amber);
  color: #7c3d10;
}

/* Segmented stress control */
.ft-segmented {
  display: flex;
  gap: var(--sp-1);
}

.ft-segmented label {
  position: relative;
  flex: 1 1 0;
  cursor: pointer;
}

.ft-segmented span {
  width: 100%;
  justify-content: center;
  border-radius: var(--radius-sm);
  padding: 0.4em 0.3em;
  flex-direction: column;
  gap: 0;
  line-height: 1.15;
}

.ft-segmented small {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.ft-segmented input:checked + span {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: #fff;
}

.ft-segmented input:checked + span small {
  color: #e6f4ec;
}

.ft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
  margin-top: var(--sp-5);
  align-items: center;
}

.ft-data .ft-actions,
#ft-data .ft-actions {
  margin-top: var(--sp-3);
}

.btn.ft-danger {
  background: var(--contested);
}

.btn.ft-danger:hover {
  background: #9b2c2c;
}

.ft-file-btn {
  margin: 0;
}

.ft-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ft-status {
  min-height: 1.5em;
  margin: var(--sp-3) 0 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.ft-status--ok { color: var(--link); }
.ft-status--warn { color: #9a4a0f; }
.ft-status--error { color: var(--contested); }

.ft-empty {
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

/* ---------- Chart ---------- */
.ft-chart {
  width: 100%;
}

.ft-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  overflow: visible;
}

.ft-grid-lines line {
  stroke: var(--border);
  stroke-width: 1;
}

.ft-axis {
  fill: var(--muted);
  font-size: 12px;
  font-family: var(--font);
}

.ft-flare-band {
  fill: var(--contested-tint);
  opacity: 0.7;
}

.ft-flare-label {
  fill: var(--contested);
  font-size: 11px;
}

.ft-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.ft-pt {
  fill: var(--surface);
  stroke: var(--green-dark);
  stroke-width: 2;
}

.ft-pt--flare {
  fill: var(--contested);
  stroke: var(--contested);
}

/* ---------- Summary ---------- */
.ft-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}

.ft-stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
}

.ft-stat dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.ft-stat dd {
  margin: 0.15em 0 0;
  font-weight: 800;
  font-size: 1.05rem;
}

.ft-freq-wrap {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-4);
}

.ft-freq h3 {
  font-size: 1rem;
  margin-bottom: var(--sp-2);
}

.ft-freq ul {
  margin: 0;
  padding-left: 1.2em;
}

.ft-print-only {
  display: none;
}

/* ---------- Tables ---------- */
.ft-table {
  min-width: 0;
}

.ft-history-table {
  min-width: 860px;
}

.ft-table td,
.ft-table th {
  vertical-align: middle;
}

.ft-notes-cell {
  max-width: 260px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ft-pain-pill {
  display: inline-block;
  min-width: 2em;
  text-align: center;
  font-weight: 800;
  padding: 0.1em 0.5em;
  border-radius: var(--radius-pill);
  background: var(--green-tint);
  color: var(--green-dark);
}

.ft-pain-pill--flare {
  background: var(--contested-tint);
  color: var(--contested);
}

.ft-diff {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ft-diff--up { color: var(--contested); }
.ft-diff--down { color: var(--green-dark); }

.ft-note {
  color: var(--muted);
  font-size: 0.85em;
}

.ft-small-badge {
  margin-left: var(--sp-2);
}

.ft-col-actions {
  white-space: nowrap;
}

.ft-link-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.35em 0.5em;
  min-height: 36px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green-dark);
  cursor: pointer;
  border-radius: var(--radius-sm);
  text-decoration: underline;
}

.ft-link-btn:hover {
  background: var(--green-tint);
}

.ft-link-btn--danger {
  color: var(--contested);
}

.ft-link-btn--danger:hover {
  background: var(--contested-tint);
}

.ft-caveat {
  margin-top: 0;
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .ft-card {
    padding: var(--sp-4);
  }

  .ft-grid,
  .ft-freq-wrap {
    grid-template-columns: 1fr;
  }

  .ft-table:not(.ft-history-table) {
    font-size: 0.85rem;
  }

  .ft-table:not(.ft-history-table) th,
  .ft-table:not(.ft-history-table) td {
    padding: 0.5em 0.5em;
  }

  .ft-actions .btn {
    flex: 1 1 auto;
    text-align: center;
  }
}

/* ---------- Print: doctor visit summary ---------- */
@media print {
  @page {
    margin: 14mm;
  }

  main .container > *:not(.ft-print) {
    display: none !important;
  }

  .ft-card {
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0 0 6mm;
  }

  .ft-print-only {
    display: block;
    margin-bottom: 4mm;
  }

  #ft-summary {
    order: -1;
  }

  main .container {
    display: flex;
    flex-direction: column;
  }

  .ft-section-head .btn,
  .ft-section-head .ft-field,
  .ft-col-actions {
    display: none !important;
  }

  .ft-stat {
    background: #fff;
    border-color: #999;
  }

  .ft-history-table {
    min-width: 0;
    font-size: 9pt;
  }

  .ft-history-wrap {
    overflow: visible;
    break-inside: auto;
    border: 0;
  }

  .ft-history-table tr {
    break-inside: avoid;
  }

  .ft-flare-band {
    fill: #f2f2f2;
  }

  .ft-pt--flare {
    fill: #000;
    stroke: #000;
  }

  .ft-line {
    stroke: #000;
  }

  .ft-svg {
    max-height: 200px;
  }

  main a[href^="http"]::after {
    content: none;
  }
}
