/* Rail */
.rail {
  background: var(--rail);
  color: var(--rail-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
@media (max-width: 900px) { .rail { position: static; height: auto; } }

.brand { display: flex; align-items: center; gap: 10px; color: inherit; padding: 2px 8px; --logo-bg: #ffffff; --logo-ink: #0b4f52; --logo-accent: #0e6366; }
.brand:hover { text-decoration: none; }
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-name span { font-weight: 400; opacity: 0.85; }

/* Navigation: named groups of links. The dashboards list is the one that grows, so it is the one that scrolls;
   the open dashboard's row runs flush into the page, like a tab. */
.rail-nav { display: flex; flex-direction: column; gap: 8px; flex: none; }
.rail-nav-dashboards { flex: 0 1 auto; min-height: 0; }
.rail-heading { display: flex; align-items: center; justify-content: space-between; min-height: 28px; padding: 0 4px 0 10px; }
.rail-title { color: var(--rail-ink-2); font-weight: 500; }
a.rail-title:hover { text-decoration: none; color: var(--rail-ink); }
.rail-title.active { color: var(--rail-ink); }
.rail-add { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: var(--radius); color: var(--rail-ink-2); }
.rail-add:hover { background: var(--rail-hover); color: var(--rail-ink); text-decoration: none; }
.rail-filter { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: var(--radius); background: rgba(0, 0, 0, 0.18); color: var(--rail-ink-2); }
.rail-filter:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.rail-filter svg { flex-shrink: 0; }
.rail-filter input[type="search"] { flex: 1; min-width: 0; padding: 7px 0; border: 0; border-radius: 0; background: transparent; color: var(--rail-ink); outline: none; -webkit-appearance: none; appearance: none; }
.rail-filter input[type="search"]::-webkit-search-cancel-button { filter: invert(1); }
.rail-filter input::placeholder { color: var(--rail-ink-2); opacity: 1; }
.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.rail-list-scroll { min-height: 108px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--rail-ink-2) transparent; margin-right: -14px; padding-right: 14px; }
.rail-link { display: block; padding: 7px 10px; border-radius: var(--radius); color: var(--rail-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-link:hover { background: var(--rail-hover); text-decoration: none; }
.rail-link.active { margin-right: -14px; padding-right: 24px; border-radius: var(--radius) 0 0 var(--radius); background: var(--plane); color: var(--ink); font-weight: 500; }
.rail-link.active:focus-visible { outline-offset: -2px; }
.rail-empty { padding: 7px 10px; color: var(--rail-ink-2); }

/* The account at the rail's foot; its menu opens upward with the admin pages and signing out. */
.account { position: relative; flex: none; margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.account-toggle { list-style: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; }
.account-toggle::-webkit-details-marker { display: none; }
.account-toggle:hover, .account[open] .account-toggle { background: var(--rail-hover); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--rail-active); display: inline-flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 700; }
.account-toggle.active .avatar { background: var(--rail-ink); color: var(--rail); }
.account-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.account-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-role { color: var(--rail-ink-2); font-size: 0.85rem; }
.account-chevron { display: inline-flex; color: var(--rail-ink-2); transform: rotate(-90deg); }
.account[open] .account-chevron { transform: rotate(90deg); }
.account-menu { position: absolute; left: 0; right: 0; bottom: calc(100% + 4px); z-index: 30; padding: 4px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18); }
.account-links { list-style: none; margin: 0 0 4px; padding: 0 0 4px; border-bottom: 1px solid var(--line); }
.menu-link { display: block; padding: 6px 10px; border-radius: var(--radius); color: var(--ink); }
.menu-link:hover { background: var(--surface-2); text-decoration: none; }
.menu-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.account-signout { display: block; width: 100%; padding: 6px 10px; border: 0; border-radius: var(--radius); background: none; color: var(--ink-2); text-align: left; cursor: pointer; }
.account-signout:hover { background: var(--surface-2); color: var(--ink); }

/* Page header and text */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-head .lede { margin-top: 6px; color: var(--ink-2); max-width: 60ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
@media (max-width: 700px) { .page-head { flex-direction: column; } .page-head .actions { justify-content: flex-start; } }

.lede a { text-decoration: underline; text-decoration-color: var(--line-strong); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.3; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-small { padding: 4px 10px; font-size: 0.9rem; }
select.select-small { padding: 3px 8px; font-size: 0.9rem; width: auto; }
.btn-large { padding: 11px 18px; font-size: 1.05rem; width: 100%; }

/* Flash */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 18px; border: 1px solid var(--line); background: var(--surface); }
.flash-notice { border-color: var(--accent); background: var(--accent-soft); }
.flash-alert { border-color: var(--danger); background: var(--danger-soft); }

/* Toolbar: the single filter row above the panels */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 16px; margin-bottom: 22px; }
.toolbar-form { display: contents; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.segmented > button, .segmented > label {
  padding: 6px 12px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; font-weight: 500;
  border-right: 1px solid var(--line);
}
.segmented > button:last-child, .segmented > label:last-child { border-right: 0; }
.segmented > button:hover, .segmented > label:hover { background: var(--surface-2); }
.segmented > button.active, .segmented > input:checked + label { background: var(--accent-soft); color: var(--accent); }
.segmented > button:focus-visible, .segmented > input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: -2px; }
.segmented-radio > input { position: absolute; opacity: 0; width: 0; height: 0; }

.toolbar-custom { position: relative; }
.toolbar-custom summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink-2); font-weight: 500; }
.toolbar-custom summary::-webkit-details-marker { display: none; }
.toolbar-custom summary.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.toolbar-custom-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.toolbar-custom-fields label { color: var(--ink-2); }
.toolbar-interval { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); margin-left: auto; order: 3; }
.toolbar-custom { order: 2; }

input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
  padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); min-width: 0;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }

.search { display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink-3); min-width: 280px; }
.search input { border: 0; padding: 7px 0; flex: 1; background: transparent; }
.search input:focus-visible { outline: none; }
.search:focus-within { outline: 2px solid var(--focus); }

/* Panel grid */
.panel-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.panel { grid-column: span var(--span, 6); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 320px; }
@media (max-width: 1200px) { .panel { grid-column: span max(var(--span, 6), 6); } }
@media (max-width: 800px) { .panel { grid-column: span 12; } }

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; }
.panel-title { font-size: 1.05rem; font-weight: 700; }
.panel-selector { color: var(--ink-3); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.panel-edit { color: var(--ink-3); font-size: 0.9rem; flex-shrink: 0; }
.panel-edit:hover { color: var(--accent); }

.panel-body { position: relative; flex: 1; min-height: 220px; padding: 6px 12px 4px; }
.panel-body canvas { width: 100% !important; height: 100% !important; }
.panel-body.is-failed canvas { display: none; }
.panel-empty:not([hidden]), .panel-error:not([hidden]) { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--ink-3); }
.panel-error { color: var(--danger); }

.panel-foot { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 16px 12px; color: var(--ink-3); font-size: 0.85rem; }
.panel-toggle { background: none; border: 0; padding: 0; color: var(--ink-3); cursor: pointer; font-size: inherit; white-space: nowrap; flex-shrink: 0; }
.panel-toggle:hover, .panel-toggle[aria-pressed="true"] { color: var(--accent); }

/* Table twin of the chart, shown in place of the chart inside the panel body. */
.panel-body.is-table canvas, .panel-body.is-table .stat { display: none !important; } /* Chart.js sets display inline */
.panel-table { position: absolute; inset: 6px 12px 4px; overflow: auto; background: var(--surface); }
.panel-table table { width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; border-collapse: separate; border-spacing: 0; }
.panel-table th, .panel-table td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 400; }
.panel-table thead th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 500; z-index: 1; }
.panel-table th:first-child, .panel-table td:first-child { text-align: left; color: var(--ink-2); position: sticky; left: 0; background: var(--surface); }
.panel-table thead th:first-child { z-index: 2; }
.panel-table tbody tr:hover td, .panel-table tbody tr:hover th { background: var(--surface-2); }

/* Number panel */
.panel-stat { min-height: 200px; }
.stat { display: grid; grid-template-rows: auto auto 1fr; height: 100%; padding: 4px 4px 0; }
.stat-value { font-size: 2.75rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat-delta { color: var(--ink-3); min-height: 1.5em; }
.stat-delta[data-direction="up"] { color: var(--good); }
.stat-delta[data-direction="down"] { color: var(--danger); }
.stat-spark { max-height: 72px; margin-top: 8px; }

/* Empty states */
.empty { max-width: 56ch; padding: 40px 0; }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--ink-2); margin-bottom: 18px; }

/* Cards (dashboard list) */
.card-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.card-title { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.card-text { color: var(--ink-2); }
.card-meta { color: var(--ink-3); font-size: 0.9rem; margin-top: auto; }

/* Forms */
.form-column { max-width: 560px; display: flex; flex-direction: column; gap: 32px; }
.form-column-wide { max-width: 760px; }
.form { display: flex; flex-direction: column; gap: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.form-row { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
.form-intro { flex-basis: 100%; display: flex; flex-direction: column; gap: 4px; } /* heading and hint above a row of fields */
.form-intro h3 { font-size: 1rem; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-narrow { max-width: 200px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }
.field label, .field legend { font-weight: 500; }
.field legend { margin-bottom: 6px; padding: 0; }
.field-inline { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.hint { color: var(--ink-3); font-size: 0.9rem; }
.hint a { text-decoration: underline; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice span { display: flex; flex-direction: column; }
.choice small { color: var(--ink-2); }
.form-actions { display: flex; gap: 8px; align-items: center; }
.form-errors { border: 1px solid var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 10px 14px; }
.form-errors ul { margin: 4px 0 0; padding-left: 18px; }
.inline-form { display: inline-flex; }

.danger-zone { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.danger-zone p { color: var(--ink-2); }

/* Selector preview in the panel form */
.preview { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); max-height: 240px; overflow: auto; }
.preview.is-invalid { border-color: var(--danger); }
.preview-status { color: var(--ink-2); }
.preview.is-invalid .preview-status { color: var(--danger); }
.preview-keys { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.preview-keys li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.preview-keys code { background: transparent; border: 0; padding: 0; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.type-badge { color: var(--ink-3); font-size: 0.85rem; flex-shrink: 0; }

/* Tables */
.table { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-weight: 500; color: var(--ink-2); background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td > span.muted { display: block; font-size: 0.9rem; } /* secondary line under a name, e.g. an email address */
.table td.muted { color: var(--ink-3); }
.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions form { display: inline; }
.result-count { margin-bottom: 10px; }
.key-cell { font-weight: 500; white-space: nowrap; } /* one line per metric; the table scrolls sideways when needed */
.key-cell .dot { color: var(--ink-3); padding: 0 1px; }

.menu { position: relative; display: inline-block; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu ul { position: absolute; right: 0; top: calc(100% + 4px); z-index: 2; list-style: none; margin: 0; padding: 4px; min-width: 200px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); text-align: left; }
.menu li a { display: block; padding: 6px 10px; border-radius: 4px; color: var(--ink); }
.menu li a:hover { background: var(--surface-2); text-decoration: none; }

.role-legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 0; }
.role-legend dt { font-weight: 700; }
.role-legend dd { margin: 0; color: var(--ink-2); }
@media (max-width: 700px) { .role-legend { grid-template-columns: 1fr; } }

/* Sign-in */
.session-body { display: grid; place-items: center; padding: 24px; background: var(--rail); }
.session-card { width: min(440px, 100%); background: var(--surface); border-radius: 10px; padding: 36px 32px; display: flex; flex-direction: column; gap: 14px; }
.session-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.session-card h1 { font-size: 1.75rem; }
.session-lede { color: var(--ink-2); margin-bottom: 8px; }
.session-note { color: var(--ink-3); font-size: 0.9rem; }

/* Small screens: the rail is a sticky top bar with the current page and a menu; filters scroll sideways;
   wide tables keep their first column in view. */
.segmented > button, .segmented > label, .segmented-link { white-space: nowrap; }
.rail-menu-toggle { display: none; }
.rail-menu { display: contents; }
@media (max-width: 900px) {
  .rail {
    position: sticky; top: 0; z-index: 20; height: auto; overflow: visible;
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 6px 12px; padding: 8px 12px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
  }
  .brand { padding: 4px 4px; }
  .brand-name { display: none; }
  .rail-menu-toggle {
    display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; min-width: 0;
    padding: 6px 12px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: var(--radius); background: transparent; color: var(--rail-ink); font: inherit; font-weight: 500; cursor: pointer;
  }
  .rail-menu-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .rail-menu-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail-menu-icon { display: inline-flex; flex-shrink: 0; }
  .rail-menu-icon-close, .rail.is-open .rail-menu-icon-open { display: none; }
  .rail.is-open .rail-menu-icon-close { display: inline-flex; }
  .rail-menu { display: none; grid-column: 1 / -1; flex-direction: column; gap: 14px; padding: 6px 0 8px; }
  /* A menu taller than the screen scrolls on its own; the negative margin keeps the active link's highlight at the edge. */
  .rail.is-open .rail-menu {
    display: flex; max-height: calc(100dvh - 60px); overflow-y: auto; overscroll-behavior: contain;
    margin-right: -12px; padding-right: 12px;
  }
  .rail-menu > * { flex-shrink: 0; } /* the menu scrolls; its sections keep their height */
  .rail-nav { gap: 2px; }
  .rail-list { gap: 0; }
  .rail-link { display: flex; align-items: center; min-height: 44px; padding: 8px 10px; }
  .rail-heading { padding: 4px 4px 4px 10px; }
  .rail-list-scroll { min-height: 0; overflow: visible; margin-right: 0; padding-right: 0; }
  .rail-link.active { margin-right: -12px; }
  .account { margin-top: 4px; }
  .account-toggle { min-height: 44px; }
  .account-menu { position: static; margin-top: 4px; box-shadow: none; }
  .menu-link, .account-signout { min-height: 44px; display: flex; align-items: center; }
  .main { padding-top: 16px; }
  .toolbar { gap: 8px 12px; }
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .toolbar-interval { margin-left: 0; }
  .search { min-width: 0; width: 100%; }
  .table-scroll-x .table th:first-child, .table-scroll-x .table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
  .table-scroll-x .table th:first-child { background: var(--surface-2); }
  .table-scroll-x .table tr.is-current td:first-child { background: var(--surface); }
  .panel { min-height: 280px; }
  .panel-stat { min-height: 0; }
  .panel-stat .panel-body { min-height: 150px; }
  .stat-value { font-size: 2.25rem; }
  .answer-number { font-size: 2.5rem; }
  .save-panel input[type="text"] { min-width: 0; width: 100%; }
  .explore-table td:first-child { white-space: normal; overflow-wrap: anywhere; }
}
/* Fingers need more room than pointers. */
@media (pointer: coarse) {
  .btn, .segmented > button, .segmented > label, .segmented-link, .panel-toggle { min-height: 42px; display: inline-flex; align-items: center; }
  .coverage-toggle { width: 38px; height: 38px; }
  input, select, textarea { font-size: 1rem; } /* keeps iOS from zooming into fields */
}

/* Dialogs: the confirmation (replaces window.confirm for data-turbo-confirm) and small task dialogs such as linking a tenant */
.confirm, .dialog { border: 1px solid var(--line-strong); border-radius: 8px; padding: 24px; background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); }
.confirm::backdrop, .dialog::backdrop { background: rgba(10, 20, 18, 0.45); }
.confirm p { font-size: 1.05rem; margin-bottom: 18px; }
.confirm .form-actions, .dialog .form-actions { justify-content: flex-end; margin-top: 4px; }
.dialog-form { display: flex; flex-direction: column; gap: 16px; }
.dialog-form h2 { overflow-wrap: anywhere; }
.dialog-form > .hint { margin-top: -8px; }

/* Tags in the catalog */
/* Cells stay table cells; the chips inside them are inline so they flow on one line and wrap as a group. */
.tags-cell { line-height: 1.9; white-space: normal; min-width: 16rem; max-width: 34rem; }
.tags-cell .tag { margin: 0 4px 2px 0; }
.tag { display: inline-flex; align-items: baseline; gap: 4px; padding: 1px 8px; margin-right: 4px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.85rem; white-space: nowrap; vertical-align: middle; }
.tag-name { color: var(--ink-3); }
.tag-name::after { content: "="; }
.tag-count { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tag-count::before { content: "\00a0"; }
.table-keys td:nth-child(n+3) { white-space: nowrap; }

/* Explore */
.explore-form { margin-bottom: 24px; }
.answer { margin-bottom: 20px; }
.answer-number { font-size: 3.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.answer-caption { color: var(--ink-2); max-width: 70ch; margin-top: 4px; }
.save-panel { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.save-panel input[type="text"] { min-width: 320px; flex: 1; }
.explore-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.explore-grid .panel { min-height: 360px; }
@media (max-width: 1000px) { .explore-grid .panel { grid-column: span 12; } }
.explore-table { overflow: auto; padding: 0 16px 8px; }
.explore-table table { width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; border-collapse: separate; border-spacing: 0; }
.explore-table th, .explore-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.explore-table thead th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 500; }
.explore-table .num { text-align: right; }
.explore-table td a { color: var(--ink); }

/* CRM extension */
.stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.stack > h2 { margin-top: 8px; }
.integration { gap: 12px; }
.integration-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.integration-status { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0; }
.integration-status dt { color: var(--ink-3); font-size: 0.9rem; }
.integration-status dd { margin: 0; }
.error-text { color: var(--danger); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.switch input { accent-color: var(--accent); width: 18px; height: 18px; }
.license { gap: 10px; }
.license.is-archived { opacity: 0.6; }
.license-head h3 { font-size: 1rem; }
.table-flat { border: 0; border-radius: 0; }
.table-flat th { background: transparent; }
.table tr.is-current td { background: var(--accent-soft); }
.invoice-split { display: block; font-size: 0.8rem; white-space: nowrap; } /* "5,300 + 700" under a period's total seats */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.badge-muted { background: var(--surface-2); color: var(--ink-3); }
/* Discrepancies page: the per-check summary and the groups below it. */
.discrepancy-summary { max-width: 640px; margin-bottom: 26px; }
.discrepancy-group { margin-top: 30px; scroll-margin-top: 72px; } /* the summary's anchor links land below the sticky bar */
.discrepancy-group .section-head h2 .badge { margin-left: 8px; }
.discrepancy-group .table-scroll-x .table td { white-space: normal; } /* long license names and details wrap; the table stays on screen */
.discrepancy-group .table td:first-child, .discrepancy-group .table td:nth-child(2) { white-space: nowrap; }
.discrepancy-group .table td:nth-child(3) { min-width: 24ch; }
.discrepancy-detail { font-variant-numeric: tabular-nums; min-width: 28ch; }
.badge-warn { background: var(--danger-soft); color: var(--danger); margin-left: 0; }
.tenant-key { font-weight: 500; }
.utilisation { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.meter { display: inline-block; width: 90px; height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--accent); }
.meter-fill.is-over { background: var(--danger); }
.row-link { color: var(--ink); font-weight: 500; }
.pager { display: flex; gap: 8px; margin-top: 12px; }
.segmented-link { padding: 6px 12px; color: var(--ink-2); font-weight: 500; border-right: 1px solid var(--line); text-decoration: none; }
.segmented-link:last-child { border-right: 0; }
.segmented-link:hover { background: var(--surface-2); text-decoration: none; }
.segmented-link.active { background: var(--accent-soft); color: var(--accent); }
/* The wrapper scrolls and clips the rounded corners; a table that clipped itself would be the box its sticky
   first column sticks to, so it would scroll away with the rest. */
.table-scroll-x { overflow-x: auto; border-radius: var(--radius); }
.table-scroll-x .table { overflow: visible; border-collapse: separate; border-spacing: 0; }
.table-scroll-x .table td, .table-scroll-x .table th { white-space: nowrap; }
.table-scroll-x .table td.tags-cell { white-space: normal; } /* the catalog's tag chips wrap as a group */
/* The pinned first column takes at most half the screen and wraps, so the columns beside it stay readable. */
@media (max-width: 900px) {
  .table-scroll-x .table :is(th, td):first-child { white-space: normal; overflow-wrap: anywhere; min-width: 10rem; max-width: 45vw; }
  .table-scroll-x .table td.key-cell { overflow-wrap: normal; } /* a metric key breaks between its parts, never inside one */
  .table-scroll-x .table td.key-cell .segments-metric { flex-wrap: wrap; }
}
.trend-down { color: var(--danger); font-weight: 500; }
.trend-up { color: var(--good); font-weight: 500; }

/* Coverage grid: which tenants count towards which license */
.section-head { display: flex; flex-direction: column; gap: 4px; }
.section-head .hint { max-width: 70ch; }
.coverage-grid th, .coverage-grid td { vertical-align: middle; }
.coverage-grid thead th { white-space: normal; }
.coverage-license { min-width: 160px; max-width: 220px; }
.coverage-license-name { display: block; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coverage-license-meta { display: block; font-weight: 400; font-size: 0.85rem; white-space: nowrap; }
.coverage-tenant { font-weight: 400; text-align: left; }
.coverage-tenant .tenant-key { display: block; }
.coverage-tenant .muted { display: block; font-size: 0.85rem; }
.coverage-cell { text-align: center; width: 1%; }
.coverage-cell .inline-form { display: inline-block; }
.coverage-toggle { width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; border: 1.5px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--on-accent); cursor: pointer; transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease; }
.coverage-toggle:hover { border-color: var(--accent); }
.coverage-toggle:active { transform: scale(0.94); }
.coverage-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.coverage-toggle.is-on { background: var(--accent); border-color: var(--accent); }
.coverage-toggle.is-on:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.coverage-toggle svg { width: 16px; height: 16px; }
.coverage-toggle[disabled] { cursor: default; opacity: 0.7; }
.coverage-toggle[disabled]:hover { border-color: var(--line-strong); }
.coverage-note { font-size: 0.85rem; white-space: nowrap; }
.coverage-grid tr.is-uncovered .coverage-tenant .tenant-key { color: var(--ink-2); }
.coverage-count { text-align: center; font-size: 0.85rem; color: var(--ink-2); border-top: 1px solid var(--line); }
.coverage-count.is-empty { color: var(--danger); }
.coverage-grid tfoot td { padding-top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .coverage-toggle { transition: none; } .coverage-toggle:active { transform: none; } }

/* Metric templates: a key drawn part by part */
.code-field { font-weight: 500; }
.segments { display: inline-flex; flex-wrap: wrap; align-items: flex-start; gap: 0 2px; }
.segment { display: inline-flex; flex-direction: column; align-items: center; padding: 2px 6px; border-radius: 4px; font-weight: 500; line-height: 1.25; }
.segment + .segment::before { content: none; }
.segment small { font-weight: 400; font-size: 0.72rem; color: var(--ink-3); line-height: 1.2; }
.segment.is-literal { color: var(--ink-3); font-weight: 400; }
.segment.is-metric { color: var(--ink); }
.segment.is-tag { color: var(--accent); background: var(--accent-soft); }
.segment.is-tag small { color: var(--accent); opacity: 0.85; }
.segment.is-skip { color: var(--ink-3); text-decoration: line-through; }
.segment.is-invalid { color: var(--danger); background: var(--danger-soft); }
.segments .segment:not(:last-child)::after { content: ""; }
.readings { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.readings li { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 14px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.readings li:last-child { border-bottom: 0; }
.reading-metric { font-size: 0.9rem; align-self: center; }
.preview { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.preview-summary { max-width: 80ch; }
.preview-problem { color: var(--danger); display: block; }
.preview-metrics { margin-top: 8px; max-width: 90ch; }
.templates td .segments { margin-bottom: 2px; }
.template-description { display: block; font-size: 0.85rem; }
.templates td.is-zero { color: var(--danger); }
.unread-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.unread-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.unread-keys { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.segments-metric { flex-wrap: nowrap; }
.segments-metric .segment { padding: 1px 4px; }
.segments-metric .segment.is-tag { font-size: 0.85rem; }
.segments-link { text-decoration: none; }
.segments-link:hover .segment.is-tag { background: var(--accent); color: var(--on-accent); }
.segments-link:hover .segment.is-tag small { color: var(--on-accent); }
