:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --danger: #f87171;
  --border: #374151;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 34rem),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 0.65rem;
  padding: 0.65rem 0.9rem;
  color: white;
  background: var(--accent-strong);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.65rem 0.8rem;
  background: var(--panel);
  color: var(--text);
}

.app {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.header {
  display: grid;
  grid-template-columns: 1fr minmax(18rem, 30rem);
  gap: 1.5rem;
  align-items: end;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4rem);
  letter-spacing: -0.06em;
}

.header p,
.muted {
  color: var(--muted);
}

.settings {
  display: grid;
  gap: 0.45rem;
}

.settings label {
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-row {
  display: flex;
  gap: 0.5rem;
}

.status-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(17, 24, 39, 0.88);
  box-shadow: var(--shadow);
}

.status-card {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  margin-bottom: 1rem;
}

.layout {
  display: grid;
  grid-template-columns: 22rem 1fr;
  gap: 1rem;
  align-items: start;
}

.panel {
  overflow: hidden;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-heading h2,
.panel-heading h3 {
  margin: 0;
}

.selected-client {
  margin: 0.25rem 0 0;
  word-break: break-all;
}

.clients {
  display: grid;
  gap: 0.5rem;
  max-height: 65vh;
  overflow: auto;
  padding: 1rem;
}

.client-button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.client-button.active {
  border-color: var(--accent);
  outline: 2px solid rgba(56, 189, 248, 0.25);
}

.client-cert {
  display: block;
  margin-bottom: 0.35rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-created {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.report-sections {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.latest-card {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 1rem;
  background: rgba(31, 41, 55, 0.65);
}

.latest-card h3 {
  margin: 0 0 0.75rem;
}

.latest-report {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.latest-report.updated .metric {
  animation: latestPulse 2800ms ease-in-out;
}

.metric {
  border-radius: 0.75rem;
  padding: 0.85rem;
  background: var(--panel);
}

.metric-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.metric-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  word-break: break-word;
}

.metric-time {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.1;
}

.metric-date {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.empty {
  display: block;
  color: var(--muted);
}

.reports-heading {
  padding: 0;
  border-bottom: 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 52rem;
}

th,
td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(31, 41, 55, 0.9);
}

td {
  font-size: 0.95rem;
}

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

.report-row-new {
  animation: reportRowUpdate 2600ms ease-in-out;
}

.cert-cell {
  max-width: 18rem;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.cert-cell {
  max-width: 18rem;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.error {
  color: var(--danger);
}

@keyframes latestPulse {
  0% {
    border-color: rgba(56, 189, 248, 0.95);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7), 0 0 24px rgba(56, 189, 248, 0.24);
    transform: translateY(-2px);
  }

  100% {
    border-color: transparent;
    box-shadow: none;
    transform: translateY(0);
  }
}

@keyframes reportRowUpdate {
  0% {
    background: transparent;
    box-shadow: inset 0 0 0 transparent;
    transform: translateY(0);
  }

  25% {
    background: rgba(56, 189, 248, 0.08);
    box-shadow: inset 2px 0 0 rgba(56, 189, 248, 0.45);
    transform: translateY(-0.08rem);
  }

  55% {
    background: rgba(56, 189, 248, 0.12);
    box-shadow: inset 2px 0 0 rgba(56, 189, 248, 0.65);
    transform: translateY(-0.08rem);
  }

  100% {
    background: transparent;
    box-shadow: inset 0 0 0 transparent;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .latest-report.updated .metric,
  .report-row-new {
    animation: none;
  }
}

@media (max-width: 900px) {
  .header,
  .layout {
    grid-template-columns: 1fr;
  }

  .latest-report {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .clients {
    max-height: 22rem;
  }
}

@media (max-width: 560px) {
  .settings-row,
  .status-card {
    flex-direction: column;
    align-items: stretch;
  }

  .latest-report {
    grid-template-columns: 1fr;
  }
}