/* ==========================================================================
   Polliwog Dashboard -- Mission Control Theme
   ==========================================================================
   Neo-brutalist monitoring dashboard for 20 live data collectors.
   Dark background, monospace data, structural grid lines, status LEDs.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Surface hierarchy */
  --bg-root: #0a0a0f;
  --bg-panel: #0f0f17;
  --bg-card: #12121c;
  --bg-card-hover: #181826;
  --bg-input: #0a0a12;
  --bg-overlay: rgba(10, 10, 15, 0.92);

  /* Borders & grid lines */
  --border-subtle: #1a1a2e;
  --border-medium: #252540;
  --border-strong: #33335a;

  /* Text hierarchy */
  --text-primary: #e0e0ee;
  --text-secondary: #8888aa;
  --text-tertiary: #555570;
  --text-label: #6a6a88;

  /* Status colors */
  --status-green: #00ff41;
  --status-amber: #ffb000;
  --status-red: #ff0040;
  --status-cyan: #00d4ff;

  /* Accent (used sparingly) */
  --accent-blue: #3366ff;
  --accent-blue-dim: #2244aa;

  /* Typography */
  --font-mono: "JetBrains Mono", "Fira Code", "SF Mono", "Cascadia Code", "Consolas", monospace;
  --font-system: system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Sizing */
  --card-radius: 2px;
  --header-height: 56px;
  --summary-height: 44px;

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-medium: 200ms ease;
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font-system);
  line-height: 1.5;
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Utility classes
   -------------------------------------------------------------------------- */
.mono {
  font-family: var(--font-mono);
}

.text-secondary {
  color: var(--text-secondary);
}

.text-tertiary {
  color: var(--text-tertiary);
}

.text-green { color: var(--status-green); }
.text-amber { color: var(--status-amber); }
.text-red   { color: var(--status-red); }
.text-cyan  { color: var(--status-cyan); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 20px;
  border-bottom: 1px solid var(--border-medium);
  background: var(--bg-panel);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.update-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.update-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-green);
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.update-dot.fetching {
  animation: pulse-dot 1s ease infinite;
}

/* --------------------------------------------------------------------------
   Polliwog SVG (tadpole mascot)
   -------------------------------------------------------------------------- */
.polliwog-svg {
  width: 32px;
  height: 20px;
  flex-shrink: 0;
}

.polliwog-svg .head {
  fill: var(--text-secondary);
  transition: fill var(--transition-medium);
}

.polliwog-svg .tail {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke var(--transition-medium);
}

.polliwog-svg.all-healthy .head {
  fill: var(--status-green);
}

.polliwog-svg.all-healthy .tail {
  stroke: var(--status-green);
  animation: wiggle-tail 2s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Section headers
   -------------------------------------------------------------------------- */
.section-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border-subtle);
}

/* --------------------------------------------------------------------------
   Card grid
   -------------------------------------------------------------------------- */
.card-grid {
  display: grid;
  gap: 1px;
  background: var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.card-grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.card-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* --------------------------------------------------------------------------
   Collector card
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
  user-select: none;
}

.card:hover {
  background: var(--bg-card-hover);
}

.card:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
  z-index: 1;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-name {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-status-dot.healthy {
  background: var(--status-green);
  box-shadow: 0 0 6px var(--status-green);
  animation: pulse-glow-green 3s ease-in-out infinite;
}

.card-status-dot.warning {
  background: var(--status-amber);
  box-shadow: 0 0 6px var(--status-amber);
  animation: pulse-glow-amber 2s ease-in-out infinite;
}

.card-status-dot.error {
  background: var(--status-red);
  box-shadow: 0 0 6px var(--status-red);
}

.card-status-dot.unknown {
  background: var(--text-tertiary);
}

.card-metric {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.card-metric-value {
  color: var(--text-primary);
  font-weight: 500;
}

.card-metric-label {
  color: var(--text-label);
  margin-left: 4px;
}

.card-age {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

/* --------------------------------------------------------------------------
   Card expanded detail
   -------------------------------------------------------------------------- */
.card-detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.card.expanded .card-detail {
  display: block;
}

.card-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.card-detail-key {
  color: var(--text-label);
}

.card-detail-val {
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Summary bar (bottom)
   -------------------------------------------------------------------------- */
.summary-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--summary-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-medium);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  z-index: 100;
}

.summary-stats {
  display: flex;
  gap: 24px;
}

.summary-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.summary-stat-value {
  color: var(--text-primary);
  font-weight: 600;
}

.summary-actions {
  display: flex;
  gap: 8px;
}

/* Content needs bottom padding so summary bar doesn't cover cards */
.main-content {
  padding-bottom: calc(var(--summary-height) + 4px);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  border-radius: var(--card-radius);
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-blue-dim);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
}

.btn:active {
  background: var(--border-medium);
}

/* --------------------------------------------------------------------------
   Log viewer overlay
   -------------------------------------------------------------------------- */
.log-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 200;
  flex-direction: column;
}

.log-overlay.visible {
  display: flex;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-medium);
  background: var(--bg-panel);
  gap: 12px;
}

.log-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.log-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.log-select {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 5px 10px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--card-radius);
  cursor: pointer;
}

.log-select:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
}

.log-close {
  font-family: var(--font-mono);
  font-size: 1rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.log-close:hover {
  color: var(--text-primary);
}

.log-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.65;
  color: var(--text-secondary);
  background: var(--bg-root);
}

.log-line {
  white-space: pre-wrap;
  word-break: break-all;
}

/* Log level coloring */
.log-line.level-error {
  color: var(--status-red);
}

.log-line.level-warn {
  color: var(--status-amber);
}

.log-line.level-info {
  color: var(--text-primary);
}

.log-line.level-debug {
  color: var(--text-tertiary);
}

.log-empty {
  color: var(--text-tertiary);
  font-style: italic;
  padding: 40px 0;
  text-align: center;
}

.log-loading {
  color: var(--text-tertiary);
  padding: 40px 0;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Loading / error states
   -------------------------------------------------------------------------- */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-tertiary);
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--status-red);
  text-align: center;
  gap: 12px;
}

.error-state .error-detail {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  max-width: 400px;
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes pulse-glow-green {
  0%, 100% { box-shadow: 0 0 4px var(--status-green); opacity: 1; }
  50%      { box-shadow: 0 0 10px var(--status-green); opacity: 0.8; }
}

@keyframes pulse-glow-amber {
  0%, 100% { box-shadow: 0 0 4px var(--status-amber); opacity: 1; }
  50%      { box-shadow: 0 0 10px var(--status-amber); opacity: 0.85; }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 0.3; }
}

@keyframes wiggle-tail {
  0%   { d: path("M16 10 C20 6, 24 14, 28 10"); }
  25%  { d: path("M16 10 C20 14, 24 6, 28 10"); }
  50%  { d: path("M16 10 C20 6, 24 14, 28 10"); }
  75%  { d: path("M16 10 C20 14, 24 6, 28 10"); }
  100% { d: path("M16 10 C20 6, 24 14, 28 10"); }
}

/* Fallback wiggle for browsers that don't support animating d: */
@keyframes wiggle-tail-transform {
  0%, 100% { transform: scaleY(1); }
  25%      { transform: scaleY(-1); }
  50%      { transform: scaleY(1); }
  75%      { transform: scaleY(-1); }
}

/* --------------------------------------------------------------------------
   Scanline effect (very subtle, atmosphere only)
   -------------------------------------------------------------------------- */
.main-content::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  z-index: 999;
}

/* --------------------------------------------------------------------------
   Responsive: tablet (< 900px)
   -------------------------------------------------------------------------- */
@media (max-width: 899px) {
  .card-grid.cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-grid.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-stats {
    gap: 16px;
  }

  .summary-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 16px;
    gap: 8px;
  }

  .main-content {
    padding-bottom: 68px;
  }
}

/* --------------------------------------------------------------------------
   Responsive: mobile (< 600px)
   -------------------------------------------------------------------------- */
@media (max-width: 599px) {
  html {
    font-size: 13px;
  }

  .header {
    padding: 0 12px;
  }

  .header-title {
    font-size: 0.85rem;
  }

  .card-grid.cols-4,
  .card-grid.cols-3 {
    grid-template-columns: 1fr;
  }

  .section-label {
    padding: 10px 12px 6px;
  }

  .card {
    padding: 12px;
  }

  .summary-bar {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px;
    gap: 6px;
  }

  .summary-stats {
    flex-wrap: wrap;
    gap: 12px;
  }

  .summary-actions {
    width: 100%;
  }

  .summary-actions .btn {
    flex: 1;
    text-align: center;
  }

  .main-content {
    padding-bottom: 100px;
  }

  .log-header {
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .log-body {
    padding: 10px 12px;
  }
}

/* --------------------------------------------------------------------------
   Login page (self-contained)
   -------------------------------------------------------------------------- */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--bg-root);
}

.login-box {
  width: 320px;
  padding: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border-medium);
  border-radius: var(--card-radius);
}

.login-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-title {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.login-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-label);
  margin-bottom: 6px;
}

.login-input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--card-radius);
  margin-bottom: 16px;
}

.login-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px var(--accent-blue-dim);
}

.login-btn {
  display: block;
  width: 100%;
  padding: 9px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--card-radius);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.login-btn:hover {
  background: var(--accent-blue-dim);
}

.login-btn:focus-visible {
  outline: 2px solid var(--status-cyan);
  outline-offset: 2px;
}

.login-error {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--status-red);
  margin-top: 12px;
  display: none;
}

.login-error.visible {
  display: block;
}

/* --------------------------------------------------------------------------
   Print (just in case someone screenshots via print)
   -------------------------------------------------------------------------- */
@media print {
  .summary-bar,
  .log-overlay,
  .main-content::before {
    display: none;
  }

  body {
    background: #fff;
    color: #111;
  }

  .card {
    border: 1px solid #ccc;
  }
}
