/* ============================================================
   NexWatch Station Dashboard
   TTC DEV - Nexstar Media Group
   ============================================================ */

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --card: #161616;
  --card-hover: #1a1a1a;
  --border: #222222;
  --border-light: #2a2a2a;
  --text: #e5e5e5;
  --text-secondary: #999999;
  --text-muted: #666666;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.15);
  --yellow: #f59e0b;
  --yellow-dim: rgba(245, 158, 11, 0.15);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.15);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

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

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-header {
  margin-bottom: 32px;
}

.login-brand {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
}

.login-callsign {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
  margin-bottom: 32px;
}

.pin-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pin-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.pin-inputs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.pin-digit {
  width: 52px;
  height: 60px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pin-digit:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
}

.login-error {
  color: var(--red);
  font-size: 0.8125rem;
  min-height: 20px;
  margin-bottom: 16px;
}

.login-btn {
  width: 100%;
  padding: 12px 24px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.login-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.login-btn:not(:disabled):hover {
  background: #2563eb;
}

.login-footer {
  margin-top: 32px;
  font-size: 0.8125rem;
}

.login-footer a {
  color: var(--text-muted);
}

.login-footer a:hover {
  color: var(--text-secondary);
}

/* ============================================================
   DASHBOARD LAYOUT
   ============================================================ */

.dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.topbar-brand {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--blue);
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.topbar-callsign {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-status {
  font-size: 0.8125rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.topbar-status.degraded::before {
  background: var(--yellow);
}

.topbar-status.down::before {
  background: var(--red);
}

.logout-btn {
  padding: 6px 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--border-light);
}

/* Tab Navigation */
.tab-nav {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

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

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--blue);
}

/* Tab Content */
.tab-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* ============================================================
   OVERVIEW TAB
   ============================================================ */

.overview-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.overview-station-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.overview-station-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.overview-market {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.overview-affiliate {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.overview-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.overview-big-number {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.1;
  margin-top: 8px;
}

.overview-big-number.good { color: var(--green); }
.overview-big-number.warn { color: var(--yellow); }
.overview-big-number.bad { color: var(--red); }

.overview-chart-card .sparkline-container {
  height: 120px;
  width: 100%;
}

.sparkline-container svg {
  width: 100%;
  height: 100%;
}

/* ============================================================
   PERFORMANCE TAB
   ============================================================ */

.perf-gauges {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

.gauge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
}

.gauge-wrap {
  width: 160px;
  height: 160px;
  margin-bottom: 16px;
}

.gauge-wrap canvas {
  width: 100%;
  height: 100%;
}

.gauge-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.gauge-value {
  font-size: 1.75rem;
  font-weight: 700;
}

.gauge-value.good { color: var(--green); }
.gauge-value.warn { color: var(--yellow); }
.gauge-value.bad { color: var(--red); }

.cwv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.cwv-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.cwv-metric {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.cwv-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.cwv-value.good { color: var(--green); }
.cwv-value.warn { color: var(--yellow); }
.cwv-value.bad { color: var(--red); }

.cwv-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.chart-container {
  width: 100%;
  min-height: 200px;
}

.chart-container svg {
  width: 100%;
  height: auto;
}

/* ============================================================
   AGREEMENTS TAB
   ============================================================ */

.agreements-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.agreement-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.agreement-item:hover {
  border-color: var(--border-light);
}

.agreement-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.agreement-name {
  font-size: 0.9375rem;
  font-weight: 500;
}

.agreement-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.agreement-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agreement-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 4px;
}

.agreement-badge.draft {
  background: var(--blue-dim);
  color: var(--blue);
}

.agreement-badge.sent {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.agreement-badge.executed {
  background: var(--green-dim);
  color: var(--green);
}

.agreement-download {
  padding: 6px 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.8125rem;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}

.agreement-download:hover {
  color: var(--text);
  border-color: var(--border-light);
  text-decoration: none;
}

/* ============================================================
   MESSAGES TAB
   ============================================================ */

.messages-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 400px;
}

.messages-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.9375rem;
  line-height: 1.5;
  position: relative;
}

.message-bubble.client {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-bubble.ttc {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message-sender {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.8;
}

.message-bubble.ttc .message-sender {
  color: var(--blue);
}

.message-text {
  word-wrap: break-word;
}

.message-time {
  font-size: 0.6875rem;
  margin-top: 6px;
  opacity: 0.6;
}

.message-compose {
  display: flex;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.message-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  padding: 12px 16px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  min-height: 44px;
  max-height: 120px;
}

.message-input:focus {
  border-color: var(--blue);
}

.message-input::placeholder {
  color: var(--text-muted);
}

.message-send-btn {
  padding: 12px 24px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.message-send-btn:hover {
  background: #2563eb;
}

.message-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   DEMO SITE TAB
   ============================================================ */

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

.demo-site-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.demo-open-btn {
  padding: 8px 20px;
  background: var(--blue);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}

.demo-open-btn:hover {
  background: #2563eb;
  text-decoration: none;
}

.demo-iframe-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  aspect-ratio: 16 / 10;
}

.demo-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ============================================================
   STATUS PAGE (PUBLIC)
   ============================================================ */

.status-page {
  background: var(--bg);
}

.status-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px;
}

.status-header {
  text-align: center;
  margin-bottom: 32px;
}

.status-brand {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 8px;
}

.status-station-name {
  font-size: 1.75rem;
  font-weight: 700;
}

.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.status-dot-lg.operational { background: var(--green); box-shadow: 0 0 8px var(--green-dim); }
.status-dot-lg.degraded { background: var(--yellow); box-shadow: 0 0 8px var(--yellow-dim); }
.status-dot-lg.down { background: var(--red); box-shadow: 0 0 8px var(--red-dim); }

.status-text-lg {
  font-size: 1.125rem;
  font-weight: 600;
}

.status-uptime-badge {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-chart-card {
  margin-bottom: 24px;
}

.status-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.status-stat-card {
  text-align: center;
  padding: 20px;
}

.status-stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.status-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.status-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 32px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.status-last-updated {
  color: var(--text-muted);
}

/* ============================================================
   SHARED: INCIDENTS
   ============================================================ */

.incident-list-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.incident-item {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

.incident-title {
  font-size: 0.9375rem;
  font-weight: 500;
}

.incident-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.severity-tag {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 4px;
}

.severity-tag.low { background: var(--blue-dim); color: var(--blue); }
.severity-tag.medium { background: var(--yellow-dim); color: var(--yellow); }
.severity-tag.high { background: var(--red-dim); color: var(--red); }
.severity-tag.critical { background: var(--red); color: #fff; }

.timeline {
  margin-top: 12px;
  padding-left: 16px;
  border-left: 2px solid var(--border);
}

.timeline-event {
  padding: 8px 0 8px 16px;
  position: relative;
}

.timeline-event::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-light);
  border: 2px solid var(--card);
}

.timeline-event.active::before {
  background: var(--blue);
}

.timeline-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.timeline-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* ============================================================
   EMPTY STATES
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-sm {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

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

  .perf-gauges {
    grid-template-columns: repeat(2, 1fr);
  }

  .cwv-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 16px;
    height: 48px;
  }

  .topbar-brand {
    font-size: 0.6875rem;
  }

  .topbar-callsign {
    font-size: 0.9375rem;
  }

  .tab-nav {
    padding: 0 12px;
  }

  .tab-btn {
    padding: 10px 14px;
    font-size: 0.8125rem;
  }

  .tab-content {
    padding: 16px;
  }

  .overview-grid {
    grid-template-columns: 1fr;
  }

  .overview-big-number {
    font-size: 1.75rem;
  }

  .perf-gauges {
    grid-template-columns: repeat(2, 1fr);
  }

  .gauge-wrap {
    width: 120px;
    height: 120px;
  }

  .message-bubble {
    max-width: 90%;
  }

  .messages-card {
    height: calc(100vh - 180px);
  }

  .login-card {
    padding: 32px 24px;
  }

  .pin-digit {
    width: 44px;
    height: 52px;
    font-size: 1.25rem;
  }

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

  .status-banner {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .agreement-item {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .demo-iframe-wrap {
    aspect-ratio: 9 / 16;
  }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tab-panel.active {
  animation: fadeIn 0.2s ease;
}

/* Pulse for status dots */
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

.status-dot-lg.operational {
  animation: pulse-green 2s ease infinite;
}

@keyframes pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

.status-dot-lg.degraded {
  animation: pulse-yellow 2s ease infinite;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.status-dot-lg.down {
  animation: pulse-red 1.5s ease infinite;
}
