/* The `hidden` attribute must win over any element's `display` (e.g. flex/grid),
   otherwise toggling `el.hidden` has no visual effect. */
[hidden] {
  display: none !important;
}

@font-face {
  font-family: 'Panton';
  src: url('./fonts/Panton-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Panton';
  src: url('./fonts/Panton-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Panton';
  src: url('./fonts/Panton-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --background: #f4f6fa;
  --foreground: #111827;
  --card: #ffffff;
  --card-foreground: #111827;
  --muted: #f1f5f9;
  --muted-foreground: #667085;
  --border: #dbe3ec;
  --border-strong: #c9d4df;
  --input: #9aa8b7;
  --primary: #4a7b90;
  --primary-hover: #5d91a6;
  --primary-dark: #354855;
  --sidebar: #ffffff;
  --sidebar-accent: #f4f6f8;
  --ok: #88b96d;
  --ok-soft: #e8f4e2;
  --warn: #f5d05e;
  --warn-soft: #fff6d8;
  --down: #ef9666;
  --down-soft: #fff0e8;
  --danger: #dc2626;
  --radius: 8px;
  --header-height: 64px;
  --sidebar-width: 236px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100vh;
  overflow: hidden;
  font-family: Inter, Roboto, 'Helvetica Neue', 'Arial Nova', 'Nimbus Sans', Arial, sans-serif;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--foreground);
  background: var(--background);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

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

.dashboard-shell {
  display: flex;
  height: 100vh;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex: 0 0 var(--sidebar-width);
  flex-direction: column;
  gap: 28px;
  width: var(--sidebar-width);
  padding: 22px 14px;
  border-right: 1px solid var(--border);
  background: var(--sidebar);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
}

.sidebar-logo img {
  display: block;
  width: 118px;
  max-width: 100%;
  height: auto;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  color: #475467;
  font-weight: 600;
}

.nav-item-active,
.nav-item:hover {
  color: var(--primary-dark);
  background: var(--sidebar-accent);
}

.nav-icon {
  width: 14px;
  color: var(--primary);
  font-size: 10px;
  text-align: center;
}

.app-frame {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted-foreground);
}

.breadcrumb strong {
  color: var(--foreground);
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-operational {
  color: #496d37;
  background: var(--ok-soft);
  border-color: rgba(136, 185, 109, 0.38);
}

.muted,
.metric-note,
.vq-card-header p {
  color: var(--muted-foreground);
}

.muted,
.metric-note {
  font-size: 12px;
}

.screen {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.screen-inner {
  width: min(100%, 1440px);
  min-height: 0;
  padding: 24px 24px 72px;
}

.title-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.title-copy {
  min-width: 0;
}

.title-copy h1 {
  margin: 0;
  overflow: hidden;
  color: var(--foreground);
  font-family: Panton, sans-serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-copy p {
  margin: 6px 0 0;
  color: var(--muted-foreground);
  font-size: 14px;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--foreground);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}

.metrics-grid,
.content-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 24px;
}

.metrics-grid {
  margin-bottom: 24px;
}

.metric-card,
.vq-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--card-foreground);
  background: var(--card);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  grid-column: span 4;
  gap: 8px;
  padding: 20px 24px;
}

.metric-label {
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-card strong {
  color: var(--primary-dark);
  font-family: Panton, sans-serif;
  font-size: 30px;
  line-height: 1;
}

.overview-card,
.incident-card {
  grid-column: span 12;
}

.vq-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 20px 24px 18px;
  border-bottom: 1px solid var(--border);
}

.vq-card-header h2 {
  margin: 0;
  font-family: Panton, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
}

.vq-card-header p {
  margin: 5px 0 0;
  font-size: 12px;
}

.vq-card-content {
  padding: 24px;
}

.legend {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  color: var(--muted-foreground);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.systems-overview {
  display: grid;
  gap: 14px;
}

.system-row {
  display: grid;
  grid-template-columns: 40px minmax(118px, 150px) minmax(0, 1fr) 84px;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

/* Current-state traffic light: full height of the 3 heatmap rows, ~3x a day cell wide. */
.traffic-light {
  align-self: stretch;
  min-height: 47px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 5px;
}

.system-row:first-child {
  padding-top: 0;
}

.system-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.system-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.system-name strong {
  overflow-wrap: anywhere;
  font-family: Panton, sans-serif;
  font-size: 15px;
  font-weight: 600;
}

.system-name span,
.system-uptime {
  color: var(--muted-foreground);
  font-size: 12px;
}

.system-uptime {
  text-align: right;
}

.system-uptime strong {
  color: var(--primary-dark);
  font-size: 13px;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(30, minmax(8px, 1fr));
  grid-auto-rows: 13px;
  gap: 4px;
  width: 100%;
}

.day-cell {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 3px;
  text-decoration: none;
}

.day-cell-action {
  appearance: none;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  cursor: pointer;
}

.day-cell-action:hover,
.day-cell-action:focus {
  border-color: rgba(53, 72, 85, 0.72);
  box-shadow: 0 0 0 2px rgba(74, 123, 144, 0.22);
}

.day-cell-action:focus {
  outline: none;
}

.level-ok {
  background: var(--ok);
}

.level-warn {
  background: var(--warn);
}

.level-down {
  background: var(--down);
}

.incident-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.incident-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  background: var(--card);
}

.incident-table th,
.incident-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.incident-table th {
  color: var(--muted-foreground);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.incident-table tbody tr:last-child td {
  border-bottom: 0;
}

.incident-table tbody tr {
  cursor: pointer;
}

.incident-table tbody tr:hover td,
.incident-table tbody tr:focus td {
  background: #f8fafc;
}

.incident-table tbody tr:focus {
  outline: 2px solid rgba(74, 123, 144, 0.45);
  outline-offset: -2px;
}

.incident-system {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
}

.incident-system::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--down);
}

.description {
  max-width: 560px;
  color: #344054;
}

.modal-overlay {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.46);
}

.incident-modal {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.24);
}

.incident-modal:focus {
  outline: none;
}

.incident-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.incident-modal-header h2 {
  margin: 10px 0 6px;
  font-family: Panton, sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
}

.incident-modal-header p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 14px;
  line-height: 1.5;
}

.modal-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  color: #496d37;
  background: var(--ok-soft);
  font-size: 12px;
  font-weight: 800;
}

.modal-close-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--muted-foreground);
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.modal-close-button:hover,
.modal-close-button:focus {
  color: var(--foreground);
  background: var(--muted);
}

.incident-modal-body {
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
}

.incident-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0 0 28px;
}

.incident-detail-grid div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}

.incident-detail-grid dt {
  margin: 0 0 6px;
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.incident-detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--foreground);
  font-weight: 700;
}

.incident-update-section h3 {
  margin: 0 0 16px;
  font-family: Panton, sans-serif;
  font-size: 16px;
  font-weight: 600;
}

.incident-updates {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.incident-update {
  position: relative;
  display: grid;
  gap: 6px;
  padding-left: 24px;
}

.incident-update::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
}

.incident-update::after {
  content: '';
  position: absolute;
  top: 18px;
  bottom: -18px;
  left: 4px;
  width: 2px;
  background: var(--border);
}

.incident-update:last-child::after {
  display: none;
}

.incident-update-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  color: var(--foreground);
  font-weight: 800;
}

.incident-update-title time {
  flex: 0 0 auto;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 600;
}

.incident-update p {
  margin: 0;
  color: #344054;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 980px) {
  html {
    overflow: auto;
  }

  .dashboard-shell {
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    display: none;
  }

  .screen {
    overflow: visible;
  }

  .metric-card {
    grid-column: span 12;
  }
}

@media (max-width: 720px) {
  .topbar,
  .title-bar,
  .vq-card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    padding: 14px 16px;
  }

  .screen-inner {
    padding: 20px 16px 48px;
  }

  .title-copy h1 {
    white-space: normal;
  }

  .legend {
    justify-content: flex-start;
  }

  .system-row {
    grid-template-columns: 1fr;
  }

  /* Stacked layout — show the light as a thin bar on top of each system. */
  .traffic-light {
    align-self: stretch;
    min-height: 0;
    height: 8px;
  }

  .system-uptime {
    text-align: left;
  }

  .incident-detail-grid {
    grid-template-columns: 1fr;
  }

  .modal-overlay {
    padding: 12px;
  }

  .incident-modal {
    max-height: calc(100vh - 24px);
  }
}

@media (max-width: 520px) {
  .vq-card-content,
  .metric-card {
    padding: 18px;
  }

  .heatmap {
    gap: 3px;
    grid-auto-rows: 10px;
  }
}

/* --- Manage systems page ------------------------------------------------- */
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.primary-button:hover {
  background: var(--primary-hover);
}
.danger-button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--danger);
  background: var(--card);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.danger-button:hover {
  background: var(--down-soft);
}

.manage-table-wrap {
  width: 100%;
}
.manage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.manage-table th,
.manage-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.manage-table th {
  color: var(--muted-foreground);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.manage-table .col-order {
  width: 84px;
  white-space: nowrap;
}
.manage-table .col-actions {
  width: 80px;
  text-align: center;
}
.system-manage-row {
  cursor: pointer;
}
.system-manage-row:hover {
  background: var(--sidebar-accent);
}
.system-manage-row:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.icon-button {
  min-width: 28px;
  height: 28px;
  margin-right: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--card);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover:not(:disabled) {
  background: var(--muted);
}
.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}
.icon-button.danger {
  color: var(--danger);
}

.type-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
}

.manage-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.manage-form .form-row span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
}
.manage-form input,
.manage-form select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--input);
  border-radius: 6px;
  font: inherit;
  background: var(--card);
}
.manage-form input[readonly] {
  background: var(--muted);
  color: var(--muted-foreground);
}
.form-error {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.footer-spacer {
  flex: 1;
}
.login-modal {
  max-width: 360px;
}
.api-key-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--sidebar-accent);
}
.api-key-section p {
  margin: 2px 0 0;
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--primary-dark);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
}

.type-badge.visibility-external {
  background: var(--ok-soft);
  color: var(--primary-dark);
}
.type-badge.visibility-internal {
  background: var(--muted);
  color: var(--muted-foreground);
}

.integration {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--sidebar-accent);
}
.integration summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.integration p {
  margin: 8px 0 0;
  font-size: 12px;
}
.integration pre {
  margin: 8px 0 0;
  padding: 12px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--primary-dark);
  color: #f4f6fa;
  font-size: 12px;
  line-height: 1.5;
}
