/* =============================================================================
   SYSTEM HEALTH DASHBOARD — SOP-OPS-01 v1.2 Part 2
   13-tile status grid. Colours match SOP §2 tokens.
   ============================================================================= */

:root {
  --sh-green-fg: #2D5144;
  --sh-green-bg: #E8F5E9;
  --sh-amber-fg: #B86E00;
  --sh-amber-bg: #FFF8E1;
  --sh-red-fg: #C62828;
  --sh-red-bg: #FFEBEE;
  --sh-unknown-fg: #6B6360;
  --sh-unknown-bg: #EBE8E3;
}

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

.sh-page {
  padding: 16px;
}

.sh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.sh-toolbar h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text-primary, #2B2523);
}

.sh-refresh-btn {
  appearance: none;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  color: var(--text-primary, #2B2523);
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.sh-refresh-btn:hover:not(:disabled) {
  background: var(--color-warm-linen, #EBE8E3);
}

.sh-refresh-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

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

@media (max-width: 960px) {
  .sh-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .sh-grid { grid-template-columns: 1fr; }
}

.sh-footer {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted, #6B6360);
}

.sh-footer--error {
  color: var(--sh-red-fg);
}

/* ---------- Tile base ---------- */

.sh-tile {
  border-radius: 8px;
  padding: 14px;
  min-height: 92px;
  background: var(--sh-unknown-bg);
  color: var(--sh-unknown-fg);
  border-left: 4px solid var(--sh-unknown-fg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 120ms ease;
}

.sh-tile:hover { transform: translateY(-1px); }

.sh-tile__header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sh-tile__name {
  flex: 1;
  min-width: 0;
}

.sh-tile__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.sh-tile__metric {
  font-size: 17px;
  font-weight: 600;
  margin-top: 8px;
  line-height: 1.25;
}

.sh-tile__checked {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 8px;
  font-weight: 400;
}

/* ---------- Level variants ---------- */

.sh-tile--green {
  background: var(--sh-green-bg);
  color: var(--sh-green-fg);
  border-left-color: var(--sh-green-fg);
}

.sh-tile--amber {
  background: var(--sh-amber-bg);
  color: var(--sh-amber-fg);
  border-left-color: var(--sh-amber-fg);
}

.sh-tile--red {
  background: var(--sh-red-bg);
  color: var(--sh-red-fg);
  border-left-color: var(--sh-red-fg);
}

.sh-tile--unknown {
  background: var(--sh-unknown-bg);
  color: var(--sh-unknown-fg);
  border-left-color: var(--sh-unknown-fg);
}

.sh-tile__dot--green { color: var(--sh-green-fg); }
.sh-tile__dot--amber { color: var(--sh-amber-fg); }
.sh-tile__dot--red { color: var(--sh-red-fg); }
.sh-tile__dot--unknown { color: var(--sh-unknown-fg); }

/* Loading skeleton — gentle pulse so refreshes aren't visually noisy */
.sh-tile--loading {
  background: var(--sh-unknown-bg);
  color: var(--sh-unknown-fg);
  border-left-color: var(--sh-unknown-fg);
  animation: sh-tile-pulse 1400ms ease-in-out infinite;
}
.sh-tile__dot--loading { color: var(--sh-unknown-fg); }

@keyframes sh-tile-pulse {
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 1; }
}

/* ---------- Clickable tiles (non-green with a panel) ---------- */

.sh-tile--clickable { cursor: pointer; }
.sh-tile--clickable:focus-visible {
  outline: 2px solid var(--color-forest-green, #2D5144);
  outline-offset: 2px;
}

/* ---------- Exception panels ---------- */

.sh-panels {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sh-panel {
  background: #fff;
  border: 1px solid var(--color-stone, #C4BCB0);
  border-radius: 8px;
  padding: 14px 16px;
}

.sh-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sh-panel__header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-primary, #2B2523);
}

.sh-panel__toggle {
  appearance: none;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.sh-panel__toggle:hover { background: var(--color-warm-linen, #EBE8E3); }

.sh-panel__help {
  margin: 8px 0 4px;
  font-size: 13px;
  color: var(--text-muted, #6B6360);
}

.sh-panel__body { margin-top: 12px; }
.sh-panel__loading,
.sh-panel__error,
.sh-empty {
  padding: 10px;
  font-size: 14px;
  color: var(--text-muted, #6B6360);
}
.sh-panel__error { color: var(--sh-red-fg); }

/* ---------- Tables inside panels ---------- */

.sh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.sh-table th,
.sh-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-warm-linen, #EBE8E3);
  vertical-align: top;
}

.sh-table th {
  font-weight: 600;
  color: var(--text-muted, #6B6360);
  background: var(--color-warm-linen, #EBE8E3);
}

.sh-table tbody tr:hover { background: rgba(0, 0, 0, 0.02); }

.sh-row--red { background: var(--sh-red-bg); }

.sh-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.sh-actions button,
.sh-webhook-actions button {
  appearance: none;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}
.sh-actions button:hover,
.sh-webhook-actions button:hover { background: var(--color-warm-linen, #EBE8E3); }
.sh-actions button:disabled,
.sh-webhook-actions button:disabled { opacity: 0.5; cursor: wait; }

.sh-webhook-actions {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

/* ---------- Webhook grouping ---------- */

.sh-error-group {
  margin-top: 10px;
  border: 1px solid var(--color-warm-linen, #EBE8E3);
  border-radius: 6px;
  padding: 8px;
}

.sh-error-group__head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.sh-error-group__head .sh-count {
  margin-left: auto;
  font-weight: 600;
  color: var(--sh-red-fg);
}

/* ---------- Details / guidance ---------- */

.sh-details summary {
  cursor: pointer;
  color: var(--text-muted, #6B6360);
  font-size: 12px;
}
.sh-details pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  background: var(--color-warm-linen, #EBE8E3);
  padding: 8px;
  border-radius: 4px;
  margin-top: 6px;
}

.sh-guidance {
  background: var(--sh-amber-bg);
  color: var(--sh-amber-fg);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 10px 0;
}

/* ---------- Toasts ---------- */

.sh-toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  max-width: 420px;
}

.sh-toast {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: sh-toast-in 160ms ease-out;
}

.sh-toast--success { background: var(--sh-green-fg); }
.sh-toast--error   { background: var(--sh-red-fg); }
.sh-toast--warn    { background: var(--sh-amber-fg); }
.sh-toast--info    { background: var(--text-primary, #2B2523); }

@keyframes sh-toast-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Controls section (Workers, Cron, Replay, Diagnostics) ---------- */

.sh-controls {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sh-workers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.sh-worker-btn {
  appearance: none;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  color: var(--text-primary, #2B2523);
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.sh-worker-btn:hover:not(:disabled) { background: var(--color-warm-linen, #EBE8E3); }
.sh-worker-btn:disabled { opacity: 0.55; cursor: wait; }

.sh-inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-top: 8px;
}
.sh-inline-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted, #6B6360);
  flex: 1 1 200px;
}
.sh-inline-form label > input,
.sh-inline-form label > select {
  display: block;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
}
.sh-inline-form input,
.sh-inline-form select {
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--color-stone, #C4BCB0);
  border-radius: 4px;
  background: #fff;
}
.sh-inline-form button {
  appearance: none;
  border: 1px solid var(--color-forest-green, #2D5144);
  background: var(--color-forest-green, #2D5144);
  color: #fff;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
}
.sh-inline-form button:hover { background: #244035; }

.sh-diag-body { margin-top: 10px; }

.sh-diag-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sh-diag-controls input[type="search"] {
  flex: 1 1 260px;
  max-width: 360px;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--color-stone, #C4BCB0);
  border-radius: 4px;
  background: #fff;
}

.sh-diag-count {
  font-size: 12px;
  color: var(--text-muted, #6B6360);
}

.sh-diag-scroll {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--color-warm-linen, #EBE8E3);
  border-radius: 4px;
}

.sh-sortable {
  cursor: pointer;
  user-select: none;
}
.sh-sortable:hover { background: var(--color-stone, #C4BCB0); }

.sh-diag-show-all {
  appearance: none;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  color: var(--text-primary, #2B2523);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: auto;
}
.sh-diag-show-all:hover { background: var(--color-warm-linen, #EBE8E3); }

.sh-cron-summary {
  display: flex;
  gap: 8px;
  margin: 8px 0;
  flex-wrap: wrap;
}

.sh-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-warm-linen, #EBE8E3);
  color: var(--text-muted, #6B6360);
}
.sh-badge--green   { background: var(--sh-green-bg); color: var(--sh-green-fg); }
.sh-badge--amber   { background: var(--sh-amber-bg); color: var(--sh-amber-fg); }
.sh-badge--red     { background: var(--sh-red-bg);   color: var(--sh-red-fg); }
.sh-badge--unknown { background: var(--sh-unknown-bg); color: var(--sh-unknown-fg); }

/* ---------- Modal ---------- */

.sh-modal-host {
  position: fixed;
  inset: 0;
  z-index: 10000;
}
.sh-modal-host[hidden] { display: none; }

.sh-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sh-modal {
  position: relative;
  max-width: 560px;
  margin: 40px auto;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}

.sh-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-warm-linen, #EBE8E3);
}
.sh-modal__header h3 { margin: 0; font-size: 16px; }

.sh-modal__x {
  appearance: none;
  background: transparent;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted, #6B6360);
  line-height: 1;
}
.sh-modal__x:hover { color: var(--text-primary, #2B2523); }

.sh-modal__body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.sh-modal__body label {
  display: block;
  font-size: 12px;
  color: var(--text-muted, #6B6360);
}
.sh-modal__body label > input,
.sh-modal__body label > select {
  display: block;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
  padding: 7px 9px;
  font-size: 14px;
  border: 1px solid var(--color-stone, #C4BCB0);
  border-radius: 4px;
  background: #fff;
  color: var(--text-primary, #2B2523);
}

.sh-modal__note {
  font-size: 13px;
  color: var(--text-muted, #6B6360);
  background: var(--color-warm-linen, #EBE8E3);
  padding: 10px;
  border-radius: 6px;
  margin: 0 0 4px;
}

.sh-req { color: var(--sh-red-fg); margin-left: 2px; }

.sh-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-warm-linen, #EBE8E3);
}
.sh-modal__actions button {
  appearance: none;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid var(--color-stone, #C4BCB0);
  background: #fff;
  cursor: pointer;
}
.sh-modal__actions .sh-modal__submit {
  background: var(--color-forest-green, #2D5144);
  border-color: var(--color-forest-green, #2D5144);
  color: #fff;
}
.sh-modal__actions button:disabled { opacity: 0.5; cursor: wait; }

.sh-modal__error {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--sh-red-bg);
  color: var(--sh-red-fg);
  border-radius: 6px;
  font-size: 13px;
  white-space: pre-wrap;
}
