/* Context/profile cards, editors, family history, diet warnings, and profile tips */

/* Dashboard Section Titles */
.context-section-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 10px;
}
.ctx-refresh-all-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px;
  padding: 2px 6px; margin-left: 6px; border-radius: var(--radius-sm); vertical-align: middle;
  transition: color 0.2s, background 0.2s;
}
.ctx-refresh-all-btn:hover { color: var(--accent); background: var(--bg-card); }
.context-section-subtitle {
  font-size: 13px; color: var(--text-muted); margin-top: 2px; margin-bottom: 8px;
}
.profile-context-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
/* Context Cards (fixed height, uniform grid) */
.context-card {
  background: var(--bg-card); border-radius: var(--radius-sm);
  border: 1px solid var(--border); padding: 12px 16px;
  cursor: pointer; transition: all 0.15s;
  min-height: 90px; display: flex; flex-direction: column; overflow: visible; min-width: 0;
}
.context-card:hover { border-color: var(--accent); }
.context-card:has(.ctx-health-dot-red) { border-left: 3px solid var(--red); }
.context-card:has(.ctx-health-dot-yellow) { border-left: 3px solid var(--yellow); }
.context-card:has(.ctx-health-dot-green) { border-left: 3px solid var(--green); }
.context-card-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-shrink: 0; min-width: 0;
}
.context-card-label {
  min-width: 0; overflow: hidden; text-overflow: ellipsis;
  font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap;
}
.diagnoses-edit-btn {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  font-size: 12px; padding: 2px 10px; border-radius: 4px; cursor: pointer;
  font-family: inherit; transition: all 0.15s; margin-left: auto; flex-shrink: 0;
}
.diagnoses-edit-btn:hover { color: var(--accent); border-color: var(--accent); }
.context-card-body {
  font-size: 12px; color: var(--text-secondary); line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; flex: 1; min-height: 0;
}
.context-card-placeholder {
  font-size: 12px; color: var(--text-muted); font-style: italic;
}
/* Empty context cards are visually hollow */
.context-card:has(.context-card-placeholder) {
  border-style: dashed; opacity: 0.75;
}
.context-card:has(.context-card-placeholder):hover { opacity: 1; }
/* Food contaminant warnings on diet card */
.diet-contaminants {
  margin-top: 4px; font-size: 11px; color: var(--yellow); line-height: 1.4;
  cursor: pointer; padding: 4px 0;
}
.diet-contaminants:hover { text-decoration: underline; }
@media (pointer: coarse) {
  .diet-contaminants { min-height: 44px; display: flex; align-items: center; }
  .contaminant-detail-item a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 8px; }
}
.contaminant-section { margin: 16px 0 12px; }
.contaminant-section-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.contaminant-detail-item {
  font-size: 13px; line-height: 1.5; padding: 8px 10px; margin-bottom: 6px;
  background: var(--bg-card); border-radius: 6px; border-left: 3px solid var(--yellow);
}
.contaminant-detail-item a { color: var(--accent); font-size: 11px; margin-left: 4px; }
.contaminant-section:last-of-type .contaminant-detail-item { border-left-color: var(--green); }
.contaminant-actions { display: flex; gap: 8px; margin-top: 20px; }
.contaminant-attribution {
  margin-top: 12px; font-size: 11px; color: var(--text-muted); text-align: center;
}
.contaminant-attribution a { color: var(--text-muted); text-decoration: underline; }
/* Health status dots */
.ctx-health-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  display: inline-block; transition: background 0.3s, box-shadow 0.3s;
}
.ctx-health-dot-gray { background: var(--text-muted); opacity: 0.4; }
.ctx-health-dot-green { background: var(--green); box-shadow: 0 0 6px rgba(52, 211, 153, 0.5); }
.ctx-health-dot-yellow { background: var(--yellow); box-shadow: 0 0 6px rgba(251, 191, 36, 0.5); }
.ctx-health-dot-red { background: var(--red); box-shadow: 0 0 6px rgba(248, 113, 113, 0.5); }
.ctx-health-dot-shimmer {
  background: linear-gradient(90deg, var(--text-muted) 25%, var(--border) 50%, var(--text-muted) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
/* AI card summary */
.ctx-ai-summary {
  font-size: 11px; line-height: 1.3; color: var(--text-muted); font-style: italic;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  max-height: 0; opacity: 0; transition: max-height 0.2s, opacity 0.2s;
  border-top: 1px solid transparent; padding-top: 0; margin-top: 0;
}
.ctx-ai-summary-visible {
  max-height: 20px; opacity: 1;
  border-top: 1px solid var(--border); padding-top: 4px; margin-top: 4px;
}
.ctx-ai-summary-green { color: var(--green); }
.ctx-ai-summary-yellow { color: var(--yellow); }
.ctx-ai-summary-red { color: var(--red); }
/* Context editor field groups */
.ctx-field-group { margin-bottom: 16px; }
.ctx-field-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 8px; display: block;
}
/* Button-group selector (replaces native <select>) */
.ctx-btn-group { display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-btn-option {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); font-size: 12px;
  cursor: pointer; font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.ctx-btn-option:not(.active):hover { border-color: var(--accent); color: var(--accent); }
.ctx-btn-option.active:hover { filter: brightness(1.05); }
/* Focus rings: non-active uses accent; active gets a contrasting ring over its blue background. */
.ctx-btn-option:not(.active):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.ctx-btn-option.active:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6); outline-offset: 2px;
}
/* Skin-type slider: emoji row and range input share the same inner span. */
.ctx-skin-slider-wrap { padding: 8px 0 4px; }
.ctx-skin-emojis {
  position: relative;
  margin: 0 14px 18px;
  height: 50px;
}
.ctx-skin-face {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 28px;
  opacity: 0.4;
  transition: opacity 0.15s, transform 0.15s;
  cursor: pointer;
  padding: 2px 6px 14px;
  display: flex; justify-content: center;
}
.ctx-skin-face[data-idx="0"] { left: 0%; }
.ctx-skin-face[data-idx="1"] { left: 20%; }
.ctx-skin-face[data-idx="2"] { left: 40%; }
.ctx-skin-face[data-idx="3"] { left: 60%; }
.ctx-skin-face[data-idx="4"] { left: 80%; }
.ctx-skin-face[data-idx="5"] { left: 100%; }
.ctx-skin-face:hover { opacity: 0.7; }
.ctx-skin-face.active {
  opacity: 1;
  transform: translateX(-50%) scale(1.25);
}
.ctx-skin-face::after {
  content: attr(data-roman);
  position: absolute;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  pointer-events: none;
}
.ctx-skin-face.active::after { color: var(--text-primary); }
.ctx-skin-range {
  width: calc(100% - 28px);
  margin: 0 14px;
  accent-color: var(--accent);
  display: block;
}
.ctx-skin-label {
  font-size: 13px; color: var(--text-primary);
  text-align: center; margin-top: 10px;
  font-weight: 600;
}
.ctx-skin-label-detail {
  display: block;
  font-size: 11px; color: var(--text-muted);
  font-weight: 400; margin-top: 2px;
  font-style: italic;
}

/* Read-only Light lens setup mirror inside the Light & Circadian editor. */
.ctx-lightsetup-mirror {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}
.ctx-lightsetup-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.ctx-lightsetup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
}
.ctx-lightsetup-row {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12px;
  min-width: 0;
}
.ctx-lightsetup-label {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.ctx-lightsetup-value {
  color: var(--text-primary); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.ctx-lightsetup-edit {
  background: transparent; border: none;
  color: var(--accent); font-size: 12px; font-weight: 500;
  cursor: pointer; padding: 4px 0;
  white-space: nowrap;
}
.ctx-lightsetup-edit:hover { text-decoration: underline; }
.ctx-lightsetup-empty {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12px; color: var(--text-muted);
}
.ctx-lightsetup-hint {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted); line-height: 1.5;
}
@media (max-width: 600px) {
  .ctx-lightsetup-grid { grid-template-columns: 1fr; }
}
.ctx-btn-option.active {
  background: var(--accent-gradient); border-color: transparent; color: white; font-weight: 600;
}
/* Toggle tag buttons for multi-select */
.ctx-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-tag {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary);
  font-size: 12px; padding: 6px 14px; border-radius: 20px; cursor: pointer;
  font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.ctx-tag:hover { border-color: var(--accent); color: var(--accent); }
.ctx-tag.active {
  background: rgba(79, 140, 255, 0.15); border-color: var(--accent); color: var(--accent); font-weight: 600;
}
/* Autocomplete suggestions */
.ctx-autocomplete-wrapper { position: relative; flex: 1; }
.ctx-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 200px; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.ctx-suggestion-item {
  padding: 8px 14px; font-size: 13px; color: var(--text-secondary); cursor: pointer;
  transition: all 0.1s;
}
.ctx-suggestion-item:hover { background: var(--bg-hover); color: var(--text-primary); }
/* Condition list in editor */
.ctx-conditions-list { margin-bottom: 16px; }
.ctx-condition-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 6px; font-size: 13px; transition: border-color 0.15s;
}
.ctx-condition-item:hover { border-color: var(--text-muted); }
.ctx-condition-name { color: var(--text-primary); flex: 1; min-width: 0; font-weight: 500; }
.ctx-condition-since { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.ctx-add-condition {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px;
}
.ctx-add-condition .supp-form-field { flex: 1; min-width: 120px; }
/* Family history subsection */
.ctx-family-history {
  border-top: 1px solid var(--border);
  padding-top: 14px; margin-top: 18px;
}
.ctx-family-head {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px;
}
.ctx-family-count {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  background: var(--bg-tertiary, rgba(128,128,128,0.08));
  padding: 1px 7px; border-radius: 8px; min-width: 16px; text-align: center;
}
.ctx-family-count:empty { display: none; }
.ctx-family-list {
  display: flex; flex-direction: column; gap: 4px; margin: 10px 0 14px;
}
.ctx-family-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; flex-wrap: wrap; transition: border-color 0.15s;
}
.ctx-family-item:hover { border-color: var(--text-muted); }
.ctx-family-relative {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-secondary);
  background: var(--bg-tertiary, rgba(128,128,128,0.08));
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
  flex-shrink: 0;
}
.ctx-family-relative-label { font-weight: 500; }
.ctx-family-condition { color: var(--text-primary); font-weight: 500; flex: 1; min-width: 100px; }
.ctx-family-age {
  font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ctx-family-note {
  font-size: 12px; color: var(--text-muted); font-style: italic;
  flex-basis: 100%; padding-left: 4px; line-height: 1.35;
  margin-top: -2px;
}
.ctx-family-add { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.ctx-family-add-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.ctx-family-select { max-width: 200px; flex-shrink: 0; }
.ctx-family-condition-wrap { flex: 1; min-width: 200px; }
.ctx-family-age-input { width: 130px; flex-shrink: 0; }
.ctx-family-note-input { flex: 1; min-width: 180px; }
@media (max-width: 600px) {
  .ctx-family-select, .ctx-family-condition-wrap,
  .ctx-family-age-input, .ctx-family-note-input { width: 100%; max-width: none; }
  .ctx-family-add-row .import-btn { width: 100%; }
}
/* Context editor note input */
.ctx-note-input {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-primary);
  color: var(--text-primary); font-size: 13px; font-family: inherit;
  transition: border-color 0.15s;
}
.ctx-note-input:focus { border-color: var(--accent); outline: none; }
.ctx-note-input::placeholder { color: var(--text-muted); }
/* Meal row: time + description side by side */
.ctx-meal-row { display: flex; gap: 8px; align-items: center; }
.ctx-meal-time {
  width: 90px; flex-shrink: 0; padding: 10px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-primary);
  color: var(--text-primary); font-size: 13px; font-family: var(--font-mono);
  transition: border-color 0.15s; box-sizing: border-box; text-align: center;
}
.ctx-meal-time::placeholder { color: var(--text-muted); font-family: inherit; font-size: 11px; }
.ctx-meal-time:focus { border-color: var(--accent); outline: none; }
.ctx-meal-input { flex: 1; min-width: 0; }
@media (max-width: 480px) {
  .ctx-meal-row { flex-direction: column; gap: 4px; }
  .ctx-meal-time { width: 100%; }
  .ctx-meal-input { width: 100%; }
}
/* Context editor action bar */
.ctx-editor-actions {
  display: flex; gap: 8px; align-items: center; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.ctx-editor-modal {
  width: min(94vw, 760px);
  max-width: 760px;
  max-height: min(90vh, 860px);
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-secondary);
  box-shadow: var(--shadow-lg);
}
.ctx-editor-modal .ctx-editor-head {
  position: sticky;
  top: 0;
  z-index: 8;
}
.ctx-editor-modal .ctx-editor-body {
  padding: 22px 26px 0;
}
.ctx-editor-modal .modal-unit {
  margin: 0 0 20px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.ctx-editor-modal .ctx-meal-time,
.ctx-editor-modal .note-editor {
  background: var(--bg-primary);
}
.ctx-editor-modal .ctx-btn-option,
.ctx-editor-modal .ctx-tag {
  border-radius: var(--radius-sm);
}
.ctx-editor-modal .ctx-editor-actions {
  position: sticky;
  bottom: 0;
  z-index: 7;
  flex-wrap: wrap;
  margin: 22px -26px 0;
  padding: 14px 26px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-secondary) 96%, var(--bg-card));
  box-shadow: 0 -12px 24px rgba(0,0,0,0.18);
}
/* Context editor modal section divider */
.ctx-editor-divider {
  height: 1px; background: var(--border); margin: 16px 0;
}
/* Additional Notes textarea */
.ctx-notes-section { margin-top: 8px; margin-bottom: 16px; }
.ctx-notes-textarea {
  width: 100%; min-height: 48px; max-height: 120px; resize: vertical;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 12px; padding: 10px 14px;
  font-family: inherit; line-height: 1.5; transition: border-color 0.15s;
  box-sizing: border-box;
}
.ctx-notes-textarea:focus { border-color: var(--accent); outline: none; }
.ctx-notes-textarea::placeholder { color: var(--text-muted); }
.context-info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; font-size: 10px; font-weight: 700;
  color: var(--text-muted); border: 1px solid var(--border); cursor: help;
  flex-shrink: 0; position: relative; font-style: normal; line-height: 1;
}
.context-info-icon:hover { color: var(--accent); border-color: var(--accent); }
.context-info-icon .context-tooltip {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%); background: var(--bg-card); color: var(--text-secondary);
  font-size: 12px; font-weight: 400; line-height: 1.5; padding: 10px 12px;
  border-radius: 6px; border: 1px solid var(--border); width: max-content;
  max-width: 260px; z-index: 100; pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.context-info-icon:hover .context-tooltip { display: block; }

@media (max-width: 720px) {
  .modal-overlay.show:has(.ctx-editor-modal) {
    align-items: stretch;
    padding: 12px;
  }
  .modal.ctx-editor-modal {
    width: 100%;
    max-width: none;
    height: calc(100dvh - 24px);
    max-height: none;
    padding: 0;
  }
  .ctx-editor-modal .gb-modal-head {
    padding: 16px 18px;
  }
  .ctx-editor-modal .gb-modal-title {
    font-size: 20px;
    line-height: 1.2;
  }
  .ctx-editor-modal .ctx-editor-body {
    padding: 18px 18px 0;
  }
  .ctx-editor-modal .ctx-editor-actions {
    margin-left: -18px;
    margin-right: -18px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  }
  .ctx-editor-modal .ctx-btn-option,
  .ctx-editor-modal .ctx-tag,
  .ctx-editor-modal .import-btn {
    min-height: 42px;
  }
  .ctx-editor-modal .ctx-btn-option,
  .ctx-editor-modal .ctx-tag {
    white-space: normal;
    text-align: left;
  }
  .ctx-editor-modal .ctx-add-condition,
  .ctx-editor-modal .goals-add-row,
  .ctx-editor-modal .ctx-family-add-row {
    flex-direction: column;
    align-items: stretch;
  }
  .ctx-editor-modal #condition-since {
    width: 100% !important;
  }
}

@media (max-width: 480px) {
  .context-card { min-height: 72px; padding: 10px 12px; }
  .context-card-label { font-size: 12px; }
}
@media (max-width: 375px) {
  .context-card { min-height: 64px; }
}
@media (hover: none) {
  .context-info-icon .context-tooltip { display: none; }
  .context-info-icon { cursor: default; }
}
@media (pointer: coarse) {
  .ctx-btn-option { min-height: 44px; }
  .ctx-tag { min-height: 44px; }
}

/* Tips badge on chart cards and context cards */
.ctx-tips-badge {
  font-size: 9px; font-weight: 600; letter-spacing: 0.05em; color: var(--accent);
  padding: 1px 5px; border-radius: 4px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  white-space: nowrap; flex-shrink: 0; cursor: pointer; transition: all 0.15s;
  margin-left: 6px; vertical-align: middle;
}
.ctx-tips-badge:hover { background: color-mix(in srgb, var(--accent) 15%, transparent); border-color: var(--accent); }
/* Tips modal */
.ctx-tips-modal-header { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 16px; }
.ctx-tip-slot { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.ctx-tip-slot:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.ctx-tip-slot-label { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.ctx-tip-tier { margin-bottom: 8px; }
.ctx-tip-tier:last-child { margin-bottom: 0; }
.ctx-tip-tier-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 4px; }
.ctx-tip-item { font-size: 13px; line-height: 1.6; color: var(--text-secondary); padding: 2px 0; }
.ctx-tip-free { color: var(--green); }
.ctx-tip-free::before { content: '\2192 '; opacity: 0.5; }
.ctx-tip-form { font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 2px; }
.ctx-tip-avoid { color: var(--orange); }
