/* ============================================
   Tower Monitoring System — Design System
   Dark industrial theme with glassmorphism
   ============================================ */

/* Google Font Import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================
   CSS Custom Properties (Design Tokens)
   ========================================== */
:root {
  /* Background */
  --bg-primary: #06090f;
  --bg-secondary: #0c1120;
  --bg-tertiary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(17, 24, 39, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(0, 229, 255, 0.3);

  /* Text */
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #00e5ff;

  /* Accent Colors */
  --accent-cyan: #00e5ff;
  --accent-cyan-dim: rgba(0, 229, 255, 0.15);
  --accent-green: #00e676;
  --accent-green-dim: rgba(0, 230, 118, 0.15);
  --accent-orange: #ff9100;
  --accent-orange-dim: rgba(255, 145, 0, 0.15);
  --accent-red: #ff1744;
  --accent-red-dim: rgba(255, 23, 68, 0.15);
  --accent-purple: #b388ff;
  --accent-purple-dim: rgba(179, 136, 255, 0.15);

  /* Status Colors */
  --status-normal: #00e676;
  --status-warning: #ff9100;
  --status-danger: #ff1744;
  --status-offline: #64748b;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow-cyan: 0 0 20px rgba(0, 229, 255, 0.15);
  --shadow-glow-green: 0 0 20px rgba(0, 230, 118, 0.15);
  --shadow-glow-red: 0 0 20px rgba(255, 23, 68, 0.2);

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

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated background gradient */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 20% 20%, rgba(0, 229, 255, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(179, 136, 255, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse 50% 50% at 50% 50%, rgba(0, 230, 118, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ==========================================
   Scrollbar
   ========================================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ==========================================
   Layout
   ========================================== */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-lg);
}

/* ==========================================
   Header
   ========================================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  animation: slideDown 0.6s ease;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-glow-cyan);
}

.header-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-info .tower-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 500;
}

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

.connection-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--accent-green-dim);
  color: var(--accent-green);
  border: 1px solid rgba(0, 230, 118, 0.2);
}

.connection-status.offline {
  background: var(--accent-red-dim);
  color: var(--accent-red);
  border-color: rgba(255, 23, 68, 0.2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

.connection-status.offline .status-dot {
  animation: none;
}

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

/* ==========================================
   Alert Banner
   ========================================== */
.alert-banner {
  display: none;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xl);
  background: linear-gradient(90deg, var(--accent-red-dim), rgba(255, 23, 68, 0.05));
  border: 1px solid rgba(255, 23, 68, 0.3);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  animation: alertFlash 1s ease infinite alternate;
}

.alert-banner.active {
  display: flex;
}

.alert-banner.warning {
  background: linear-gradient(90deg, var(--accent-orange-dim), rgba(255, 145, 0, 0.05));
  border-color: rgba(255, 145, 0, 0.3);
  animation: none;
}

.alert-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.alert-content {
  flex: 1;
}

.alert-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-red);
}

.alert-banner.warning .alert-title {
  color: var(--accent-orange);
}

.alert-message {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.alert-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-red);
  text-align: right;
  min-width: 80px;
}

.alert-banner.warning .alert-value {
  color: var(--accent-orange);
}

/* ==========================================
   Main Grid Layout
   ========================================== */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: var(--space-lg);
}

.main-grid .tower-3d-section {
  grid-column: 1;
  grid-row: 1 / 3;
}

.main-grid .gauges-section {
  grid-column: 2;
  grid-row: 1;
}

.main-grid .sensor-cards-section {
  grid-column: 2;
  grid-row: 2;
}

.main-grid .chart-section {
  grid-column: 1 / -1;
  grid-row: 3;
}

/* ==========================================
   Card Component
   ========================================== */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
  animation: fadeInUp 0.5s ease both;
}

.card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-title-icon {
  font-size: 1rem;
}

.card-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-badge.live {
  background: var(--accent-green-dim);
  color: var(--accent-green);
  border: 1px solid rgba(0, 230, 118, 0.2);
  animation: pulse 2s infinite;
}

/* ==========================================
   3D Tower View
   ========================================== */
.tower-3d-container {
  width: 100%;
  height: 480px;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  background: radial-gradient(ellipse at center, rgba(0, 229, 255, 0.03) 0%, transparent 70%);
}

.tower-3d-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.tower-3d-overlay {
  position: absolute;
  bottom: var(--space-md);
  left: var(--space-md);
  display: flex;
  gap: var(--space-sm);
}

.tower-3d-label {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* ==========================================
   Gauge Section
   ========================================== */
.gauges-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
}

.gauge-item {
  text-align: center;
}

.gauge-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto var(--space-sm);
}

.gauge-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 8;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent-cyan);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease;
}

.gauge-fill.warning {
  stroke: var(--accent-orange);
}

.gauge-fill.danger {
  stroke: var(--accent-red);
}

.gauge-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.gauge-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

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

/* ==========================================
   Sensor Data Cards
   ========================================== */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.sensor-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.sensor-item:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-default);
}

.sensor-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.sensor-icon.accel {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
}

.sensor-icon.gyro {
  background: var(--accent-purple-dim);
  color: var(--accent-purple);
}

.sensor-icon.temp {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

.sensor-info {
  flex: 1;
  min-width: 0;
}

.sensor-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sensor-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sensor-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 2px;
}

/* ==========================================
   Chart Section
   ========================================== */
.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
}

.chart-tabs {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.chart-tab {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.chart-tab:hover {
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.chart-tab.active {
  background: var(--accent-cyan-dim);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* ==========================================
   History Section
   ========================================== */
.history-section {
  margin-top: var(--space-lg);
  animation: fadeInUp 0.5s ease both;
  animation-delay: 0.3s;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

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

.filter-input {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 8px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
}

.filter-input:focus {
  border-color: var(--accent-cyan);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), #0099cc);
  color: var(--bg-primary);
  border-color: transparent;
}

.btn-primary:hover {
  box-shadow: var(--shadow-glow-cyan);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-glass);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn-danger {
  background: var(--accent-red-dim);
  color: var(--accent-red);
  border-color: rgba(255, 23, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(255, 23, 68, 0.25);
}

.btn-simulate {
  background: linear-gradient(135deg, var(--accent-purple), #7c4dff);
  color: white;
  border-color: transparent;
  animation: shimmer 3s infinite;
}

.btn-simulate:hover {
  box-shadow: 0 0 20px rgba(179, 136, 255, 0.3);
  transform: translateY(-1px);
}

/* Table */
.history-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.history-table thead {
  background: rgba(255, 255, 255, 0.03);
}

.history-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.history-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.history-table tbody tr {
  transition: background var(--transition-fast);
}

.history-table tbody tr:hover {
  background: var(--bg-glass-hover);
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-sans);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.normal {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.status-badge.warning {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

.status-badge.danger {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.page-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.page-btn:hover {
  border-color: var(--border-default);
  color: var(--text-primary);
  background: var(--bg-glass);
}

.page-btn.active {
  background: var(--accent-cyan-dim);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 var(--space-sm);
}

/* ==========================================
   Simulation Controls
   ========================================== */
.sim-controls {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.4s ease;
}

.sim-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: var(--space-sm);
}

.sim-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--accent-purple);
  font-weight: 500;
}

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

/* ==========================================
   Empty State
   ========================================== */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-xl);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.9rem;
  margin-bottom: var(--space-sm);
}

.empty-state-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes alertFlash {
  from {
    box-shadow: 0 0 0 0 rgba(255, 23, 68, 0.1);
  }
  to {
    box-shadow: 0 0 30px 0 rgba(255, 23, 68, 0.15);
  }
}

@keyframes shimmer {
  0% { box-shadow: 0 0 5px rgba(179, 136, 255, 0.1); }
  50% { box-shadow: 0 0 15px rgba(179, 136, 255, 0.2); }
  100% { box-shadow: 0 0 5px rgba(179, 136, 255, 0.1); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ==========================================
   Responsive Design
   ========================================== */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .main-grid .tower-3d-section {
    grid-column: 1;
    grid-row: auto;
  }

  .main-grid .gauges-section,
  .main-grid .sensor-cards-section,
  .main-grid .chart-section {
    grid-column: 1;
    grid-row: auto;
  }

  .tower-3d-container {
    height: 380px;
  }
}

@media (max-width: 768px) {
  .app-container {
    padding: var(--space-md);
  }

  .header {
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
  }

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

  .gauges-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
  }

  .gauge-wrapper {
    width: 90px;
    height: 90px;
  }

  .gauge-value {
    font-size: 1rem;
  }

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

  .tower-3d-container {
    height: 300px;
  }

  .history-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .history-filters {
    flex-wrap: wrap;
  }

  .chart-container {
    height: 220px;
  }

  .alert-banner {
    flex-direction: column;
    text-align: center;
  }

  .sim-controls {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .gauges-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .gauge-wrapper {
    width: 75px;
    height: 75px;
  }

  .gauge-value {
    font-size: 0.85rem;
  }

  .card {
    padding: var(--space-md);
  }
}
