/* ==========================================================================
   style.css — Project 28: CDN Cache Hit Indicator
   Dark theme with neon green LED glow effect
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Background palette */
  --bg-primary:    #1a1a2e;   /* deep navy — page background */
  --bg-secondary:  #16213e;   /* slightly lighter — card background */
  --bg-card:       #0f3460;   /* accent navy — panel headers */
  --bg-input:      #1a2744;   /* input / table row backgrounds */

  /* Text */
  --text-primary:   #e0e0e0;
  --text-secondary: #9e9e9e;
  --text-muted:     #616161;

  /* Accent colours */
  --accent-blue:   #4fc3f7;
  --accent-green:  #00ff88;
  --accent-orange: #ff9800;
  --accent-purple: #ce93d8;
  --accent-red:    #ef5350;

  /* LED colours */
  --led-on-color:  #00ff88;
  --led-off-color: #424242;
  --led-glow:      0 0 20px #00ff88, 0 0 40px #00cc66, 0 0 60px #009944;

  /* Card borders */
  --border-subtle: rgba(255, 255, 255, 0.07);

  /* Timing */
  --transition-fast:   0.2s ease;
  --transition-medium: 0.4s ease;
  --transition-slow:   0.8s ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
header {
  background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
  border-bottom: 1px solid var(--border-subtle);
  padding: 1.5rem 2rem;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-green);
  letter-spacing: 0.02em;
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

header .subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.25rem;
  font-style: italic;
}

/* Live indicator dot */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: 20px;
  padding: 0.2rem 0.75rem;
  font-size: 0.75rem;
  color: var(--accent-green);
  margin-top: 0.5rem;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

/* --------------------------------------------------------------------------
   Main Layout
   -------------------------------------------------------------------------- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Top row: ESP32 panel + Stats grid */
.top-row {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 800px) {
  .top-row {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.card-header {
  background: var(--bg-card);
  padding: 0.75rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.card-body {
  padding: 1.5rem;
}

/* --------------------------------------------------------------------------
   ESP32 Virtual Board Panel
   -------------------------------------------------------------------------- */
.esp32-panel {
  /* inherits .card */
}

.esp32-board {
  background: #0d1117;
  border: 2px solid #30363d;
  border-radius: 10px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  position: relative;
}

/* Board label */
.board-label {
  font-family: 'Courier New', monospace;
  font-size: 0.65rem;
  color: #8b949e;
  letter-spacing: 0.15em;
  text-align: center;
}

/* GPIO pin strip (decorative) */
.gpio-strip {
  display: flex;
  gap: 4px;
  margin: 0.5rem 0;
}

.gpio-pin {
  width: 6px;
  height: 14px;
  background: #d4a017;
  border-radius: 2px;
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   Virtual LED
   -------------------------------------------------------------------------- */
.led-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.led-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--led-off-color);
  border: 3px solid #555;
  transition: background var(--transition-medium),
              box-shadow var(--transition-medium),
              border-color var(--transition-medium);
  position: relative;
  cursor: default;
}

/* Inner shine effect */
.led-circle::before {
  content: '';
  position: absolute;
  top: 12%;
  left: 15%;
  width: 35%;
  height: 35%;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  transition: background var(--transition-medium);
}

/* HIT state — green glow */
.led-circle.led-on {
  background: var(--led-on-color);
  border-color: #00cc66;
  box-shadow: var(--led-glow);
}

.led-circle.led-on::before {
  background: rgba(255, 255, 255, 0.4);
}

/* Pulse animation on HIT */
.led-circle.led-pulse {
  animation: led-pulse-anim 0.6s ease-out;
}

@keyframes led-pulse-anim {
  0%   { transform: scale(1);    box-shadow: var(--led-glow); }
  30%  { transform: scale(1.15); box-shadow: 0 0 40px #00ff88, 0 0 80px #00cc66; }
  60%  { transform: scale(0.97); }
  100% { transform: scale(1);    box-shadow: var(--led-glow); }
}

.led-label {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: color var(--transition-medium);
  color: var(--text-muted);
}

.led-label.hit  { color: var(--accent-green); }
.led-label.miss { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast),
              filter var(--transition-fast);
  letter-spacing: 0.03em;
  width: 100%;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, #00c76a, #00ff88);
  color: #000;
  box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(0, 255, 136, 0.5);
}

.btn-danger {
  background: linear-gradient(135deg, #c62828, #ef5350);
  color: #fff;
  box-shadow: 0 4px 15px rgba(239, 83, 80, 0.3);
}

.btn-danger:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(239, 83, 80, 0.5);
}

.btn-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.5rem;
}

/* --------------------------------------------------------------------------
   Stats Grid (right panel)
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1rem;
}

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

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}

/* Coloured left accent bar */
.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 12px 0 0 12px;
}

.stat-card.blue::before   { background: var(--accent-blue); }
.stat-card.green::before  { background: var(--accent-green); }
.stat-card.orange::before { background: var(--accent-orange); }
.stat-card.purple::before { background: var(--accent-purple); }

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
}

.stat-card.blue   .stat-value { color: var(--accent-blue); }
.stat-card.green  .stat-value { color: var(--accent-green); }
.stat-card.orange .stat-value { color: var(--accent-orange); }
.stat-card.purple .stat-value { color: var(--accent-purple); }

.stat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   History Table
   -------------------------------------------------------------------------- */
.history-card {
  margin-top: 0;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 0 0 12px 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

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

tbody tr:hover {
  background: var(--bg-input);
}

tbody tr.new-row {
  animation: row-flash 0.6s ease-out;
}

@keyframes row-flash {
  0%   { background: rgba(0, 255, 136, 0.15); }
  100% { background: transparent; }
}

tbody td {
  padding: 0.65rem 1rem;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-hit {
  background: rgba(0, 255, 136, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(0, 255, 136, 0.3);
}

.badge-miss {
  background: rgba(239, 83, 80, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 83, 80, 0.3);
}

/* Response time colouring */
.rt-fast { color: var(--accent-green); }
.rt-slow { color: var(--accent-orange); }

/* X-Cache header monospace */
.x-cache-val {
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Empty state */
.empty-row td {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2rem;
}

/* --------------------------------------------------------------------------
   Dual-Mode Status Badge (Header)
   -------------------------------------------------------------------------- */
.mode-badge-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 0.6rem;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all var(--transition-medium);
}

.mode-badge.simulation {
  background: rgba(255, 152, 0, 0.12);
  border: 1px solid rgba(255, 152, 0, 0.4);
  color: var(--accent-orange);
}

.mode-badge.simulation .mode-dot {
  background: var(--accent-orange);
  box-shadow: 0 0 8px rgba(255, 152, 0, 0.6);
}

.mode-badge.real-aws {
  background: rgba(0, 255, 136, 0.15);
  border: 1px solid rgba(0, 255, 136, 0.5);
  color: var(--accent-green);
  box-shadow: 0 0 15px rgba(0, 255, 136, 0.2);
}

.mode-badge.real-aws .mode-dot {
  background: var(--accent-green);
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.8);
}

.mode-badge.real-cloudflare {
  background: rgba(243, 128, 32, 0.18);
  border: 1px solid rgba(243, 128, 32, 0.6);
  color: #ff9d42;
  box-shadow: 0 0 15px rgba(243, 128, 32, 0.25);
}

.mode-badge.real-cloudflare .mode-dot {
  background: #f38020;
  box-shadow: 0 0 10px rgba(243, 128, 32, 0.9);
}

.mode-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  animation: pulse-dot 1.5s infinite;
}

/* --------------------------------------------------------------------------
   Config & Cache Testing Controls Card
   -------------------------------------------------------------------------- */
.config-card {
  margin-bottom: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.config-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.config-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-blue);
  letter-spacing: 0.04em;
}

.input-with-button {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.text-input {
  flex: 1;
  min-width: 220px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.text-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.3);
}

.btn-success {
  background: linear-gradient(135deg, #00b0ff, #0081cb);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 176, 255, 0.3);
  width: auto;
  padding: 0.6rem 1rem;
}

.btn-success:hover {
  filter: brightness(1.15);
}

.btn-secondary {
  background: #37474f;
  color: #eceff1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: auto;
  padding: 0.6rem 1rem;
}

.btn-secondary:hover {
  background: #455a64;
}

.btn-warning {
  background: linear-gradient(135deg, #f57c00, #ff9800);
  color: #000;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(255, 152, 0, 0.3);
}

.btn-warning:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(255, 152, 0, 0.5);
}

.btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 600px) {
  .btn-group {
    grid-template-columns: 1fr;
  }
}

.url-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  word-break: break-all;
}

.status-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-orange);
  display: inline-block;
}

.status-indicator-dot.active-aws {
  background: var(--accent-green);
  box-shadow: 0 0 6px var(--accent-green);
}

.target-url-text {
  font-family: 'Courier New', monospace;
  color: var(--accent-blue);
  font-weight: 600;
}

.url-feedback-text {
  font-size: 0.75rem;
  min-height: 1.2rem;
  font-weight: 600;
}

.url-feedback-text.success { color: var(--accent-green); }
.url-feedback-text.error { color: var(--accent-red); }

.cache-bust-explanation {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid var(--accent-orange);
}

.cache-bust-explanation code {
  color: var(--accent-orange);
  background: rgba(255, 152, 0, 0.1);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
}

/* --------------------------------------------------------------------------
   Live Metadata & Edge Telemetry Card
   -------------------------------------------------------------------------- */
.metadata-card {
  margin-bottom: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.meta-item {
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.meta-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.meta-value {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: #fff;
  font-weight: 600;
}

.meta-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alert-error {
  background: rgba(239, 83, 80, 0.15);
  border: 1px solid rgba(239, 83, 80, 0.5);
  color: var(--accent-red);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-bottom: 1rem;
  line-height: 1.4;
  font-weight: 600;
}

.alert-info {
  background: rgba(79, 195, 247, 0.15);
  border: 1px solid rgba(79, 195, 247, 0.5);
  color: var(--accent-blue);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-bottom: 1rem;
  line-height: 1.5;
  font-weight: 500;
}

/* Mode badges in History Table */
.badge-sim {
  background: rgba(255, 152, 0, 0.15);
  color: var(--accent-orange);
  border: 1px solid rgba(255, 152, 0, 0.3);
}

.badge-aws {
  background: rgba(0, 255, 136, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(0, 255, 136, 0.3);
}

.badge-cf, .badge-cloudflare {
  background: rgba(243, 128, 32, 0.18);
  color: #ff9d42;
  border: 1px solid rgba(243, 128, 32, 0.4);
}

.badge-expired {
  background: rgba(255, 193, 7, 0.2);
  color: #ffd54f;
  border: 1px solid rgba(255, 193, 7, 0.4);
}

.badge-revalidated {
  background: rgba(33, 150, 243, 0.2);
  color: #64b5f6;
  border: 1px solid rgba(33, 150, 243, 0.4);
}

.badge-dynamic {
  background: rgba(156, 39, 176, 0.2);
  color: #ba68c8;
  border: 1px solid rgba(156, 39, 176, 0.4);
}

.badge-bypass {
  background: rgba(120, 144, 156, 0.2);
  color: #b0bec5;
  border: 1px solid rgba(120, 144, 156, 0.4);
}

.mode-selector-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.mode-tab-btn {
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-tab-btn:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.mode-tab-btn.active {
  background: rgba(0, 255, 136, 0.12);
  color: var(--accent-green);
  border-color: var(--accent-green);
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.15);
}

.mode-tab-btn.active.cf-tab {
  background: rgba(243, 128, 32, 0.14);
  color: #ff9d42;
  border-color: #f38020;
  box-shadow: 0 0 10px rgba(243, 128, 32, 0.2);
}

.mode-tab-btn.active.sim-tab {
  background: rgba(255, 152, 0, 0.12);
  color: var(--accent-orange);
  border-color: var(--accent-orange);
  box-shadow: 0 0 10px rgba(255, 152, 0, 0.2);
}

.badge-err {
  background: rgba(239, 83, 80, 0.25);
  color: #ff8a80;
  border: 1px solid var(--accent-red);
}

/* LED Error State */
.led-circle.led-error {
  background: var(--accent-red);
  border-color: #d32f2f;
  box-shadow: 0 0 25px var(--accent-red);
}

.led-label.err {
  color: var(--accent-red);
}

/* --------------------------------------------------------------------------
   Utility classes
   -------------------------------------------------------------------------- */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
