/* ==========================================================================
   Direct Media Hub v2 — Mission Control Theme
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  /* Background layers */
  --bg-base: #0a0b0e;
  --bg-surface: #12141a;
  --bg-elevated: #1a1d26;
  --bg-hover: #222630;

  /* Text hierarchy */
  --text-primary: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #555a6e;

  /* Accent colors */
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;

  /* Status */
  --status-ok: var(--accent-green);
  --status-warn: var(--accent-amber);
  --status-error: var(--accent-red);
  --status-info: var(--accent-blue);

  /* Borders */
  --border-subtle: #1e2130;
  --border-default: #2a2e3e;

  /* Typography */
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-display: 'Space Grotesk', var(--font-body);

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 32px;

  /* Widget */
  --widget-radius: 12px;
  --widget-padding: 20px;

  /* Sidebar */
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms 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 {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* --------------------------------------------------------------------------
   Scrollbar Styling
   -------------------------------------------------------------------------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Sidebar Navigation
   -------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-green), #15803d);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: white;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

.sidebar-toggle {
  display: none;
  padding: var(--gap-xs);
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
}

.nav-menu {
  list-style: none;
  padding: var(--gap-md);
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  margin-bottom: var(--gap-xs);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-sm) var(--gap-md);
  border-radius: 8px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active .nav-link {
  background: rgba(34, 197, 94, 0.1);
  color: var(--accent-green);
}

.nav-link svg {
  flex-shrink: 0;
}

.sidebar-footer {
  padding: var(--gap-md) var(--gap-lg);
  border-top: 1px solid var(--border-subtle);
}

.legacy-link {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: 12px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

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

/* --------------------------------------------------------------------------
   Mobile Header (hidden on desktop)
   -------------------------------------------------------------------------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--gap-md);
  align-items: center;
  justify-content: space-between;
  z-index: 99;
}

.mobile-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-lg) var(--gap-xl);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.page-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--gap-lg);
}

.current-time {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-xs) var(--gap-sm);
  background: var(--bg-elevated);
  border-radius: 20px;
}

.status-text {
  font-size: 12px;
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Status Dot
   -------------------------------------------------------------------------- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  position: relative;
}

.status-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

.status-ok {
  background: var(--status-ok);
}

.status-ok::after {
  background: var(--status-ok);
  opacity: 0.3;
}

.status-warn {
  background: var(--status-warn);
}

.status-warn::after {
  background: var(--status-warn);
  opacity: 0.3;
}

.status-error {
  background: var(--status-error);
}

.status-error::after {
  background: var(--status-error);
  opacity: 0.3;
  animation: pulse-error 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.5); opacity: 0; }
}

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

/* --------------------------------------------------------------------------
   Widget Grid
   -------------------------------------------------------------------------- */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--gap-md);
  padding: var(--gap-xl);
  flex: 1;
}

.widget-container {
  min-height: 200px;
}

.col-4 {
  grid-column: span 4;
}

.col-6 {
  grid-column: span 6;
}

.col-12 {
  grid-column: span 12;
}

/* --------------------------------------------------------------------------
   Widget Card
   -------------------------------------------------------------------------- */
.widget-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--widget-radius);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.widget-card:hover {
  border-color: var(--border-default);
}

.widget-card[data-status="warn"] {
  border-color: rgba(245, 158, 11, 0.3);
}

.widget-card[data-status="error"] {
  border-color: rgba(239, 68, 68, 0.3);
}

.widget-header {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-md) var(--widget-padding);
  border-bottom: 1px solid var(--border-subtle);
}

.widget-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.widget-refresh {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 16px;
  transition: all var(--transition-fast);
}

.widget-refresh:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.widget-body {
  flex: 1;
  padding: var(--widget-padding);
}

.widget-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-sm) var(--widget-padding);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
}

.widget-trend {
  font-family: var(--font-mono);
  font-size: 12px;
}

.widget-updated {
  font-size: 11px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Widget Error State
   -------------------------------------------------------------------------- */
.widget-error .widget-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--gap-md);
}

.error-message {
  color: var(--text-secondary);
  font-size: 13px;
}

.retry-btn {
  padding: var(--gap-sm) var(--gap-md);
  background: var(--bg-hover);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.retry-btn:hover {
  background: var(--border-default);
}

/* --------------------------------------------------------------------------
   Skeleton Loader
   -------------------------------------------------------------------------- */
.widget-skeleton {
  height: 100%;
  padding: var(--widget-padding);
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--widget-radius);
}

.skeleton-header {
  height: 20px;
  width: 60%;
  background: var(--bg-elevated);
  border-radius: 4px;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-body {
  flex: 1;
  background: var(--bg-elevated);
  border-radius: 8px;
  animation: shimmer 1.5s ease-in-out infinite;
  animation-delay: 0.1s;
}

.skeleton-footer {
  height: 16px;
  width: 40%;
  background: var(--bg-elevated);
  border-radius: 4px;
  animation: shimmer 1.5s ease-in-out infinite;
  animation-delay: 0.2s;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

.widget-container.loading .widget-card {
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   Metrics Display
   -------------------------------------------------------------------------- */
.metric {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.metric-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.1;
}

.metric-value.large {
  font-size: 48px;
}

.metric-value.small {
  font-size: 24px;
}

.metric-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-row {
  display: flex;
  gap: var(--gap-lg);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-md);
}

/* --------------------------------------------------------------------------
   Trend Indicators
   -------------------------------------------------------------------------- */
.trend-up {
  color: var(--accent-green);
}

.trend-down {
  color: var(--accent-red);
}

.trend-flat {
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Charts & Sparklines
   -------------------------------------------------------------------------- */
.sparkline-container {
  height: 60px;
  margin-top: var(--gap-md);
}

.chart-container {
  position: relative;
  height: 100%;
}

/* --------------------------------------------------------------------------
   Progress Bars & Gauges
   -------------------------------------------------------------------------- */
.progress-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--transition-normal);
}

.progress-fill.ok { background: var(--accent-green); }
.progress-fill.warn { background: var(--accent-amber); }
.progress-fill.error { background: var(--accent-red); }

/* Circular Gauge */
.gauge {
  position: relative;
  width: 100px;
  height: 100px;
}

.gauge-circle {
  transform: rotate(-90deg);
}

.gauge-bg {
  fill: none;
  stroke: var(--bg-hover);
  stroke-width: 8;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent-green);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--transition-normal);
}

.gauge-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Mini Calendar (for Casa widget)
   -------------------------------------------------------------------------- */
.mini-calendar {
  display: flex;
  gap: 2px;
  margin-top: var(--gap-md);
}

.calendar-day {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--bg-hover);
  position: relative;
}

.calendar-day.booked {
  background: var(--accent-green);
}

.calendar-day.available {
  background: var(--bg-hover);
}

.calendar-day.gap {
  background: var(--accent-amber);
}

.calendar-day[title]::before {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.calendar-day:hover[title]::before {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Alert List
   -------------------------------------------------------------------------- */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  margin-top: var(--gap-md);
}

.alert-item {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-sm);
  background: var(--bg-elevated);
  border-radius: 6px;
  font-size: 12px;
}

.alert-item.warn {
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent-amber);
}

.alert-item.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
}

/* --------------------------------------------------------------------------
   System Health Bar
   -------------------------------------------------------------------------- */
.health-bar {
  display: flex;
  align-items: center;
  gap: var(--gap-xl);
  flex-wrap: wrap;
}

.health-item {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.health-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.health-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.health-bars {
  display: flex;
  gap: var(--gap-md);
}

.health-metric {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  min-width: 80px;
}

.health-metric-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.health-metric-bar {
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}

.health-metric-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent-green);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.main-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  padding: var(--gap-md);
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
}

.footer-dot {
  color: var(--border-default);
}

/* --------------------------------------------------------------------------
   Inspector Widget (Agent I1)
   -------------------------------------------------------------------------- */
.inspector-content {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}

.inspector-scores {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.inspector-score-row {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.inspector-score-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 70px;
  flex-shrink: 0;
}

.inspector-score-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-base);
  border-radius: 4px;
  overflow: hidden;
}

.inspector-score-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.inspector-score-fill.score-ok {
  background: var(--accent-green);
}

.inspector-score-fill.score-warning {
  background: var(--accent-amber);
}

.inspector-score-fill.score-critical {
  background: var(--accent-red);
}

.inspector-score-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  width: 65px;
  text-align: right;
  flex-shrink: 0;
}

.inspector-alerts-section {
  background: var(--bg-base);
  border-radius: 8px;
  padding: var(--gap-sm);
}

.inspector-alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--gap-sm);
}

.inspector-alerts-header .section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.inspector-alerts-summary {
  display: flex;
  gap: var(--gap-xs);
}

.alert-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
}

.alert-badge.critical {
  color: var(--accent-red);
}

.alert-badge.warning {
  color: var(--accent-amber);
}

.alert-badge.info {
  color: var(--accent-blue);
}

.inspector-alerts-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
}

.inspector-alert-item {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  padding: 6px 8px;
  background: var(--bg-surface);
  border-radius: 6px;
  font-size: 12px;
}

.inspector-alert-item.critical {
  border-left: 2px solid var(--accent-red);
}

.inspector-alert-item.warning {
  border-left: 2px solid var(--accent-amber);
}

.inspector-alert-item.info {
  border-left: 2px solid var(--accent-blue);
}

.inspector-alert-item .alert-icon {
  font-size: 10px;
  flex-shrink: 0;
}

.inspector-alert-item .alert-title {
  flex: 1;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector-alert-item .alert-time {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.no-alerts {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: var(--gap-sm);
}

.inspector-scan-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: var(--gap-xs);
  border-top: 1px solid var(--border-subtle);
}

/* --------------------------------------------------------------------------
   Responsive: Tablet (< 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .mobile-header {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding-top: 56px;
  }

  .header-bar {
    position: relative;
    top: auto;
  }

  .widget-grid {
    grid-template-columns: repeat(6, 1fr);
    padding: var(--gap-md);
  }

  .col-4 {
    grid-column: span 3;
  }

  .col-6 {
    grid-column: span 6;
  }

  .col-12 {
    grid-column: span 6;
  }
}

/* --------------------------------------------------------------------------
   Responsive: Mobile (< 640px)
   -------------------------------------------------------------------------- */
@media (max-width: 639px) {
  .widget-grid {
    grid-template-columns: 1fr;
    gap: var(--gap-sm);
  }

  .col-4,
  .col-6,
  .col-12 {
    grid-column: span 1;
  }

  .header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--gap-sm);
    padding: var(--gap-md);
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

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

  .metric-value {
    font-size: 24px;
  }

  .metric-value.large {
    font-size: 32px;
  }

  .health-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--gap-md);
  }
}

/* --------------------------------------------------------------------------
   Print Styles
   -------------------------------------------------------------------------- */
@media print {
  .sidebar,
  .mobile-header,
  .widget-refresh,
  .sidebar-toggle {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .main-content {
    margin-left: 0;
  }

  .widget-card {
    background: white;
    border: 1px solid #ddd;
    break-inside: avoid;
  }

  .status-dot::after {
    display: none;
  }

  .widget-footer {
    background: #f5f5f5;
  }

  * {
    animation: none !important;
  }
}
