/*
 * Gate portal: Service desk, Operations and Administration pages (console/pages/tickets.js, clients.js,
 * patching.js, software.js, deployment.js, roles.js, billing.js, integrations.js) and the tenant banner. Shared tokens
 * (kit/tokens.css) only; the shared components live in kit/kit.css and console/console.css.
 */

/* ========== Shared ========== */
.cx .cx-ops-gap { margin-bottom: 16px; }
.cx .cx-mt-sm { margin-top: 8px; }
.cx .cx-panel-pad { padding: 12px 16px; }
.cx-panel-body.is-flush .cx-gridwrap.is-embedded { border-top: 1px solid var(--c-line); border-bottom: 1px solid var(--c-line); }
.cx-panel-body.is-flush > .cx-totals { margin: 12px 16px 14px auto; }
.cx-ops-bad { color: var(--c-bad); }
.cx-ops-h2 { font-size: var(--t-16); line-height: 22px; }
.cx-flip .cx-icon { transform: rotate(180deg); }
.cx-code-row { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.cx-code-row .cx-secret, .cx-code-row .cx-input { flex: 1; min-width: 0; white-space: pre-wrap; }
.cx-code-row .cx-input { height: 30px; }
.cx-code-row .cx-btn { flex: 0 0 auto; }
.cx-progress { display: grid; gap: 2px; min-width: 150px; }
.cx-progress .cx-meter { min-width: 0; }
.cx-progress .cx-meter-text { display: none; }
.cx-table td .cx-avatar { width: 26px; height: 26px; font-size: 10px; }
.cx-pagehead-actions .cx-month-picker { flex-wrap: nowrap; }
.cx-month-picker .cx-input { width: 150px; }
.cx-panel-body > .cx-gridwrap { min-width: 0; }

/* Vertical facts list for side panels (ticket properties): label beside the value. */
.cx-sidefacts { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px 12px; align-items: center; margin: 0; }
.cx-sidefacts dt { color: var(--c-text-2); font-size: var(--t-13); font-weight: 500; }
.cx-sidefacts dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.cx-sidefacts .cx-select { width: 100%; }

/* Two-column detail pages (ticket). */
.cx-ops-cols { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.cx-ops-main, .cx-ops-side { display: grid; gap: 16px; min-width: 0; }
.cx-ops-side { position: sticky; top: 68px; }

/* ========== Ticket conversation ========== */
.cx-thread { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.cx-msg { position: relative; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; align-items: start; }
.cx-msg:not(:last-child)::before { content: ""; position: absolute; top: 34px; bottom: -12px; left: 14.5px; width: 1px; background: var(--c-line); }
.cx-msg-avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--c-muted-bg); color: var(--c-text-2); font-size: var(--t-13); font-weight: 700; }
.cx-msg.is-staff .cx-msg-avatar { background: var(--c-accent-soft); color: var(--c-accent); }
.cx-msg.is-note .cx-msg-avatar { background: var(--c-warn-bg); color: var(--c-warn); }
.cx-msg-card { min-width: 0; padding: 10px 14px 12px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); }
.cx-msg.is-note .cx-msg-card { border-color: #ecd28f; border-left: 3px solid var(--c-warn); background: var(--c-warn-bg); }
.cx-msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 4px; }
.cx-msg-head strong { font-weight: 600; }
.cx-msg-kind { color: var(--c-text-3); font-size: var(--t-13); }
.cx-msg.is-note .cx-msg-kind { color: var(--c-warn); font-weight: 600; }
.cx-msg-time { margin-left: auto; color: var(--c-text-3); font-size: var(--t-13); white-space: nowrap; }
.cx-msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.cx-thread-empty { padding: 20px; border: 1px dashed var(--c-line-2); border-radius: var(--r-md); color: var(--c-text-2); text-align: center; }
.cx-composer { display: grid; border-top: 1px solid var(--c-line); background: var(--c-surface-2); border-radius: 0 0 var(--r-md) var(--r-md); }
.cx-composer .cx-composer-input { width: 100%; min-height: 96px; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--c-line); border-radius: 0; background: var(--c-surface); }
.cx-composer .cx-composer-input:focus { box-shadow: inset 0 0 0 2px var(--c-accent-soft); }
.cx-composer.is-private .cx-composer-input { background: var(--c-warn-bg); }
.cx-composer-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 16px; }
.cx-composer-options { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.cx-composer-options .cx-check-row { align-items: center; font-weight: 500; }
.cx-composer-options .cx-check-row input { margin-top: 0; }
.cx-composer .cx-form-error { padding: 0 16px 10px; }

/* ========== AI investigation ========== */
details.cx-ai > summary { list-style: none; cursor: pointer; }
details.cx-ai > summary::-webkit-details-marker { display: none; }
details.cx-ai:not([open]) > summary { border-bottom: 0; }
.cx-ai-summary .cx-ai-chevron { color: var(--c-text-3); transition: transform .12s ease; }
details.cx-ai[open] .cx-ai-chevron { transform: rotate(90deg); }
.cx-ai-hint { margin-left: auto; padding-right: 8px; font-size: var(--t-13); }
.cx-ai-body { display: grid; gap: 16px; }
.cx-ai-form { display: grid; gap: 8px; }
.cx-ai-form .cx-textarea { width: 100%; min-height: 72px; }
.cx-ai-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.cx-ai-foot .cx-field-help { flex: 1; min-width: 220px; }
.cx-ai-list { display: grid; gap: 12px; }
.cx-ai-inv { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface-2); }
.cx-ai-inv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.cx-ai-prompt { flex: 1; min-width: 180px; overflow-wrap: anywhere; }
.cx-ai-report summary { color: var(--c-text-2); font-size: var(--t-13); font-weight: 600; cursor: pointer; }
.cx-ai-report[open] summary { margin-bottom: 6px; }
.cx-ai-report-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.cx-ai-proposal { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); }
.cx-ai-proposal-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px; }
.cx-ai-rationale { color: var(--c-text-2); overflow-wrap: anywhere; }
.cx-ai-proposal .cx-sidefacts { grid-template-columns: 84px minmax(0, 1fr); }
.cx-ai-exec { display: grid; gap: 6px; }
.cx-ai-exec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: var(--t-13); }
.cx-ai-exec .cx-pre { max-height: 220px; }

/* ========== Checklists, segmented filters, steps ========== */
.cx-checklist { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.cx-checklist legend { margin-bottom: 4px; padding: 0; color: var(--c-text-2); font-size: var(--t-13); font-weight: 600; }
.cx-checklist .cx-checklist-filter { width: 100%; }
.cx-checklist-items { display: grid; gap: 2px; max-height: 220px; overflow-y: auto; padding: 6px 8px; border: 1px solid var(--c-line); border-radius: var(--r-sm); background: var(--c-surface); }
.cx-checklist.is-tall .cx-checklist-items { max-height: 320px; }
.cx-checklist-items .cx-check-row { padding: 4px 2px; }
.cx-checklist-items .cx-check-row[hidden] { display: none; }
.cx-check-text { display: grid; min-width: 0; }
.cx-check-text small { color: var(--c-text-3); font-size: var(--t-13); overflow-wrap: anywhere; }
.cx-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--c-line-2); border-radius: var(--r-sm); background: var(--c-surface); overflow: hidden; }
.cx a.cx-seg-item, .cx-seg-item { padding: 0 12px; line-height: 28px; border-right: 1px solid var(--c-line); color: var(--c-text-2); font-size: var(--t-13); font-weight: 500; text-decoration: none; white-space: nowrap; }
.cx-seg-item:last-child { border-right: 0; }
.cx a.cx-seg-item:hover { background: var(--c-surface-2); color: var(--c-text); text-decoration: none; }
.cx a.cx-seg-item.is-on { background: var(--c-accent-soft); color: var(--c-accent); font-weight: 600; }
.cx-steps { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0 0 16px; padding: 0 0 10px; border-bottom: 1px solid var(--c-line); list-style: none; color: var(--c-text-3); font-size: var(--t-13); }
.cx-steps li.is-on { color: var(--c-text); font-weight: 600; }
.cx-steps li.is-done { color: var(--c-ok); }

/* ========== Patch policy editor ========== */
.cx-policy-editor { display: grid; gap: 16px; }
.cx-policy-editor .cx-input, .cx-policy-editor .cx-select { width: 100%; }
.cx-policy-editor .cx-section-title { gap: 8px; }
.cx-rule-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) minmax(0, 1fr) 32px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--c-line); }
.cx-rule-row:last-child { border-bottom: 0; }
.cx-ring-card { margin-bottom: 12px; }
.cx-windows { display: grid; gap: 8px; }
.cx-window-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 10px; border: 1px solid var(--c-line); border-radius: var(--r-sm); background: var(--c-surface-2); }
.cx-days { display: flex; flex-wrap: wrap; gap: 4px; }
.cx-day { position: relative; cursor: pointer; }
.cx-day input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cx-day span { display: inline-block; min-width: 38px; padding: 0 6px; border: 1px solid var(--c-line-2); border-radius: 13px; background: var(--c-surface); color: var(--c-text-2); font-size: var(--t-13); line-height: 24px; text-align: center; }
.cx-day input:checked + span { border-color: #b9cdf3; background: var(--c-accent-soft); color: var(--c-accent); font-weight: 600; }
.cx-day input:focus-visible + span { box-shadow: var(--focus); }
.cx-policy-editor .cx-input.cx-time { width: 110px; }
.cx-window-row > .cx-iconbtn { margin-left: auto; }
.cx-policy-foot { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border: 1px solid var(--c-line); border-radius: var(--r-md); background: var(--c-surface); box-shadow: 0 -4px 12px rgba(16,24,40,.06); }
.cx-policy-foot > div:first-child { flex: 1; min-width: 0; }

/* ========== Users and roles ========== */
.cx-role-options { display: grid; gap: 6px; }
.cx-role-option { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 4px 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--c-line); border-radius: var(--r-sm); cursor: pointer; }
.cx-role-option:hover { background: var(--c-surface-2); }
.cx-role-option:has(input:checked) { border-color: #b9cdf3; background: var(--c-accent-soft); }
.cx-role-option input { margin-top: 2px; accent-color: var(--c-accent); }
.cx-role-option-text { display: grid; gap: 2px; min-width: 0; }
.cx-role-option-text small { color: var(--c-text-2); font-size: var(--t-13); }
.cx-role-option-meta { color: var(--c-text-3); font-size: var(--t-13); white-space: nowrap; }
.cx-matrix-scroll { max-height: 70vh; }
.cx-matrix th.cx-matrix-role { min-width: 92px; white-space: normal; line-height: 1.25; text-align: center; vertical-align: bottom; padding-top: 6px; padding-bottom: 6px; height: auto; }
.cx-matrix .cx-matrix-perm { position: sticky; left: 0; z-index: 1; background: var(--c-surface); }
.cx-matrix th.cx-matrix-perm { z-index: 2; background: var(--c-surface-2); }
.cx-matrix td { height: 32px; }
.cx-matrix .cx-matrix-cell { text-align: center; }
.cx-matrix .cx-matrix-yes { color: var(--c-ok); stroke-width: 2.4; }
.cx-matrix tr.cx-matrix-group td { height: 30px; background: var(--c-muted-bg); color: var(--c-text-2); font-size: var(--t-13); font-weight: 600; }
.cx-matrix tbody tr:hover td.cx-matrix-perm { background: #f6f9fe; }

/* ========== Billing ========== */
.cx-totals { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 24px; width: min(420px, 100%); margin: 12px 0 0 auto; }
.cx-totals dt { color: var(--c-text-2); text-align: right; }
.cx-totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.cx-totals .is-total { padding-top: 6px; border-top: 1px solid var(--c-line); color: var(--c-text); font-weight: 600; }

/* ========== Tenant banner ========== */
.cx-tenant-banner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.cx-tenant-banner-result { color: var(--c-text-2); font-size: var(--t-13); }

/* ========== Responsive ========== */
@media (max-width: 1100px) {
  .cx-ops-cols { grid-template-columns: minmax(0, 1fr); }
  .cx-ops-side { position: static; }
}
@media (max-width: 760px) {
  .cx-rule-row { grid-template-columns: minmax(0, 1fr) 32px; }
  .cx-rule-row > .cx-select { grid-column: 1; }
  .cx-rule-row > .cx-iconbtn { grid-column: 2; grid-row: 1; }
  .cx-role-option { grid-template-columns: 18px minmax(0, 1fr); }
  .cx-role-option-meta { grid-column: 2; white-space: normal; }
  .cx-msg-time { margin-left: 0; }
}
@media (max-width: 560px) {
  .cx-ops-panel > .cx-panel-head { flex-wrap: wrap; row-gap: 2px; padding-top: 8px; padding-bottom: 8px; }
  .cx-ops-panel > .cx-panel-head .cx-panel-sub { order: 3; flex-basis: 100%; }
  .cx-pagehead-actions .cx-month-picker .cx-input { width: 140px; }
  .cx-sidefacts { grid-template-columns: 84px minmax(0, 1fr); }
  .cx-code-row { flex-direction: column; align-items: stretch; }
  .cx-seg { width: 100%; }
}
