/* Failure modes tab (views/modes.mjs). Tokens only; stages stay neutral, red marks failure,
   green marks success, and dashed purple is only for AI suggestions nobody has accepted yet. */

/* ------------------------------------------------------------------ header and toolbar */
.modes-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  margin-bottom: var(--space-4);
}
.modes-head-text { flex: 1 1 360px; min-width: 0; }
.modes-head .page-lead { margin: 0; }
.modes-head .page-title:focus { outline: none; }

.modes-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.modes-ai { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); min-width: 0; }
.modes-ai-lock { max-width: 52ch; }

.modes-h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-md);
  line-height: 1.3;
}
.modes-count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font: 600 var(--text-xs)/1 var(--font-sans);
  font-variant-numeric: tabular-nums;
}

.modes-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-xs);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: pointer;
  border-radius: 3px;
}
.modes-link:hover { text-decoration-thickness: 2px; }

/* ------------------------------------------------------------------ two columns */
.modes-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}
.modes-main { display: grid; gap: var(--space-4); min-width: 0; }

/* ------------------------------------------------------------------ notes to sort */
.modes-notes {
  position: sticky;
  top: 112px;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 128px);
  padding: 0;
  overflow: hidden;
}
.modes-notes-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 14px var(--space-4) 10px;
}
.modes-select-all { font-size: var(--text-xs); color: var(--ink-2); }
.modes-notes-tip { padding: 0 var(--space-4) 10px; }

.modes-bulk {
  display: grid;
  gap: var(--space-2);
  margin: 0 var(--space-3) 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  animation: modes-rise var(--dur) var(--ease);
}
.modes-bulk-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.modes-bulk-count { flex: 1 1 auto; font: 600 var(--text-xs)/1.3 var(--font-sans); color: var(--accent); }
.modes-bulk-new { width: 100%; }

.modes-note-list {
  display: grid;
  align-content: start;
  gap: 2px;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 2px var(--space-2) var(--space-2);
  overflow: auto;
  list-style: none;
  border-top: 1px solid var(--line);
}
.modes-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 10px 8px 6px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.modes-note:first-child { margin-top: 6px; }
.modes-note:hover { background: var(--surface-2); }
.modes-note.is-selected {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.modes-note-check { margin-top: 3px; }
.modes-note-body { min-width: 0; }
.modes-note-text {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.modes-note.is-empty .modes-note-text { color: var(--ink-3); font-style: italic; }
.modes-note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin-top: 4px;
  min-width: 0;
}
.modes-note-link {
  flex: 1 1 64px;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  font-size: var(--text-xs);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 3px;
}
.modes-note-link:hover { color: var(--accent); text-decoration: underline; }
.modes-note .stage-chip { min-height: 20px; padding-top: 0; padding-bottom: 0; }
.modes-note .stage-chip .stage-label { max-width: 16ch; }
.modes-note-menu { margin-left: auto; }
.modes-note-menu .menu-button { margin-right: -4px; color: var(--ink-3); }
.modes-note:hover .modes-note-menu .menu-button,
.modes-note.is-selected .modes-note-menu .menu-button,
.modes-note-menu .menu-button:focus-visible { color: var(--ink); }

.modes-notes-done {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4) var(--space-6);
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  text-align: center;
}
.modes-notes-done p { margin: 0; max-width: 30ch; }
.modes-done-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--good-soft);
  color: var(--good);
}

.modes-nonote {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px var(--space-3);
  margin: 0;
  padding: 10px var(--space-4);
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-size: var(--text-xs);
}

/* ------------------------------------------------------------------ notices */
.modes-hint-many,
.modes-recheck {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--ink);
}
.modes-hint-many > .icon, .modes-recheck > .icon { color: var(--warn); }
.modes-hint-many p, .modes-recheck p { flex: 1 1 240px; margin: 0; min-width: 0; }

/* ------------------------------------------------------------------ ranked bars */
.modes-summary { padding: var(--space-4) 18px; }
.modes-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px var(--space-3);
  margin-bottom: 10px;
}
.modes-bars { display: grid; gap: 1px; margin: 0 -8px; padding: 0; list-style: none; }
.modes-bar-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1.25fr) minmax(96px, 2fr) 4ch 5ch;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}
.modes-bar-row:hover { background: var(--surface-2); }
.modes-bar-rank { font: 500 var(--text-xs)/1 var(--font-mono); color: var(--ink-3); text-align: right; }
.modes-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.modes-bar-track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.modes-bar-row:hover .modes-bar-track { background: var(--bg); }
.modes-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--bad);
  transition: width var(--dur-slow) var(--ease);
}
.modes-bar-fill.is-success { background: var(--good); }
.modes-bar-count { text-align: right; font-weight: 600; }
.modes-bar-share { text-align: right; color: var(--ink-3); font-size: var(--text-xs); }

/* ------------------------------------------------------------------ AI suggestions (not accepted yet) */
.modes-suggestions { display: grid; gap: 10px; }
.modes-suggestion {
  display: grid;
  gap: var(--space-2);
  padding: 14px var(--space-4);
  border: 1.5px dashed color-mix(in srgb, var(--ai) 70%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ai-soft) 60%, var(--surface));
}
.modes-suggestion-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ai);
  font: 600 var(--text-xs)/1.3 var(--font-sans);
}
.modes-suggestion-name { font-size: var(--text-md); }
.modes-suggestion-def { margin: 0; color: var(--ink-2); max-width: 72ch; }
.modes-suggestion-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.modes-suggestion-reason { color: var(--ink-2); font-size: var(--text-xs); }
.modes-suggestion-notes { min-width: 0; margin: 2px 0 0; padding: 0; border: 0; }
.modes-suggestion-notes ul { display: grid; gap: 2px; margin: 6px -8px 0; padding: 0; list-style: none; }
.modes-suggestion-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.modes-suggestion-note:hover { background: color-mix(in srgb, var(--ai-soft) 80%, var(--surface)); }
.modes-suggestion-note input { margin-top: 3px; }
.modes-suggestion-note-body { display: grid; gap: 2px; min-width: 0; }
.modes-suggestion-note-text { color: var(--ink); overflow-wrap: anywhere; }
.modes-suggestion-note-meta { color: var(--ink-3); font-size: var(--text-xs); overflow-wrap: anywhere; }
.modes-suggestion-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: 2px; }

/* ------------------------------------------------------------------ first-mode prompt */
.modes-start {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-2);
}
.modes-start p { margin: 6px 0 0; max-width: 60ch; }
.modes-start strong { color: var(--ink); font-weight: 600; }
.modes-start-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ mode cards */
.modes-card {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 18px 20px 12px 22px;
  scroll-margin-top: 120px;
}
.modes-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  width: 3px;
  height: 32px;
  border-radius: 0 3px 3px 0;
  background: var(--bad);
}
.modes-card.is-success::before { background: var(--good); }
.modes-card:focus { outline: none; }
.modes-card.is-flash { animation: modes-flash 1.6s var(--ease); }

.modes-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-4);
}
.modes-card-titles { display: grid; gap: 4px; min-width: 0; }

.modes-name,
.modes-def {
  width: calc(100% + 14px);
  min-height: 0;
  margin: 0 -7px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
}
.modes-name {
  display: block;
  resize: none;
  overflow: hidden;
  font: 600 var(--text-lg)/1.3 var(--font-sans);
  letter-spacing: -0.01em;
  color: var(--ink);
}
.modes-def {
  display: block;
  resize: none;
  overflow: hidden;
  font: 400 var(--text-sm)/1.5 var(--font-sans);
  color: var(--ink-2);
}
.modes-def::placeholder { font-style: italic; }
.modes-name:hover,
.modes-def:hover { border-color: var(--line); }
.modes-name:focus,
.modes-def:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
  color: var(--ink);
}

.modes-card-count {
  display: grid;
  justify-items: end;
  min-width: 64px;
  padding-top: 2px;
  line-height: 1.15;
  text-align: right;
}
.modes-count-num {
  font: 600 var(--text-xl)/1 var(--font-sans);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--bad);
}
.modes-count-num.is-success { color: var(--good); }
.modes-count-num.is-zero { color: var(--ink-3); }
.modes-count-word { margin-top: 4px; color: var(--ink-3); font-size: var(--text-xs); }
.modes-count-share { color: var(--ink-2); font-size: var(--text-xs); font-weight: 600; font-variant-numeric: tabular-nums; }

.modes-card-grid {
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(0, 1fr);
  align-items: start;
  gap: var(--space-3) var(--space-5);
}
.modes-field { display: grid; gap: 6px; min-width: 0; }
.modes-stage { min-height: 32px; padding-top: 5px; padding-bottom: 5px; }
.modes-instructed .segmented { justify-self: start; }
.modes-instructed-hint { max-width: 62ch; }

.modes-chips { display: grid; gap: 6px; }
.modes-chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.modes-readonly-chip .icon { margin-left: -2px; }
.modes-readonly-chip.is-unset { background: transparent; border: 1px dashed var(--line); color: var(--ink-3); }

.modes-evidence { display: grid; gap: 6px; }
.modes-evidence-title { font: 600 var(--text-xs)/1.3 var(--font-sans); color: var(--ink-3); }
.modes-evidence-empty { margin: 0; color: var(--ink-3); font-size: var(--text-xs); }
.modes-evidence-empty strong { color: var(--ink-2); font-weight: 600; }
.modes-quotes { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.modes-quote {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 5px 10px;
  border-left: 2px solid var(--line);
  border-radius: 0 6px 6px 0;
  color: var(--ink);
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.modes-quote:hover { background: var(--surface-2); border-left-color: var(--ink-3); text-decoration: none; }
.modes-quote-text { min-width: 0; overflow-wrap: anywhere; }
.modes-quote-text::before { content: open-quote; }
.modes-quote-text::after { content: close-quote; }
.modes-quote-id { flex: none; color: var(--ink-3); font: 400 var(--text-xs)/1.3 var(--font-mono); }
.modes-more {
  justify-self: start;
  margin-left: 12px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: 500 var(--text-xs)/1.3 var(--font-sans);
  cursor: pointer;
  border-radius: 3px;
}
.modes-more:hover { text-decoration: underline; }

.modes-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.modes-source { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: var(--text-xs); }
.modes-card-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.modes-delete:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); }

/* ------------------------------------------------------------------ Not a product problem bucket */
.modes-bucket {
  border: 1.5px dashed color-mix(in srgb, var(--ink-3) 45%, var(--line));
  border-radius: var(--radius);
}
.modes-bucket:focus { outline: none; }
.modes-bucket-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px var(--space-3);
  padding: 12px var(--space-4);
  border-radius: var(--radius);
  cursor: pointer;
  list-style: none;
}
.modes-bucket-summary::-webkit-details-marker { display: none; }
.modes-bucket-summary:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.modes-bucket-summary:focus-visible { outline-offset: -2px; }
.modes-bucket-title { font-weight: 600; color: var(--ink); }
.modes-bucket-meta { flex: 1 1 auto; color: var(--ink-3); font-size: var(--text-xs); }
.modes-bucket-chevron { display: inline-flex; color: var(--ink-3); transition: transform var(--dur) var(--ease); }
.modes-bucket[open] .modes-bucket-chevron { transform: rotate(180deg); }
.modes-bucket-body { display: grid; gap: 10px; padding: 0 var(--space-4) 12px 18px; }

/* ------------------------------------------------------------------ next step */
.modes-next {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 20px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.modes-next p { margin: 0; color: var(--ink-2); }

.modes-empty-card { padding: 0; }

/* ------------------------------------------------------------------ dialogs */
.modes-form { display: grid; gap: var(--space-4); }
.modes-form-def { min-height: 84px; }
.modes-form-notes { display: grid; gap: 6px; }
.modes-form-notes ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  list-style: none;
}
.modes-form-notes li { display: grid; gap: 1px; min-width: 0; overflow-wrap: anywhere; }
.modes-form-note-id { color: var(--ink-3); font-size: var(--text-xs); }
.modes-form-more { color: var(--ink-3); font-size: var(--text-xs); }
.modes-goes { display: grid; gap: 4px; margin: 6px 0 var(--space-3); padding-left: 1.2em; color: var(--ink-2); }
.modes-merge-pick { display: grid; gap: 4px; min-width: 0; margin: 0 0 var(--space-4); padding: 0; border: 0; }
.modes-merge-pick legend { margin-bottom: 6px; }
.modes-merge-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.modes-merge-option:hover { background: var(--surface-2); }
.modes-merge-option.is-on { border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: var(--accent-soft); }
.modes-merge-name { font-weight: 500; overflow-wrap: anywhere; }
.modes-merge-count { color: var(--ink-3); font-size: var(--text-xs); white-space: nowrap; }

/* ------------------------------------------------------------------ motion */
@keyframes modes-flash {
  0% { outline: 2px solid var(--accent); outline-offset: 2px; }
  70% { outline: 2px solid var(--accent); outline-offset: 2px; }
  100% { outline: 2px solid transparent; outline-offset: 6px; }
}
@keyframes modes-rise { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ narrow screens */
@media (max-width: 899px) {
  .modes-layout { grid-template-columns: minmax(0, 1fr); }
  .modes-notes { position: static; max-height: none; }
  .modes-note-list { max-height: 60vh; }
}

@media (max-width: 640px) {
  .modes-card { padding: var(--space-4) var(--space-4) 10px 18px; }
  .modes-card-grid { grid-template-columns: minmax(0, 1fr); }
  .modes-name { font-size: var(--text-md); }
  .modes-count-num { font-size: var(--text-lg); }
  .modes-bar-row { grid-template-columns: 22px minmax(0, 1fr) auto auto; row-gap: 6px; }
  .modes-bar-track { grid-column: 2 / -1; grid-row: 2; }
  .modes-start { flex-direction: column; }
  .modes-quote { flex-direction: column; gap: 2px; }
}
