/* components — chips, review/improvement forms, chip-dropdown, health */

  /* Chips */

  .chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: var(--font-control);
    font-weight: 600;
    white-space: nowrap;
  }

  .chip.good { color: #d2f2de; background: rgba(34, 179, 74, 0.16); border-color: rgba(34, 179, 74, 0.4); }
  .chip.warn { color: #fed7aa; background: rgba(249, 115, 22, 0.14); border-color: rgba(249, 115, 22, 0.4); }
  .chip.bad  { color: #fecaca; background: rgba(220, 38, 38, 0.14); border-color: rgba(220, 38, 38, 0.4); }
  .chip.info { color: #dbeafe; background: rgba(37, 99, 235, 0.16); border-color: rgba(37, 99, 235, 0.4); }
  /* Errored benchmark unit: purple, so a failure never reads as a merely low .bad score. */
  .chip.err  { color: #e9d5ff; background: rgba(168, 85, 247, 0.16); border-color: rgba(168, 85, 247, 0.4); }
  /* Benchmark units that will NEVER run in this deployment: dimmed and dashed,
     so they don't read as the plain not-yet-run pending dot. */
  .chip.skip { color: var(--muted); background: transparent; border-style: dashed; }

  /* Chips inside table cells can NEVER bleed into the neighbouring column:
     clip to the cell and degrade long labels to an ellipsis. inline-block
     (not inline-flex) because text-overflow only ellipsizes block text. */
  td .chip {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
  }

  /* Internal Review (lp.dash) thumb buttons */
  .internal-review-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .internal-review-cell {
    display: inline-flex;
    gap: 6px;
  }

  .internal-review-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 32px;
    height: 28px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted-strong);
    font-size: var(--font-control);
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
  }

  .internal-review-btn:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.25);
  }

  .internal-review-btn.up.active {
    color: #d2f2de;
    background: rgba(34, 179, 74, 0.18);
    border-color: rgba(34, 179, 74, 0.5);
  }

  .internal-review-btn.down.active {
    color: #fecaca;
    background: rgba(220, 38, 38, 0.18);
    border-color: rgba(220, 38, 38, 0.5);
  }

  /* The set "irrelevant" verdict is a STATUS indicator: it carries the sheet's
     warning accent (--amber, spelled rgba here for the alpha — same expansion
     as .chip.warn) so it reads on its own, not only via the dimmed row, and
     stays distinct from the green up / red down actives. Applies to the row
     button and the modal button alike — both carry .irrelevant.active. */
  .internal-review-btn.irrelevant.active {
    color: #fed7aa;
    background: rgba(249, 115, 22, 0.18);
    border-color: rgba(249, 115, 22, 0.55);
  }

  /* Rows marked irrelevant by a -1 internal review: dimmed, never hidden —
     the buttons stay clickable so the marker can be revised. */
  tr.row-irrelevant td {
    opacity: 0.45;
  }

  /* The verdict cell escapes the dim: at 0.45 the orange marker that EXPLAINS
     why the row is greyed would itself wash out, and the buttons stay the
     control for revising the marker. */
  tr.row-irrelevant td:has(.internal-review-cell) {
    opacity: 1;
  }

  .internal-review-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .internal-review-toggle {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }

  .internal-review-textarea {
    width: 100%;
    min-height: 100px;
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    font-size: var(--font-control);
    line-height: 1.5;
    resize: vertical;
  }

  .internal-review-textarea::placeholder { color: rgba(255, 255, 255, 0.35); }

  .internal-review-textarea:focus {
    outline: none;
    border-color: rgba(34, 179, 74, 0.5);
  }

  .internal-review-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }

  .internal-review-buttons {
    display: flex;
    gap: 8px;
    margin-left: auto;
  }

  .internal-review-cancel,
  .internal-review-submit {
    height: 34px;
    padding: 0 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: var(--font-control);
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    transition: border-color 0.15s, background 0.15s;
  }

  .internal-review-cancel:hover {
    border-color: rgba(255, 255, 255, 0.25);
  }

  .internal-review-submit.positive {
    background: rgba(34, 179, 74, 0.2);
    border-color: rgba(34, 179, 74, 0.5);
    color: #d2f2de;
  }

  .internal-review-submit.positive:hover:not(:disabled) {
    background: rgba(34, 179, 74, 0.3);
  }

  .internal-review-submit.negative {
    background: rgba(220, 38, 38, 0.2);
    border-color: rgba(220, 38, 38, 0.5);
    color: #fecaca;
  }

  .internal-review-submit.negative:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.3);
  }

  .internal-review-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  /* Comment-count indicator per improvement row; opens the thread modal. */
  .improvement-comments-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-family: inherit;
    font-size: var(--font-control);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
  }

  .improvement-comments-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.22);
  }

  /* Comment thread entries inside the modal. */
  .improvement-comments-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .improvement-comment {
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
  }

  .improvement-comment + .improvement-comment { margin-top: 10px; }

  .improvement-comment-meta {
    font-size: 0.69rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 4px;
  }

  .improvement-comment-body {
    font-size: 0.93rem;
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* Chip-dropdown — shared colored-label selector; native <option> cannot be
     styled as colored chips. The trigger reuses .chip colors; the open/closed
     state lives in CHIP_DD_OPEN (state-driven render, survives the 10s tick).
     Used by the improvements Scope column and the form-embedded label
     selectors (improvement scope, support source, new-user role). */
  .chip-dropdown {
    position: relative;
    display: inline-block;
    max-width: 100%;
  }

  /* .chip.chip-dd-btn outranks the td .chip inline-block rule: the trigger
     stays a flex row (label + caret) and ellipsizes via .chip-dd-label. */
  .chip.chip-dd-btn {
    display: inline-flex;
    align-items: center;
    appearance: none;
    font-family: inherit;
    gap: 6px;
    max-width: 100%;
    cursor: pointer;
    /* Match the shared closed-control box: explicit 28px height with zeroed
       vertical padding (overriding base .chip's 4px 9px) so the flex label
       centers in the same pixel height a 28px native <select> renders. Keep
       the base chip's 9px horizontal padding. */
    height: 28px;
    padding: 0 9px;
    box-sizing: border-box;
    transition: background 0.15s, border-color 0.15s;
  }

  .chip-dd-btn:disabled { opacity: 0.6; cursor: not-allowed; }

  .chip-dd-btn:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
  }

  .chip-dd-btn:focus-visible,
  .chip-dd-btn:focus {
    outline: none;
    border-color: var(--accent-5);
  }

  .chip-dd-btn .chip-dd-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Hide the ▾ glyph and draw the same inline-SVG chevron used by the header
     controls, so every closed pill caret stays visually consistent. */
  .chip-dd-btn .chip-dd-caret {
    width: 10px;
    height: 7px;
    font-size: 0;
    color: transparent;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='rgba(255,255,255,0.6)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 1.5 6 6.5 11 1.5'/></svg>");
    background-repeat: no-repeat;
    background-size: 10px 7px;
    background-position: center;
  }

  .chip-dd-btn.chip-dd-empty {
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
    border-style: dashed;
  }

  .chip-dd-btn.chip-dd-empty:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.25);
  }

  .chip-dd-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 60;
    min-width: 180px;
    /* Long option lists scroll instead of growing past the viewport. */
    max-height: 40vh;
    overflow-y: auto;
    padding: 6px;
    flex-direction: column;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }

  .chip-dropdown.open .chip-dd-menu { display: flex; }

  /* Flipped above the trigger when the viewport leaves no room below
     (set by chipDdApplyPlacement after every repaint). */
  .chip-dd-menu.drop-up {
    top: auto;
    bottom: calc(100% + 4px);
  }

  .chip-dd-option {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 4px 6px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
  }

  .chip-dd-option:hover { background: rgba(255, 255, 255, 0.08); }

  .chip-dd-option .chip { pointer-events: none; }

  /* Multi-select variant: the trigger shows the SET of selected label chips
     (or the placeholder), and each option carries a ✓ check column. Shares the
     .chip-dropdown / .chip-dd-menu shell with the single-select component. */
  .chip-dd-multi-btn { flex-wrap: nowrap; }

  .chip-dd-multi {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
  }

  .chip-dd-multi .chip { pointer-events: none; flex-shrink: 0; }

  .chip-dd-check {
    display: inline-flex;
    width: 14px;
    flex-shrink: 0;
    justify-content: center;
    color: var(--accent-5);
    font-weight: 700;
  }

  .chip-dd-option-on { background: rgba(255, 255, 255, 0.06); }

  /* td clips overflow for ellipsis, .panel/.panel-body clip for layout —
     all of which would cut or scroll an OPEN popover. Let it escape. */
  td:has(.chip-dropdown.open) { overflow: visible; }
  .panel:has(.chip-dropdown.open),
  .panel-body:has(.chip-dropdown.open) { overflow: visible; }

  .improvement-add-btn {
    /* Flex-center the "+" glyph (same approach as .internal-review-btn);
       the UA's default button line box left it visibly off-center. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    color: #d2f2de;
    background: rgba(34, 179, 74, 0.16);
    border: 1px solid rgba(34, 179, 74, 0.4);
    transition: background 0.15s, border-color 0.15s;
  }

  .improvement-add-btn:hover {
    background: rgba(34, 179, 74, 0.28);
    border-color: rgba(34, 179, 74, 0.6);
  }

  .manual-improvement-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* 16px matches .filter-bar, the sibling above the table in other panels. */
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
  }

  .manual-improvement-form[hidden] {
    display: none;
  }

  .manual-improvement-form .internal-review-textarea {
    margin-top: 0;
    min-height: 70px;
  }

  .manual-form-label {
    display: inline-flex;
    align-items: center;
    color: var(--muted);
    font-size: var(--font-control);
    font-weight: 600;
  }

  .internal-review-status {
    color: var(--muted);
    font-size: 0.82rem;
  }

  .internal-review-status.error {
    color: #fecaca;
  }

  .muted { color: var(--muted); }

  .snippet {
    color: var(--muted-strong);
    word-break: break-word;
    font-size: 0.88rem;
    line-height: 1.35;
  }

  /* Failed-turn response snippet: same red as .chip.bad text. */
  .snippet.bad { color: #fecaca; }

  /* In-flight turn: live "Generating response since Xs…" cell (see app.js). */
  .snippet.generating {
    color: var(--muted);
    animation: generating-pulse 1.6s ease-in-out infinite;
  }

  @keyframes generating-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
  }

  .num-cell {
    color: var(--text);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
  }

  /* Health grid */

  .health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
    gap: 12px;
  }

  .health-card {
    border-radius: var(--radius-md);
    border: 1px solid var(--panel-border);
    background: rgba(255,255,255,0.018);
    padding: 16px 18px;
  }

  .health-label {
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
  }

  .health-value {
    margin-top: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-title);
  }

  .health-card[data-state="good"] .health-value { color: var(--accent-5); }
  .health-card[data-state="warn"] .health-value { color: var(--amber); }
  .health-card[data-state="bad"]  .health-value { color: var(--red); }
  .health-card[data-state="off"]  .health-value { color: rgba(255,255,255,0.45); }

  .health-sub {
    margin-top: 5px;
    color: var(--muted-strong);
    font-size: 0.82rem;
  }

  .empty-state {
    padding: 26px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    color: var(--muted);
    text-align: center;
  }
