:root {
  /* Palette and surface inherited from sonetel-neon's KPI cards (CR-035). */
  --bg: #f4f6fb; --panel: #ffffff; --ink: #1b2330; --muted: #6b7689; --line: #e4e8f0;
  --up: #1a7f37; --up-bg: #ecfdf5; --up-line: #a7f3d0; --bad-bg: #fef2f2; --bad-line: #fecaca;
  --down-bg: #fff1f2; --down-line: #fecdd3; --error-edge: #d92d20; /* CR-040: bad value vs broken data */
  --stale-bg: #fffbeb; --stale-line: #fde68a;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 4px 16px rgba(20, 30, 50, 0.05);
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); background: #fff; }
.topbar h1 { display: flex; align-items: center; gap: .5rem; font-size: 1.1rem; margin: 0; color: var(--ink); } /* CR-069: the name in ink, the accent is for actions */
.topbar h1 .mark { display: block; width: 30px; height: 30px; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.topbar-actions a { color: var(--accent-text); text-decoration: none; font-size: .95rem; }
.topbar button { font: inherit; padding: .4rem .9rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.topbar button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.topbar button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding: 1.25rem; }

/* Four-number card template (spec §4), styled after sonetel-neon's .kpi cards (CR-035):
   title + last 24h on top, yesterday as the headline, 7d / 30d avg at the bottom, each with a
   visible small-caps caption. The whole card tints when yesterday beat both averages. */
.card { background: var(--panel); border: 1px solid transparent; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-height: 124px; display: flex; flex-direction: column; }
.card-good { background: var(--up-bg); border-color: var(--up-line); }
.card-bad { background: var(--down-bg); border-color: var(--down-line); }
/* An error is about the data, not its value: tint plus a solid red edge so it never reads as "bad". */
.card-errored { background: var(--bad-bg); border-color: var(--bad-line); box-shadow: inset 4px 0 0 var(--error-edge), var(--shadow); }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.card-corner { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.card-cap { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); }
.card-mainwrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 0; }
.card-main { font-size: 32px; font-weight: 800; letter-spacing: -.5px; line-height: 1; font-variant-numeric: tabular-nums; }
.card-unit { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.card-bottom { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.card-status { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
/* CR-044: thresholds set in admin. Critical is a stronger red than "bad"; error keeps its edge. */
.card-critical { background: #fee2e2; border-color: #f87171; }
.card-warn { background: var(--stale-bg); border-color: #fbbf24; }
.card-good .card-status, .card-bad .card-status, .card-errored .card-status { border-top-color: rgba(27, 35, 48, 0.08); }
.card-when { color: var(--muted); text-align: right; }
.pill { padding: 1px 7px; border-radius: 999px; }
.pill-ok { background: #e6f4ea; color: var(--up); }
.pill-error { background: #fde8e8; color: #b42318; }
.pill-stale { background: #fef3c7; color: #92610a; }
.pill-empty { background: #eef1f4; color: var(--muted); }

/* Home + collector pages (CR-036). */
.view { padding: 0 1.25rem 2rem; }
.view .card-grid { padding: 0; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 22px 0 10px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.back { display: inline-block; margin-top: 18px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; }
.back:hover { color: var(--ink); }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid transparent; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; color: var(--ink); cursor: pointer; transition: border-color .15s; min-height: 150px; }
.tile:hover, .tile:focus-visible { border-color: #c9d6f3; outline: none; }
.tile-good { background: var(--up-bg); border-color: var(--up-line); }
.tile-bad { background: var(--down-bg); border-color: var(--down-line); }
.tile-error { background: var(--bad-bg); border-color: var(--bad-line); box-shadow: inset 4px 0 0 var(--error-edge), var(--shadow); }
.tile-stale { background: var(--stale-bg); border-color: var(--stale-line); }
.tile-critical { background: #fee2e2; border-color: #f87171; }
.tile-warn { background: var(--stale-bg); border-color: #fbbf24; }
.tile-critical .tile-problems { color: #b42318; }
.tile-warn .tile-problems { color: #92610a; }
.tile-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tile-problems { font-size: 12px; font-weight: 700; color: #b42318; }
.tile-stale .tile-problems { color: #92610a; }
.tile-metric { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tile-count { font-size: 32px; font-weight: 800; letter-spacing: -.5px; line-height: 1.1; flex: 1; display: flex; align-items: center; gap: 6px; }
.tile-up { font-size: 13px; font-weight: 600; display: flex; gap: 14px; }
.tile-bottom { display: flex; justify-content: flex-end; align-items: baseline; font-size: 11px; font-weight: 600; }
.card-stale { background: var(--stale-bg); border-color: var(--stale-line); }

/* Star toggle on each card (CR-036). */
.star { border: 0; background: none; padding: 0 6px 0 0; margin: 0; cursor: pointer; vertical-align: -2px; line-height: 0; }
.star svg { width: 15px; height: 15px; fill: none; stroke: #9aa3b2; stroke-width: 1.8; stroke-linejoin: round; }
.star:hover svg { stroke: #c08a00; }
.star-on svg { fill: #f5b301; stroke: #d99a00; }

@media (max-width: 600px) { .card-grid, .tile-grid { grid-template-columns: 1fr; } .view { padding: 0 1rem 1.5rem; } }

/* CR-058: time view. Neutral colours on data; the accent (CR-065) only on the range buttons. */
.card-link { color: inherit; text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.card-spark { margin-top: 8px; height: 26px; }
.spark { width: 100%; height: 26px; }
.spark path { fill: none; stroke: var(--muted); stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.card-grid-one { grid-template-columns: minmax(0, 360px); }
.timeview { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-top: 16px; }
.tv-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.tv-range { font: inherit; font-size: .85rem; padding: .25rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; }
.tv-range.on { border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.tv-compare { margin-left: auto; font-size: .85rem; color: var(--muted); }
.tv-chart { width: 100%; overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.chart-line { fill: none; stroke: var(--ink); stroke-width: 2; }
.chart-avg7 { fill: none; stroke: var(--muted); stroke-width: 1.3; stroke-dasharray: 5 4; }
.chart-avg30 { fill: none; stroke: #a7afbd; stroke-width: 1.3; stroke-dasharray: 1.5 3.5; }
.chart-prev { fill: none; stroke: #c9cfd9; stroke-width: 1.6; stroke-dasharray: 6 4; }
.chart-dot { fill: var(--ink); cursor: pointer; }
.chart-partial { fill: #fff; stroke: var(--ink); stroke-width: 1.5; }
.chart-grid { stroke: var(--line); }
.chart-axis { font-size: 11px; fill: var(--muted); }
.chart-empty { font-size: 13px; fill: var(--muted); }
.tv-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--ink); vertical-align: middle; margin-right: -6px; }
.lg-avg7 { border-top: 1.5px dashed var(--muted); }
.lg-avg30 { border-top: 1.5px dotted #a7afbd; }
.lg-prev { border-top: 1.5px dashed #c9cfd9; }
/* CR-060: trigger event ticks (status colours, as on the cards). */
.chart-ev { stroke: none; }
.chart-ev-threshold_critical, .chart-ev-error { fill: var(--error-edge); }
.chart-ev-threshold_low { fill: #d9a400; }
.chart-ev-recovered, .chart-ev-ok_again { fill: var(--up); }
.chart-ev-stale { fill: #a7afbd; }
.chart-ev-target_hit { fill: var(--ink); }
/* CR-022: comments - markers on the chart and the list under it. */
.chart-comment { fill: #fff; stroke: var(--muted); stroke-width: 1.5; }
.chart-comment-high { fill: var(--ink); stroke: var(--ink); }
.chart-cline { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.chart-ctext { font-size: 11px; fill: var(--ink); }
.tv-comments { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.tv-h { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 0 0 6px; }
.tv-clist { list-style: none; margin: 0 0 8px; padding: 0; }
.tv-clist li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.tv-clist li.high .tv-cbody { font-weight: 600; }
.tv-cdate { color: var(--muted); font-variant-numeric: tabular-nums; }
.tv-ctag { font-size: .75rem; padding: 0 .45rem; border-radius: 9px; background: #eef2f8; color: var(--muted); }
.tv-cbody { flex: 1; min-width: 12rem; }
.tv-clist button { font: inherit; font-size: .75rem; padding: .1rem .45rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.tv-cform { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.tv-cform input[type=text] { flex: 1; min-width: 14rem; font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px; }
.tv-cform input[type=date] { font: inherit; padding: .3rem; border: 1px solid var(--line); border-radius: 6px; }
.tv-cform label { font-size: .85rem; color: var(--muted); }
.tv-cform button { font: inherit; padding: .35rem .9rem; border-radius: 6px; }
.tv-cmsg { color: var(--error-edge); font-size: .85rem; }
/* CR-059: periods - calm tints, never status colours or the accent. */
.chart-band { opacity: .55; }
.chart-band-blue { fill: #dbe7ff; background: #dbe7ff; }
.chart-band-violet { fill: #ece3ff; background: #ece3ff; }
.chart-band-teal { fill: #d6f1ee; background: #d6f1ee; }
.chart-band-grey { fill: #e6e9ef; background: #e6e9ef; }
.chart-bandtext { font-size: 10.5px; fill: var(--muted); }
.tv-swatch { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
/* CR-062: target - on the card and as a step line (neutral ink, never the accent). */
.card-target { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.card-target.reached { color: var(--up); font-weight: 600; }
.chart-target { fill: none; stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 8 3 2 3; opacity: .75; }
.lg-target { border-top: 1.5px dashed var(--ink); opacity: .75; }
/* CR-063: history feed - status colours only on event rows. */
.tv-history .feed-threshold_critical .tv-cbody, .tv-history .feed-error .tv-cbody { color: var(--error-edge); }
.tv-history .feed-recovered .tv-cbody, .tv-history .feed-ok_again .tv-cbody, .tv-history .feed-target_hit .tv-cbody { color: var(--up); }

