/* Troubleshoot tab (troubleshoot-view.js). A slim list of tools on the left, set apart from the environment tabs
   above it: vertical, with a filled marker for the current tool. The tool fills the right side; its picker and
   filters sit at its top. On a phone the list becomes a select. No drop shadows. */
.tab-troubleshoot.env-body { padding: 0; }
.ts-view { min-width: 0; }
.ts-layout { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: 520px; }

/* Tool list */
.ts-rail { padding: 24px 12px; border-right: 1px solid var(--border); background: var(--page); border-radius: 0 0 0 var(--radius-card); }
.ts-rail-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; position: sticky; top: 72px; }
.ts-rail-item { position: relative; display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: 8px; color: var(--secondary); font-size: 14px; font-weight: 500; text-decoration: none; }
.ts-rail-item svg { flex: none; color: var(--muted); }
.ts-rail-item:hover { background: var(--subtle); color: var(--text); text-decoration: none; }
.ts-rail-item[aria-current="page"] { background: var(--current-bg); color: var(--current-text); font-weight: 600; }
.ts-rail-item[aria-current="page"]::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; border-radius: 0 2px 2px 0; background: var(--current-bar); }
.ts-rail-item[aria-current="page"] svg { color: var(--current-text); }
.ts-rail-item:focus-visible { outline-offset: -2px; }
.ts-phone-pick { display: none; }

/* Tool */
.ts-tool { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 24px 24px 24px; }
.ts-tool > .ui-state { margin-top: 8px; }
.ts-tool-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.ts-tool-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ts-pick { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; flex: 1 1 360px; min-width: 0; }
.ts-pick:empty { display: none; }
.ts-pick .ts-field { flex: 0 1 380px; min-width: min(100%, 240px); }
.ts-pick-loading { display: flex; align-items: center; width: 280px; max-width: 100%; height: var(--control-h); }
.ts-pick-loading .skeleton { width: 100%; }
.ts-restart { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-left: auto; min-width: 0; }
.ts-restart:empty { display: none; }
.ts-restart-row { display: flex; align-items: center; min-height: var(--control-h); }
.ts-restart-row > button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h); min-height: var(--control-h); padding: 0 16px; border-color: var(--field-border); background: var(--card); color: var(--text); }
.ts-restart-row > button:hover:not(:disabled) { background: var(--subtle); }
.ts-restart .container-restart-status { max-width: 420px; margin: 0; font-size: 13px; line-height: 20px; color: var(--secondary); text-align: right; }
.ts-restart .container-restart-status.error { color: #B91C1C; }
.ts-restart .container-restart-status.success { color: #166534; }

/* Fields */
.ts-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: 13px; }
.ts-field-label { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--secondary); }
.ts-field input[type="number"] { width: 160px; }
.ts-help { margin: 0; font-size: 13px; line-height: 20px; color: var(--muted); }

/* Container state */
.ts-pill { display: inline-flex; align-items: center; gap: 8px; height: 28px; margin-bottom: 8px; padding: 0 12px; border-radius: 999px; background: var(--subtle); color: var(--secondary); font-size: 13px; font-weight: 500; white-space: nowrap; }
.ts-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.ts-pill.tone-good { background: #DCFCE7; color: #166534; }
.ts-pill.tone-warn { background: #FEF3C7; color: var(--warn-text, #7A5900); }
.ts-pill.tone-bad { background: #FEE2E2; color: #991B1B; }
.ts-pill.tone-info { background: #DBEAFE; color: #1D4ED8; }
.ts-image { display: flex; align-items: flex-start; gap: 8px; min-width: 0; margin-top: -4px; font-size: 12px; line-height: 16px; color: var(--muted); }
.ts-image-label { flex: none; padding-top: 8px; font-weight: 500; color: var(--secondary); }
.ts-image code { flex: 1 1 auto; min-width: 0; padding-top: 8px; font-family: var(--mono); font-size: 12px; color: var(--secondary); overflow-wrap: anywhere; word-break: break-all; }
.ts-image .ui-icon-button { flex: none; width: 32px; height: 32px; min-height: 32px; padding: 0; border: 0; background: transparent; color: var(--secondary); }
.ts-image .ui-icon-button:hover { background: var(--subtle); }

/* Toolbar */
.ts-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--page); }
.ts-toolbar > .ts-field { flex: 0 1 180px; min-width: 150px; }
.ts-toolbar > .ts-search { flex: 1 1 220px; }
.ts-search-box { position: relative; display: flex; align-items: center; }
.ts-search-box svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.ts-search-box input { width: 100%; padding-left: 32px; }
.ts-toolbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.ts-toolbar-actions > button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h); min-height: var(--control-h); padding: 0 16px; border-color: var(--field-border); background: var(--card); color: var(--text); }
.ts-toolbar-actions > .ui-icon-button { width: var(--control-h); padding: 0; justify-content: center; }
.ts-toolbar-actions > button:hover:not(:disabled) { background: var(--subtle); }
.ts-follow[aria-pressed="true"] { border-color: #86C99C; background: #E8F7EE; color: #14532D; font-weight: 600; }
.ts-toolbar-actions > .ts-follow[aria-pressed="true"]:hover { background: #D7F0E0; }

/* Log */
.ts-body { min-width: 0; }
.ts-body[aria-busy="true"] { min-height: 160px; }
.ts-log-wrap { position: relative; }
.ts-log { height: clamp(320px, calc(100vh - 300px), 1100px); overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--card); font-family: var(--mono); font-size: 13px; line-height: 20px; overscroll-behavior: contain; }
.ts-log:focus-visible { outline: 2px solid var(--focus, var(--action)); outline-offset: 2px; }
.ts-log > .ui-state { margin: 16px; font-family: Inter, system-ui, sans-serif; }
.ts-line { display: grid; grid-template-columns: 104px 64px minmax(0, 1fr); gap: 0 12px; padding: 4px 16px; border-bottom: 1px solid oklch(0.95 0.005 60); }
.ts-line:last-child { border-bottom: 0; }
.ts-ts { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ts-lvl { font-weight: 600; color: var(--secondary); text-transform: lowercase; }
.ts-msg { min-width: 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.ts-line.lvl-error { background: #FEF2F2; }
.ts-line.lvl-error .ts-lvl { color: #B91C1C; }
.ts-line.lvl-warn { background: #FFFBEB; }
.ts-line.lvl-warn .ts-lvl { color: var(--warn-text, #7A5900); }
.ts-line.lvl-info .ts-lvl { color: #166534; }
.ts-line.lvl-debug .ts-lvl { color: #5B21B6; }
.ts-day { position: sticky; top: 0; z-index: 1; padding: 4px 16px; border-bottom: 1px solid var(--border); background: var(--subtle); font-family: Inter, system-ui, sans-serif; font-size: 12px; font-weight: 600; color: var(--secondary); }
.ts-hit { padding: 0 1px; border-radius: 2px; background: #FDE68A; color: inherit; }
.ts-jump { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 8px; height: 36px; min-height: 36px; padding: 0 16px; border: 1px solid var(--field-border); border-radius: 999px; background: var(--card); color: var(--text); font-size: 13px; }
.ts-jump:hover { background: var(--subtle); }
.ts-foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; font-size: 12px; line-height: 16px; color: var(--muted); }
.ts-foot:empty { display: none; }
.ts-follow-status { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--secondary); }
.ts-foot .ts-note { flex: 1 1 100%; font-size: 12px; }
.ts-error:empty { display: none; }
.ts-error-line { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 8px 12px; border: 1px solid #FECACA; border-radius: 8px; background: #FEF2F2; color: #991B1B; font-size: 13px; line-height: 20px; }
.ts-error-line svg { flex: none; margin-top: 1px; }

/* Code blocks: configuration, ETL output, Kafka event bodies */
.ts-code { max-height: 520px; margin: 0; padding: 12px 16px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--page); font-family: var(--mono); font-size: 13px; line-height: 20px; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.ts-code:focus-visible { outline: 2px solid var(--focus, var(--action)); outline-offset: 2px; }

/* ETL */
.ts-etl { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 24px; margin: 0 0 12px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.ts-etl dt { font-size: 12px; font-weight: 500; color: var(--muted); }
.ts-etl dd { margin: 0; font-size: 14px; color: var(--text); }
.ts-etl-output { max-height: clamp(280px, calc(100vh - 420px), 900px); }

/* Configuration */
.ts-body > .ts-config-editor, .ts-body > .ts-config-full { display: flex; flex-direction: column; gap: 12px; }
.ts-config-full { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.ts-config-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.ts-config-head .text-button { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; margin-left: auto; padding: 0; font-size: 13px; }
.ts-subtitle { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; color: var(--text); }
.ts-config-status { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--page); font-size: 13px; color: var(--text); }
.ts-config-rows { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.ts-config-row { display: grid; grid-template-columns: minmax(0, 1fr) 220px auto; align-items: center; gap: 8px 16px; padding: 12px 16px; border-top: 1px solid var(--border); }
.ts-config-row:first-child { border-top: 0; }
.ts-config-about { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ts-config-key { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.ts-config-value input, .ts-config-value select { width: 100%; }
.ts-config-row .text-button { min-height: 36px; padding: 0 4px; font-size: 13px; }
.ts-config-summary { margin: 0; font-size: 13px; color: var(--text); }
.ts-config-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ts-config-actions > button:not(.text-button) { height: var(--control-h); min-height: var(--control-h); padding: 0 16px; }
.ts-config-actions > .secondary { border-color: var(--field-border); background: var(--card); color: var(--text); }
.ts-config-actions > .secondary:hover:not(:disabled) { background: var(--subtle); }
.ts-config-actions > .text-button { font-size: 13px; }

/* Terminal */
.ts-terminal-note { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.ts-more > summary { cursor: pointer; font-size: 13px; font-weight: 500; color: var(--secondary); border-radius: 4px; }
.ts-more > summary:hover { color: var(--text); }
.ts-more > summary:focus-visible { outline: 2px solid var(--focus, var(--action)); outline-offset: 2px; }
.ts-more[open] { flex: 1 1 100%; }
.ts-more[open] > summary { margin-bottom: 4px; }
.ts-terminal-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.ts-terminal-controls > button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h); min-height: var(--control-h); padding: 0 16px; }
.ts-terminal-controls > .secondary { border-color: var(--field-border); background: var(--card); color: var(--text); }
.ts-terminal-controls > .secondary:hover { background: var(--subtle); }
.ts-terminal { display: flex; flex-direction: column; overflow: hidden; border: 1px solid #1F2937; border-radius: 12px; background: #111827; }
.ts-terminal-output { height: clamp(260px, calc(100vh - 420px), 900px); margin: 0; padding: 12px 16px; overflow: auto; font-family: var(--mono); font-size: 13px; line-height: 20px; color: #E5E7EB; white-space: pre-wrap; overflow-wrap: anywhere; }
.ts-terminal-output:focus-visible { outline: 2px solid #FDBA74; outline-offset: -2px; }
.ts-prompt { display: flex; align-items: flex-start; gap: 8px; padding: 8px 8px 8px 16px; border-top: 1px solid #374151; background: #0B1220; }
.ts-prompt-sign { padding-top: 8px; font-family: var(--mono); font-size: 13px; font-weight: 600; color: #FDBA74; }
.ts-prompt textarea { flex: 1 1 auto; min-height: 36px; height: 36px; padding: 8px 0; border: 0; background: transparent; color: #F9FAFB; font-family: var(--mono); font-size: 13px; line-height: 20px; resize: none; outline: none; }
.ts-prompt textarea::placeholder { color: #9CA3AF; }
.ts-prompt:focus-within { box-shadow: inset 0 0 0 2px #FDBA74; }
.ts-prompt.off { opacity: .55; }
.ts-send { display: grid; place-items: center; flex: none; width: 36px; height: 36px; min-height: 36px; padding: 0; border: 1px solid #4B5563; border-radius: 8px; background: #1F2937; color: #F9FAFB; }
.ts-send:hover:not(:disabled) { background: #374151; }
.ts-send:focus-visible { outline: 2px solid #FDBA74; outline-offset: 2px; }

/* Kafka events */
.ts-events { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; background: var(--card); overflow: hidden; }
.ts-events > .ui-state { margin: 12px; }
.ts-event { border-top: 1px solid var(--border); }
.ts-event:first-child { border-top: 0; }
.ts-event > summary { display: grid; grid-template-columns: 16px 150px 190px minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; min-height: 40px; padding: 8px 16px; cursor: pointer; list-style: none; font-size: 13px; color: var(--text); }
.ts-event > summary::-webkit-details-marker { display: none; }
.ts-event > summary:hover { background: var(--page); }
.ts-event > summary:focus-visible { outline: 2px solid var(--focus, var(--action)); outline-offset: -2px; }
.ts-event > summary svg { color: var(--muted); transition: transform 150ms; }
.ts-event[open] > summary svg { transform: rotate(90deg); }
.ts-event-where { color: var(--secondary); font-variant-numeric: tabular-nums; }
.ts-event-key { min-width: 0; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.ts-event-type { justify-self: end; padding: 0 8px; border-radius: 999px; background: var(--subtle); font-size: 12px; font-weight: 500; color: var(--secondary); }
.ts-event-type:empty { display: none; }
.ts-event > .ts-code { margin: 0 16px 12px; max-height: 360px; }

/* Settings */
.ts-settings { display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.ts-settings-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.ts-settings-row > button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h); min-height: var(--control-h); padding: 0 24px; }
.ts-saved { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: #166534; }
.ts-saved:empty { display: none; }

@media (max-width: 1100px) {
  .ts-layout { grid-template-columns: 168px minmax(0, 1fr); }
  .ts-rail { padding: 16px 8px; }
  .ts-tool { padding: 16px 24px 24px; }
  .ts-config-row { grid-template-columns: minmax(0, 1fr) 180px; }
  .ts-config-row .text-button { grid-column: 2; justify-self: end; }
}
@media (max-width: 700px) {
  .ts-layout { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .ts-rail { display: none; }
  .ts-phone-pick { display: block; padding: 16px 16px 0; }
  .ts-tool { padding: 12px 16px 16px; }

  .ts-restart { margin-left: 0; align-items: flex-start; }
  .ts-restart .container-restart-status { text-align: left; }
  .ts-toolbar { padding: 12px; }
  .ts-toolbar > .ts-field { flex: 1 1 140px; min-width: 0; }
  .ts-toolbar > .ts-search { flex: 1 1 100%; }
  .ts-toolbar-actions { flex: 1 1 100%; margin-left: 0; }
  .ts-toolbar-actions > .ts-follow, .ts-toolbar-actions > #ts-expand { flex: 1 1 auto; justify-content: center; }
  .ts-log { height: clamp(320px, calc(100vh - 260px), 900px); }
  .ts-line { grid-template-columns: auto minmax(0, 1fr); padding: 8px 12px; }
  .ts-line .ts-msg { grid-column: 1 / -1; }
  .ts-event > summary { grid-template-columns: 16px minmax(0, 1fr); }
  .ts-event > summary > :nth-child(n+3) { grid-column: 2; justify-self: start; }
  .ts-config-row { grid-template-columns: minmax(0, 1fr); }
  .ts-config-row .text-button { grid-column: auto; justify-self: start; }
}

.service-version-table{width:100%;border-collapse:collapse;font-size:.9rem}.service-version-table th,.service-version-table td{padding:.65rem;border-bottom:1px solid var(--border,#ded8d1);text-align:left;vertical-align:top}.service-version-table button{padding:.4rem .7rem;margin:0 .35rem .35rem 0;font-size:.85rem}.tool-versions .ts-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:.65rem}.tool-versions select{max-width:100%}
/* Keep service search and pagination on one desktop row; wrap on narrow screens. */
.ts-version-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin:12px 0 18px}
.ts-version-toolbar input[type=search]{flex:1 1 190px;width:auto;min-width:120px}
.ts-version-toolbar select{width:80px;flex:0 0 80px}
.ts-version-toolbar button,.ts-version-toolbar span{white-space:nowrap}
.service-version-table td:last-child button{margin:0 8px 6px 0}
.service-version-table td:last-child .ts-help{display:block;max-width:28em}
/* Keep pagination and long image references from changing column geometry. */
.service-version-table{table-layout:fixed;min-width:720px}
.service-version-table th,.service-version-table td{white-space:normal;overflow-wrap:anywhere}
.service-version-table th:nth-child(1){width:10%}
.service-version-table th:nth-child(2),.service-version-table th:nth-child(3){width:30%}
.service-version-table th:nth-child(4){width:12%}
.service-version-table th:nth-child(5){width:18%}
.service-version-table button{max-width:100%;white-space:normal;overflow-wrap:anywhere}
.ts-version-editor{border:1px solid var(--line,#ded8d1);border-radius:12px;padding:18px;margin:18px 0;display:grid;gap:12px}
.ts-version-editor h4,.ts-version-editor p{margin:0}
.ts-version-editor button{justify-self:start}
.ts-version-editor select{min-width:0;max-width:100%}
.ts-version-package{margin:0;padding-left:20px;overflow-wrap:anywhere}
.ts-update-status{border:1px solid var(--line,#ded8d1);border-left:4px solid var(--accent,#b84b00);border-radius:12px;background:var(--surface,#fff);padding:20px;margin:20px 0;display:grid;gap:12px}
.ts-update-status h3,.ts-update-status p{margin:0}.ts-update-status button{justify-self:start}
.ts-update-error{color:var(--danger,#a32820);overflow-wrap:anywhere}
.ts-update-steps{display:flex;flex-wrap:wrap;gap:8px 20px;list-style:none;padding:0;margin:4px 0;color:var(--muted,#626b7b)}
.ts-update-steps .current{color:var(--accent,#b84b00);font-weight:700;text-decoration:underline;text-underline-offset:5px}
.ts-update-changes{margin:0;padding-left:20px}.ts-installed{margin:24px 0}.ts-installed>summary{font-weight:600;cursor:pointer;margin-bottom:12px}
.ts-installed .service-version-table th:nth-child(1){width:18%}.ts-installed .service-version-table th:nth-child(2),.ts-installed .service-version-table th:nth-child(3){width:32%}.ts-installed .service-version-table th:nth-child(4){width:18%}

.ts-update-status.is-ready{border-left-color:var(--success,#16814b)}.ts-update-status.needs-attention{border-left-color:var(--danger,#a32820)}

.ts-installed-updates{border:1px solid var(--line,#ded8d1);border-radius:12px;padding:20px;margin:20px 0;background:var(--surface,#fff)}
.ts-installed-updates h3{margin:0 0 14px}.ts-installed-update{display:grid;gap:10px;margin:16px 0}.ts-installed-update h4,.ts-installed-update p{margin:0}
.ts-update-badge{display:inline-block;justify-self:start;border-radius:20px;padding:4px 12px;background:#dcfce7;color:#166534;font-weight:600;font-size:.85rem}.ts-update-badge.uncertain{background:#fff3cd;color:#805500}

/* Give long package labels room without widening the page on phones. */
.provisioning-log-toolbar > .ts-field { flex: 1 1 320px; min-width: 0; }
