/* Components: machine tiles, KPI tiles, fleet table, chart, feed, forms, chips, toasts */

/* Status chips: symbol + label so colour is never the only signal. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-1);
  font-weight: 600;
  white-space: nowrap;
}
.status .sym { font-family: var(--mono); font-size: 11px; line-height: 1; }
.status--normal { color: var(--nominal); }
.status--anomaly { color: var(--anomaly); }
.status--offline { color: var(--offline); }
.status--learning { color: var(--learning); }

.status-chip {
  padding: 2px var(--s-2);
  border: 1px solid currentColor;
  border-radius: var(--radius);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px var(--s-2);
  border-radius: var(--radius);
  font-size: var(--fs-1);
  font-weight: 600;
  border: 1px solid var(--line-strong);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge--warn { border-color: var(--anomaly); color: var(--anomaly); background: var(--anomaly-dim); }
.badge--info { border-color: var(--nominal); color: var(--nominal); }

/* Machine tiles */
.machine-list { display: flex; flex-direction: column; }
.machine-tile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}
.machine-tile.is-selected { background: var(--bg-2); border-left-color: var(--nominal); }
.machine-tile.is-anomaly { border-left-color: var(--anomaly); }
.machine-tile.is-selected.is-anomaly { border-left-color: var(--anomaly); }
.machine-tile.is-offline .tile-kw { color: var(--text-dim); }

.tile-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  gap: 2px var(--s-2);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-3);
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}
.tile-main:hover { background: var(--bg-2); }
.tile-main:focus-visible { outline-offset: -2px; }
.tile-name { grid-column: 1; grid-row: 1; font-weight: 600; font-size: var(--fs-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-type { grid-column: 1; grid-row: 2; font-size: var(--fs-1); color: var(--text-muted); }
.tile-kw { grid-column: 2; grid-row: 1 / 3; font-size: var(--fs-5); line-height: 1.1; text-align: right; align-self: center; white-space: nowrap; }
.tile-kw .unit { font-family: var(--sans); font-size: var(--fs-1); color: var(--text-muted); }
.tile-meta {
  grid-column: 1 / 3;
  grid-row: 3;
  display: flex;
  gap: var(--s-3);
  align-items: center;
  font-size: var(--fs-1);
  color: var(--text-muted);
  flex-wrap: wrap;
}
.tile-meta .num { color: var(--text); }
.tile-gear {
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  width: 36px;
  cursor: pointer;
  font-size: var(--fs-4);
}
.tile-gear:hover { background: var(--bg-2); color: var(--text); }
.tile-gear:focus-visible { outline-offset: -2px; }

@media (max-width: 767px) {
  .machine-list { flex-direction: row; padding: var(--s-2); gap: var(--s-2); }
  .machine-tile {
    min-width: 200px;
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-radius: var(--radius);
  }
}

/* KPI tiles: a single bordered grid, cells separated by lines rather than
   floating cards. */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-1);
  overflow: hidden;
}
.kpi {
  padding: var(--s-3);
  border-right: 1px solid var(--line);
  min-width: 0;
}
.kpi:last-child { border-right: 0; }
.kpi-label { font-size: var(--fs-1); color: var(--text-muted); margin-bottom: var(--s-1); }
.kpi-value { font-size: var(--fs-6); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value .unit { font-family: var(--sans); font-size: var(--fs-2); color: var(--text-muted); margin-left: 3px; }
.kpi-sub { font-size: var(--fs-1); color: var(--text-muted); margin-top: var(--s-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi--anomaly .kpi-value { color: var(--anomaly); }
.kpi--learning .kpi-value { color: var(--learning); }

@media (max-width: 1199px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-right: 0; }
  .kpi:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 767px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-last-child(-n + 2) { border-bottom: 0; }
  .kpi-value { font-size: var(--fs-5); }
}

/* Chart */
.chart-panel .panel-head { gap: var(--s-2); }
.legend { display: flex; gap: var(--s-3); flex-wrap: wrap; font-size: var(--fs-1); color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend .sw { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--chart-series); }
.legend .sw--forecast { border-top-style: dashed; border-top-color: var(--chart-forecast); }
.legend .sw--anomaly { width: auto; height: auto; border: 0; color: var(--chart-anomaly); font-family: var(--mono); }
.legend .sw--truth { width: 18px; height: 6px; border: 0; background: var(--chart-truth); }
.legend .sw--warmup { width: 18px; height: 12px; border: 1px solid var(--line-strong); background: var(--chart-warmup); }

.chart {
  position: relative;
  height: 300px;
  min-width: 0;
}
.chart svg { width: 100%; height: 100%; }
.chart svg:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.chart-score { height: 80px; border-top: 1px solid var(--line); }
.chart text { font-family: var(--mono); font-size: 11px; fill: var(--text-muted); }
.chart .grid line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .axis line { stroke: var(--chart-axis); stroke-width: 1; }
.chart .series { fill: none; stroke: var(--chart-series); stroke-width: 1.75; stroke-linejoin: round; }
.chart .forecast { fill: none; stroke: var(--chart-forecast); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .anomaly-marks { fill: var(--chart-anomaly); stroke: var(--bg-1); stroke-width: 1; }
.chart .truth { fill: var(--chart-truth); }
.chart .warmup { fill: var(--chart-warmup); }
.chart .threshold { stroke: var(--chart-anomaly); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .score-series { fill: none; stroke: var(--text-muted); stroke-width: 1.25; }
.chart .score-flag { fill: var(--chart-anomaly); }
.chart .cursor line { stroke: var(--chart-cursor); stroke-width: 1; stroke-dasharray: 2 2; }
.chart .cursor circle { fill: var(--bg-1); stroke: var(--chart-cursor); stroke-width: 1.5; }
.chart .now-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .axis-title { fill: var(--text-dim); font-family: var(--sans); }

.chart-readout {
  position: absolute;
  top: var(--s-2);
  left: 56px;
  padding: var(--s-1) var(--s-2);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: var(--fs-1);
  pointer-events: none;
  white-space: nowrap;
  display: flex;
  gap: var(--s-3);
}
.chart-readout .num { color: var(--text); }
.chart-readout .is-anomaly { color: var(--anomaly); }

.note {
  font-size: var(--fs-1);
  color: var(--text-muted);
  padding: var(--s-2) var(--s-3);
  border-top: 1px solid var(--line);
}

/* Fleet table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: var(--fs-2); }
.table th, .table td {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table th { font-weight: 600; color: var(--text-muted); font-size: var(--fs-1); }
.table th.r, .table td.r { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.is-selected td { background: var(--bg-2); }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--bg-2); }
.table .row-btn {
  background: none; border: 0; padding: 0; color: inherit; cursor: pointer; font: inherit; font-weight: 600; text-align: left;
}

/* Event feed */
.feed { display: flex; flex-direction: column; }
.feed-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  font-size: var(--fs-1);
}
.feed-item .feed-time { color: var(--text-muted); grid-column: 1; }
.feed-item .feed-kind { grid-column: 2; font-weight: 600; }
.feed-item .feed-msg { grid-column: 1 / 3; color: var(--text); }
.feed-item--anomaly { border-left-color: var(--anomaly); background: rgba(245, 165, 36, 0.06); }
.feed-item--anomaly .feed-kind { color: var(--anomaly); }
.feed-item--clear .feed-kind { color: var(--nominal); }
.feed-item--error { border-left-color: var(--danger); }
.feed-item--error .feed-kind { color: var(--danger); }
.feed-item--sim .feed-kind, .feed-item--profile .feed-kind, .feed-item--info .feed-kind { color: var(--text-muted); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  height: 24px;
  padding: 0 var(--s-2);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--fs-1);
  font-weight: 600;
}
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--bg-3); color: var(--text); }
.seg button:focus-visible { outline-offset: -2px; }

.empty {
  padding: var(--s-4) var(--s-3);
  color: var(--text-muted);
  font-size: var(--fs-2);
}

/* Forms (settings drawer, profile modal) */
.form-section { margin-bottom: var(--s-5); }
.form-section > h3 {
  padding-bottom: var(--s-1);
  margin-bottom: var(--s-3);
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--s-3) var(--s-3);
}
.form-grid .span-2 { grid-column: 1 / -1; }
.field-block { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-block label { font-size: var(--fs-1); color: var(--text-muted); }
.field-block .help { font-size: 11px; color: var(--text-dim); }
.field-block .input, .field-block .select { width: 100%; }
.field-inline { display: flex; align-items: center; gap: var(--s-2); }
.field-inline .input { flex: 1; }
.field-inline .unit { font-size: var(--fs-1); color: var(--text-muted); white-space: nowrap; }
.check { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-2); cursor: pointer; }

.banner {
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  font-size: var(--fs-2);
  margin-bottom: var(--s-3);
  background: var(--bg-2);
}
.banner--error { border-color: var(--danger); }
.banner--warn { border-color: var(--anomaly); }
.banner--ok { border-color: var(--nominal); }
.banner h4 { font-size: var(--fs-2); margin-bottom: var(--s-1); }
.banner ul { padding-left: var(--s-4); list-style: disc; margin: var(--s-1) 0; }
.banner .actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); flex-wrap: wrap; }

/* Profile list */
.profile-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); }
.profile-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-1) var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.profile-row:last-child { border-bottom: 0; }
.profile-row .p-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-row .p-meta { font-size: var(--fs-1); color: var(--text-muted); display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
.profile-row .p-actions { display: flex; gap: var(--s-1); flex-wrap: wrap; justify-content: flex-end; grid-row: 1 / 3; }
@media (max-width: 767px) {
  .profile-row { grid-template-columns: 1fr; }
  .profile-row .p-actions { grid-row: auto; justify-content: flex-start; }
}

.radio-group { display: flex; flex-direction: column; gap: var(--s-2); }
.radio-group label { display: flex; gap: var(--s-2); align-items: flex-start; font-size: var(--fs-2); cursor: pointer; }
.radio-group input { margin-top: 3px; accent-color: var(--nominal); }
.radio-group .help { display: block; color: var(--text-muted); font-size: var(--fs-1); }

.toast {
  padding: var(--s-2) var(--s-3);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  font-size: var(--fs-2);
  display: flex;
  gap: var(--s-2);
  align-items: flex-start;
}
.toast--error { border-left-color: var(--danger); }
.toast--ok { border-left-color: var(--nominal); }
.toast--warn { border-left-color: var(--anomaly); }
.toast .btn { margin-left: auto; flex-shrink: 0; }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-3);
}

.log-size { font-size: var(--fs-1); color: var(--text-muted); }
