/* ============================================================================
   MXAccess Gateway dashboard — view layer.
   Layers over theme.css (the technical-light design system). Every colour,
   font, and surface here resolves to a theme.css token — no hard-coded hex.
   theme.css owns the tokens and the component library; this sheet only wires
   the dashboard's own class names and Bootstrap widgets into that system.
   ========================================================================= */

body.dashboard-body { min-height: 100vh; }

/* ── App bar ─────────────────────────────────────────────────────────────────
   The kit's theme.css styles .app-bar / .brand / .mark / .spacer; these rules
   centre the row and tweak the brand. Used by the minimal /denied page header —
   the main dashboard's navigation lives in the kit side-rail shell (ThemeShell). */
.app-bar { align-items: center; gap: 1rem; }
.app-bar .brand { color: var(--ink); }
.app-bar .brand:hover { text-decoration: none; }

/* ── Page header ─────────────────────────────────────────────────────────────
   h1 in sans, the sub-line in monospace as a quiet meta crumb. */
.dashboard-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  animation: rise 0.4s ease both;
}
.dashboard-page-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}
.dashboard-page-header .text-secondary {
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
}

/* ── KPI / aggregate cards ───────────────────────────────────────────────────
   The MetricCard component renders .agg-card with label/value/sub; this is
   the technical-light aggregate card — uppercase eyebrow, big mono number.
   Class names align with master (ScadaLink CentralUI) for consistency. */
.metric-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  margin-bottom: 1rem;
  animation: rise 0.4s ease both;
  animation-delay: 0.04s;
}
.metric-grid.compact { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); }

.agg-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: none;
}
.agg-card .card-body { padding: 0.7rem 0.9rem; }
.agg-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
}
.agg-card-wide { grid-column: span 2; }

.agg-value {
  margin-top: 0.25rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  /* break-word, not anywhere: keep date/number tokens whole, wrap at spaces. */
  overflow-wrap: break-word;
}
.agg-sub {
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

/* ── Section panels ──────────────────────────────────────────────────────────
   Each .dashboard-section is a raised panel: white card, hairline border. */
.dashboard-section {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin-top: 1rem;
  padding: 0.9rem;
  animation: rise 0.4s ease both;
  animation-delay: 0.09s;
}

.section-heading { margin-bottom: 0.6rem; }
.section-heading h2 {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin: 0;
}

/* ── Data tables ─────────────────────────────────────────────────────────────
   Dense, hairline-ruled, uppercase head on a faint fill. */
.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0;
  font-size: 0.85rem;
  background: var(--card);
}
.dashboard-table th,
.dashboard-table td {
  padding: 0.45rem 0.8rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--rule);
}
.dashboard-table th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  background: #fbfbf9;
  white-space: nowrap;
}
.dashboard-table td {
  max-width: 26rem;
  /* break-word, not anywhere: only split a word when it genuinely cannot
     fit, so the column keeps whole words like "unconstrained" intact. */
  overflow-wrap: break-word;
}
.dashboard-table tbody tr:last-child td { border-bottom: none; }
.dashboard-table tbody tr:hover { background: #f3f6fd; }

/* Key/value detail tables: left label column, monospace values, zebra rows. */
.details-table th {
  width: 16rem;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--card);
}
.details-table td {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--ink);
}
.details-table tbody tr:nth-child(even) { background: #fbfbf9; }
.details-table tbody tr:hover { background: #fbfbf9; }

/* Inline code: monospace, accent ink, no Bootstrap pink. */
code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent-deep);
}

/* Status chips never wrap, even in a narrow table column. */
.chip { white-space: nowrap; }

/* ── Empty / placeholder state ───────────────────────────────────────────────*/
.empty-state {
  background: #fbfbf9;
  border: 1px dashed var(--rule-strong);
  border-radius: 6px;
  color: var(--ink-faint);
  padding: 1rem 1.1rem;
  font-size: 0.85rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────
   Flatten Bootstrap buttons onto the single accent + hairline palette.

   Button *sizing* is not here: ZB.MOM.WW.Theme 0.4.0 upstreamed it into
   layout.css as --bs-btn-* variable overrides, and ThemeHead emits that sheet
   ahead of this one, so it applies without a local copy. Do not reintroduce a
   local font-size on .btn — a literal at equal specificity beats Bootstrap's
   `font-size: var(--bs-btn-font-size)` and flattens .btn-sm into a
   padding-only difference across the whole app.

   What remains is shape, not size, and is app-specific. border-radius stays a
   literal rather than --bs-btn-border-radius so .btn-sm cannot shrink it; the
   .btn-group seam rules outrank .btn, so groups still render seamed. */
.btn { border-radius: 5px; font-weight: 500; white-space: nowrap; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
}
.btn-outline-secondary {
  color: var(--ink-soft);
  background: var(--card);
  border-color: var(--rule-strong);
}
.btn-outline-secondary:hover {
  color: var(--ink);
  background: #f0f0ec;
  border-color: var(--rule-strong);
}
.btn-outline-danger {
  color: var(--bad);
  background: var(--card);
  border-color: #eec3c3;
}
.btn-outline-danger:hover {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

/* ── Forms ───────────────────────────────────────────────────────────────────*/
.form-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
}
.form-control,
.form-select {
  font-size: 0.85rem;
  border-color: var(--rule-strong);
  border-radius: 5px;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.15rem rgba(47, 95, 208, 0.15);
}

/* ── Alerts ──────────────────────────────────────────────────────────────────*/
.alert { border-radius: 6px; border-width: 1px; font-size: 0.85rem; }
.alert-success { color: var(--ok); background: var(--ok-bg); border-color: #c6e6cd; }
.alert-danger { color: var(--bad); background: var(--bad-bg); border-color: #eec3c3; }

/* ── API key management ──────────────────────────────────────────────────────*/
.api-key-management-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
}
.scope-grid {
  display: grid;
  gap: 0.35rem 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}
.one-time-secret {
  display: block;
  overflow-wrap: anywhere;
  white-space: normal;
  font-family: var(--mono);
}
.api-key-create-modal { display: block; }
.api-key-create-modal .modal-body {
  max-height: min(70vh, 44rem);
  overflow-y: auto;
}
.modal-content {
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
}

@media (max-width: 700px) {
  .page { padding: 0.85rem; }
  .dashboard-page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .details-table th { width: 9rem; }
}

/* ── Browse tab ───────────────────────────────────────────────────────────────
   Two-pane layout: the Galaxy hierarchy tree on the left, the live
   subscription panel on the right. Both panes are .dashboard-section cards. */
.browse-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  align-items: start;
}
.browse-panel { margin-top: 0; }

.browse-search { margin-bottom: 0.6rem; }

/* Click-to-dismiss "Galaxy redeployed" notice above the tree. The whole banner
   is the dismiss target, so it has to read as one. */
.browse-stale-banner {
  cursor: pointer;
  padding: 0.4rem 0.7rem;
  margin-bottom: 0.6rem;
}
.browse-search-note {
  margin-top: 0.5rem;
  font-size: 0.74rem;
  color: var(--ink-faint);
}

.browse-tree {
  max-height: 32rem;
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.3rem 0;
  background: #fbfbf9;
}
.browse-search-results { padding: 0.15rem 0; }

.tree-children { margin-left: 0.95rem; border-left: 1px solid var(--rule); }

.tree-row,
.tree-attr {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.5rem;
  font-size: 0.82rem;
  white-space: nowrap;
}
.tree-row:hover,
.tree-attr:hover { background: #eef2fb; }

.tree-toggle {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  line-height: 1;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 0.7rem;
  cursor: pointer;
}
.tree-toggle-empty { cursor: default; }

/* Loading / failed-to-load rows sit among .tree-row siblings and carry the same
   leading .tree-toggle-empty spacer. The spacer only takes its width as a flex
   item, so this container has to be flex or the row loses its indent. */
.tree-load-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.5rem;
  font-size: 0.82rem;
}
.tree-load-status > span:not(.tree-toggle) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-icon { color: var(--accent); font-size: 0.72rem; }
.tree-name { color: var(--ink); }
.tree-row-area .tree-name { font-weight: 600; }
.tree-tag { font-size: 0.72rem; color: var(--ink-faint); }

.tree-attr { cursor: context-menu; }
.attr-icon { flex: none; color: var(--ink-faint); width: 0.6rem; text-align: center; }
.attr-name { font-family: var(--mono); color: var(--ink); }
.attr-type { font-size: 0.72rem; color: var(--ink-faint); }
.attr-flag {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.02rem 0.28rem;
  border-radius: 3px;
}
.attr-flag-alarm { color: var(--bad); background: var(--bad-bg); }
.attr-flag-hist { color: var(--accent-deep); background: #e7ecfb; }

/* ── Subscription panel ───────────────────────────────────────────────────── */
.sub-panel-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.76rem;
  color: var(--ink-faint);
  margin-bottom: 0.5rem;
  min-height: 1.6rem;
}
.sub-clear { margin-left: auto; }
.sub-table td { vertical-align: middle; }
.sub-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}
.sub-actions-col { width: 1%; white-space: nowrap; }

.quality-chip {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
}
.quality-good { color: var(--ok); background: var(--ok-bg); }
.quality-bad { color: var(--bad); background: var(--bad-bg); }
.sub-error {
  margin-left: 0.3rem;
  color: var(--bad);
  font-weight: 700;
  cursor: help;
}

/* ── Right-click context menu ─────────────────────────────────────────────── */
.context-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1040;
  background: transparent;
}
.context-menu {
  position: fixed;
  z-index: 1050;
  min-width: 13rem;
  background: var(--card);
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(27, 29, 33, 0.16);
  padding: 0.25rem;
}
.context-menu-head {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.83rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}
.context-menu-item:hover { background: #eef2fb; color: var(--accent-deep); }

/* ── Alarms tab ───────────────────────────────────────────────────────────── */
.alarm-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}
.alarm-filter-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.alarm-filter-field { display: flex; flex-direction: column; gap: 0.2rem; }
.alarm-filter-field input[type="number"] { width: 7rem; }
.alarm-filter-grow { flex: 1 1 14rem; }
.alarm-filter-grow input { width: 100%; }

.alarm-state {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  white-space: nowrap;
}
.alarm-state-active { color: var(--bad); background: var(--bad-bg); }
.alarm-state-acked { color: var(--warn); background: var(--warn-bg); }
.alarm-state-other { color: var(--idle); background: var(--idle-bg); }
.alarm-severity {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.alarm-desc {
  margin-top: 0.1rem;
  font-size: 0.74rem;
  color: var(--ink-faint);
}

@media (max-width: 960px) {
  .browse-layout { grid-template-columns: minmax(0, 1fr); }
}
