/* ==========================================================================
   Reset, typography and layout primitives.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--on-surface);
  font-family: var(--font-body);
  font-size: var(--fs-body-md);
  line-height: var(--lh-body-md);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

::selection {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

/* Thin, recessive scrollbars — chrome should not compete with telemetry. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-highest) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--surface-highest);
  border-radius: var(--r-full);
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--outline-variant);
}

:focus-visible {
  outline: 2px solid var(--primary-container);
  outline-offset: 2px;
  border-radius: var(--r-md);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

canvas {
  display: block;
}

[hidden] {
  display: none !important;
}

/* --- Type scale ---------------------------------------------------------- */

.t-headline-xl { font-family: var(--font-headline); font-size: var(--fs-headline-xl); line-height: var(--lh-headline-xl); font-weight: 700; letter-spacing: -0.02em; }
.t-headline-lg { font-family: var(--font-headline); font-size: var(--fs-headline-lg); line-height: var(--lh-headline-lg); font-weight: 600; letter-spacing: -0.02em; }
.t-headline-md { font-family: var(--font-headline); font-size: var(--fs-headline-md); line-height: var(--lh-headline-md); font-weight: 600; letter-spacing: -0.01em; }
.t-headline-sm { font-family: var(--font-headline); font-size: var(--fs-headline-sm); line-height: var(--lh-headline-sm); font-weight: 600; }
.t-body-lg { font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); letter-spacing: -0.01em; }
.t-body { font-size: var(--fs-body-md); line-height: var(--lh-body-md); }
.t-body-sm { font-size: var(--fs-body-sm); line-height: var(--lh-body-sm); letter-spacing: 0.01em; }
.t-label { font-family: var(--font-mono); font-size: var(--fs-label-md); line-height: var(--lh-label-md); font-weight: 500; letter-spacing: 0.04em; }
.t-label-sm { font-family: var(--font-mono); font-size: var(--fs-label-sm); line-height: var(--lh-label-sm); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.t-metric { font-family: var(--font-mono); font-size: var(--fs-metric); line-height: var(--lh-metric); font-weight: 600; letter-spacing: -0.03em; }
.t-metric-inline { font-family: var(--font-mono); font-size: var(--fs-metric-inline); line-height: var(--lh-metric-inline); font-weight: 500; letter-spacing: -0.02em; }
.t-code { font-family: var(--font-mono); font-size: var(--fs-code); line-height: var(--lh-code); }

.mono { font-family: var(--font-mono); }
.dim { color: var(--on-surface-variant); }
.faint { color: var(--outline); }
.bright { color: var(--on-surface); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Addresses and names keep their case inside the uppercase label style. */
.keep-case { text-transform: none; letter-spacing: 0.02em; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }

/* --- Semantic colour ----------------------------------------------------- */

.c-ok { color: var(--signal-ok); }
.c-live { color: var(--signal-live); }
.c-warn { color: var(--signal-warn); }
.c-crit { color: var(--signal-crit-text); }
.c-info { color: var(--signal-info); }
.c-idle { color: var(--signal-idle); }

/* --- Layout primitives --------------------------------------------------- */

.row { display: flex; align-items: center; }
.row-top { display: flex; align-items: flex-start; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.end { justify-content: flex-end; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.shrink0 { flex-shrink: 0; }

.g-xs { gap: var(--sp-xs); }
.g-sm { gap: var(--sp-sm); }
.g-md { gap: var(--sp-md); }
.g-lg { gap: var(--sp-lg); }
.g-gutter { gap: var(--gutter); }

.grid { display: grid; gap: var(--gutter); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

/* The 12-column fluid grid the system is built on.
   `align-items: start` matters: without it every column stretches to the
   tallest one in the row, leaving dead space under the shorter columns. */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gutter);
  align-items: start;
}
.sp-2 { grid-column: span 2; }
.sp-3 { grid-column: span 3; }
.sp-4 { grid-column: span 4; }
.sp-5 { grid-column: span 5; }
.sp-6 { grid-column: span 6; }
.sp-7 { grid-column: span 7; }
.sp-8 { grid-column: span 8; }
.sp-9 { grid-column: span 9; }
.sp-12 { grid-column: span 12; }

/* Tablet / laptop: 8 columns, tighter gutter. */
@media (max-width: 1439px) {
  .grid-12 { gap: 12px; }
  .grid-5, .grid-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sp-3 { grid-column: span 6; }
  .sp-4 { grid-column: span 6; }
  .sp-5 { grid-column: span 12; }
  .sp-7 { grid-column: span 12; }
  .sp-8 { grid-column: span 12; }
  .sp-9 { grid-column: span 12; }
}

/* Mobile: single-column stack. */
@media (max-width: 767px) {
  .grid-2, .grid-3, .grid-4, .grid-5, .grid-6 { grid-template-columns: minmax(0, 1fr); }
  .grid-12 { grid-template-columns: minmax(0, 1fr); gap: var(--sp-sm); }
  .grid-12 > * { grid-column: span 1 !important; }
}

.scroll-y { overflow-y: auto; }
.scroll-x { overflow-x: auto; }
.rel { position: relative; }

/* --- Animation ----------------------------------------------------------- */

@keyframes pulse-ring {
  0%   { transform: scale(0.8); opacity: 0.9; }
  70%  { transform: scale(2.4); opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}

@keyframes pulse-fade {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(340%); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
