/* ============================================================
   M365 Monitoring Dashboard — Stylesheet
   System-color theme via CSS light-dark() — follows OS preference
   ============================================================ */

/* -- Color Scheme ------------------------------------------------ */
:root {
  color-scheme: light dark;
}

/* -- Reset & Base ------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background-color: light-dark(#f5f5f5, #1a1a1a);
  color: light-dark(#1a1a1a, #e5e5e5);
}

/* -- Page Header ------------------------------------------------- */
.header {
  text-align: center;
  padding: 28px 0 20px;
  border-bottom: 3px solid light-dark(#1a1a1a, #e5e5e5);
  margin-bottom: 24px;
  background-color: light-dark(#f5f5f5, #1a1a1a);
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  color: light-dark(#1a1a1a, #e5e5e5);
  margin-bottom: 6px;
}

.header .meta {
  font-size: 12px;
  color: light-dark(#888, #999);
}

.header .user-info {
  color: light-dark(#888, #999);
  margin-left: 4px;
}

/* -- Freshness Indicator ----------------------------------------- */
.freshness {
  font-weight: 600;
}

.freshness.fresh {
  color: light-dark(#2d7a3e, #5cb86c);
}

.freshness.stale {
  color: light-dark(#a36800, #e0a030);
}

.freshness.old {
  color: light-dark(#b01c1c, #e84040);
}

/* -- Layout Container -------------------------------------------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 48px;
}

/* -- Loading / Error States -------------------------------------- */
#loading {
  text-align: center;
  padding: 48px 0;
  color: light-dark(#888, #999);
  font-size: 14px;
}

#error {
  text-align: center;
  padding: 48px 0;
  color: light-dark(#b01c1c, #e84040);
  font-size: 14px;
}

/* -- Badge Groups ------------------------------------------------ */
.badge-group {
  margin-bottom: 18px;
}

.badge-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: light-dark(#888, #999);
  margin-bottom: 8px;
  padding-left: 2px;
}

.badge-group-note {
  font-weight: 400;
  font-size: 9px;
  letter-spacing: 0;
  text-transform: none;
  color: light-dark(#aaa, #777);
  margin-left: 6px;
}

.badge-group-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  flex-wrap: wrap;
}

/* -- Status Badges ----------------------------------------------- */
.status-badge {
  flex: 1 1 0;
  min-width: 100px;
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  border-radius: 10px;
  border: 2px solid light-dark(#d8d8d8, #444);
  background-color: light-dark(#fff, #222);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
}

.status-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

.status-badge:active {
  transform: translateY(0);
}

.badge-label {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: light-dark(#555, #bbb);
  margin-bottom: 4px;
}

.badge-value {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 2px;
}

.badge-detail {
  font-size: 8px;
  color: light-dark(#888, #999);
  line-height: 1.3;
  display: none;
}

/* Badge severity variants */
.badge-green {
  background-color: light-dark(#d4edda, #1e4a2a);
  border-color: #4a9e5c;
  box-shadow: 0 2px 6px rgba(74, 158, 92, 0.2);
}

.badge-green .badge-value {
  color: light-dark(#2d7a3e, #5cb86c);
}

.badge-green .badge-label {
  color: light-dark(#2d7a3e, #5cb86c);
}

.badge-amber {
  background-color: light-dark(#fff3cd, #3a2e0a);
  border-color: #c87f0a;
  box-shadow: 0 2px 6px rgba(200, 127, 10, 0.2);
}

.badge-amber .badge-value {
  color: light-dark(#a36800, #e0a030);
}

.badge-amber .badge-label {
  color: light-dark(#a36800, #e0a030);
}

.badge-red {
  background-color: light-dark(#f8d0d0, #4a1010);
  border-color: #c0292a;
  box-shadow: 0 2px 8px rgba(192, 41, 42, 0.25);
}

.badge-red .badge-value {
  color: light-dark(#b01c1c, #e84040);
}

.badge-red .badge-label {
  color: light-dark(#b01c1c, #e84040);
}

/* Blue badge for informational/neutral sections */
.badge-blue {
  background-color: light-dark(#dce8f5, #0f2440);
  border-color: light-dark(#5b8db8, #3a7ac0);
  box-shadow: 0 2px 6px rgba(59, 122, 192, 0.2);
}

.badge-blue .badge-value {
  color: light-dark(#2a6496, #6aadee);
}

.badge-blue .badge-label {
  color: light-dark(#2a6496, #6aadee);
}

.badge-blue .badge-detail {
  color: light-dark(#3a7ab8, #5898d4);
}

/* Gray badge for no-data placeholders */
.badge-gray {
  background-color: light-dark(#f0f0f0, #2a2a2a);
  border-color: light-dark(#ccc, #555);
  box-shadow: none;
  cursor: default;
}

.badge-gray .badge-value {
  color: light-dark(#aaa, #666);
}

.badge-gray .badge-label {
  color: light-dark(#999, #777);
}

.badge-gray .badge-detail {
  color: light-dark(#bbb, #555);
}

/* -- Detail Sections --------------------------------------------- */

/* Collapsed state (default) */
.detail-section {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding: 0;
  margin-bottom: 0;
  border: none;
  border-radius: 8px;
  background-color: light-dark(#fff, #222);
  transition: max-height 0.4s ease-out, opacity 0.3s ease-out, padding 0.3s, margin 0.3s;
}

/* Expanded state */
.detail-section.expanded {
  max-height: none;
  opacity: 1;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid light-dark(#d8d8d8, #444);
}

/* Section header bar */
.section-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 2px solid light-dark(#d8d8d8, #444);
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: light-dark(#1a1a1a, #e5e5e5);
}

.section-source {
  font-size: 9px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: light-dark(#888, #999);
  text-align: right;
}

/* -- Metrics Row ------------------------------------------------- */
.metrics-row {
  display: flex;
  flex-direction: row;
  gap: 24px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.metric-item, .metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 60px;
}

[title] {
  cursor: help;
}

.status-badge[title] {
  cursor: pointer;
}

.badge-gray[title] {
  cursor: default;
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: light-dark(#1a1a1a, #e5e5e5);
}

.metric-value.green { color: light-dark(#2d7a3e, #5cb86c); }
.metric-value.amber { color: light-dark(#a36800, #e0a030); }
.metric-value.red   { color: light-dark(#b01c1c, #e84040); }

.metric-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: light-dark(#888, #999);
  margin-top: 3px;
}

/* -- Sparkline Charts -------------------------------------------- */
.sparkline-container {
  margin-bottom: 14px;
}

.sparkline-bars {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 2px;
  height: 40px;
}

.spark-bar {
  flex: 1;
  min-width: 4px;
  border-radius: 2px 2px 0 0;
  transition: opacity 0.15s;
}

.spark-bar:hover {
  opacity: 0.75;
}

.bar-green {
  background-color: #7dad6c;
}

.bar-amber {
  background-color: #c87f0a;
}

.bar-red {
  background-color: #b01c1c;
}

.sparkline-label {
  font-size: 9px;
  color: light-dark(#888, #999);
  margin-top: 4px;
}

/* -- Detail Tables ----------------------------------------------- */
.detail-table-container {
  overflow-x: auto;
}

.scroll-table-container {
  max-height: 400px;
  overflow-y: scroll;
  border: 1px solid light-dark(#d8d8d8, #444);
  border-radius: 4px;
  margin-top: 8px;
}

.detail-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
  color: light-dark(#1a1a1a, #e5e5e5);
}

.detail-table thead tr {
  border-bottom: 2px solid light-dark(#d8d8d8, #444);
}

.detail-table thead th {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: light-dark(#888, #999);
  padding: 4px 8px 6px;
  text-align: left;
}

.detail-table tbody tr {
  border-bottom: 1px solid light-dark(#ebebeb, #333);
}

.detail-table tbody tr:last-child {
  border-bottom: none;
}

.detail-table tbody td {
  padding: 6px 8px;
  vertical-align: middle;
}

.detail-table tbody tr:hover {
  background-color: light-dark(rgba(0,0,0,0.03), rgba(255,255,255,0.04));
}

/* Row severity colouring */
.row-red {
  color: light-dark(#b01c1c, #e84040);
}

.row-amber {
  color: light-dark(#a36800, #e0a030);
}

/* -- Severity Pill Badges ---------------------------------------- */
.severity-pill {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.severity-pill.critical,
.severity-pill.high {
  background-color: light-dark(#f8d0d0, #4a1010);
  color: light-dark(#b01c1c, #e84040);
}

.severity-pill.medium {
  background-color: light-dark(#fff3cd, #3a2e0a);
  color: light-dark(#a36800, #e0a030);
}

.severity-pill.low,
.severity-pill.informational {
  background-color: light-dark(#d4edda, #1e4a2a);
  color: light-dark(#2d7a3e, #5cb86c);
}

/* -- Section action links ---------------------------------------- */
.section-links {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid light-dark(#eee, #444);
  flex-wrap: wrap;
}

.section-link {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.section-link:hover {
  opacity: 0.8;
}

.teams-link {
  background: light-dark(#eee8f9, #2a1a50);
  color: light-dark(#5b2d8e, #b088e0);
  border: 1px solid light-dark(#d0c0e8, #4a2a70);
}

.portal-link {
  background: light-dark(#e8f0fe, #1a3050);
  color: light-dark(#1a56db, #6ea8fe);
  border: 1px solid light-dark(#c5d9f2, #2a4a70);
}

/* -- Responsive -------------------------------------------------- */
@media (max-width: 720px) {
  .badge-group-row {
    flex-wrap: wrap;
  }

  .status-badge {
    flex: 1 1 calc(33% - 10px);
    min-width: 100px;
  }

  .metrics-row {
    gap: 16px;
  }

  .metric-value {
    font-size: 22px;
  }
}

@media (max-width: 480px) {
  .status-badge {
    flex: 1 1 calc(50% - 10px);
  }

  .header h1 {
    font-size: 17px;
  }
}
