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

:root {
  --ok:        #107c10;
  --ok-bg:     #dff6dd;
  --degraded:  #7a5c00;
  --degraded-bg:#fff4ce;
  --down:      #a4262c;
  --down-bg:   #fde7e9;
  --na:        #605e5c;
  --bg:        #ffffff;
  --surface:   #f3f2f1;
  --border:    #edebe9;
  --border-dark:#c8c6c4;
  --text:      #323130;
  --subtext:   #605e5c;
  --accent:    #0078d4;
  --header-bg: #0078d4;
  --header-text:#ffffff;
  --section-bg:#f3f2f1;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.65rem 1.5rem;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid #005a9e;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
  color: #fff;
}

.controls { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }

select, button {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 2px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
}
select option { background: #fff; color: var(--text); }
button:hover { background: rgba(255,255,255,0.25); }

#last-updated { color: rgba(255,255,255,0.75); font-size: 0.78rem; }

/* ── Matrix wrapper ── */
#matrix-wrapper {
  overflow-x: auto;
  padding: 1.5rem;
}

#matrix {
  border-collapse: collapse;
  min-width: 100%;
  white-space: nowrap;
  font-size: 13px;
}

/* ── Sticky header row ── */
#matrix thead tr {
  position: sticky;
  top: 0px;
  z-index: 10;
}

/* Hide the header row before data populates it */
#matrix thead tr:empty { display: none; }

#matrix th {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-dark);
  font-weight: 600;
  font-size: 0.78rem;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  vertical-align: bottom;
}

/* ── Sticky first column ── */
#matrix td:first-child,
#matrix th:first-child {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--bg);
  min-width: 200px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#matrix thead th:first-child { z-index: 15; background: var(--surface); }

/* ── Rows ── */
#matrix tbody tr:hover > td { background: #f0f6fc !important; }
#matrix tbody tr:hover > td:first-child { background: #f0f6fc !important; }

#matrix td {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}
#matrix td:first-child { text-align: left; }

/* ── System name cell ── */
.system-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--accent);
  text-decoration: none;
}
.system-name:hover span:first-child { text-decoration: underline; }
.system-name span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; color: var(--text); }

.env-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  background: #e1dfdd;
  color: var(--subtext);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

/* ── Status icons ── */
.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  cursor: default;
}
.status-icon svg { display: block; }
.status-na {
  color: var(--na);
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}

/* ── Last incident column ── */
.last-incident {
  color: var(--subtext);
  font-size: 0.78rem;
  text-align: center;
}

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
  pointer-events: none;
  max-width: 240px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  color: var(--text);
}
.tooltip.hidden { display: none; }

/* ── Details drawer ── */
.details-panel {
  position: fixed;
  top: 0; right: 0;
  width: min(480px, 100vw);
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--border-dark);
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.2s ease;
  box-shadow: -4px 0 16px rgba(0,0,0,0.1);
}
.details-panel.hidden { transform: translateX(100%); }

#details-close {
  position: absolute;
  top: 1rem; right: 1rem;
  font-size: 1.2rem;
  background: none;
  border: 1px solid var(--border-dark);
  color: var(--subtext);
  cursor: pointer;
  border-radius: 2px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
}
#details-close:hover { background: var(--surface); }

#details-title { font-size: 1rem; font-weight: 700; padding-right: 2rem; color: var(--text); }

#details-meta table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
#details-meta td { padding: 0.35rem 0.5rem; border: 1px solid var(--border); font-size: 0.82rem; color: var(--text); }
#details-meta td:first-child { color: var(--subtext); width: 50%; background: var(--surface); }

#details-history h3 { font-size: 0.82rem; font-weight: 700; color: var(--subtext); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.5rem; }
#details-history-list { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }

#details-history-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text);
}

#empty-msg { color: var(--subtext); padding: 2rem 0; text-align: center; }
