/* ============================================================================
   AIRMECH MISSION CONTROL — Refined Control Room
   ============================================================================ */

:root {
  /* Brand */
  --blue: #2563EB;
  --blue-light: #3B82F6;
  --blue-dark: #1D4ED8;
  --blue-glow: rgba(37, 99, 235, 0.15);
  --orange: #F97316;
  --orange-glow: rgba(249, 115, 22, 0.12);
  --green: #10B981;
  --green-glow: rgba(16, 185, 129, 0.12);
  --purple: #8B5CF6;
  --purple-glow: rgba(139, 92, 246, 0.12);
  --danger: #EF4444;

  /* Surfaces */
  --bg: #F0F2F5;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --surface-hover: #F8FAFC;

  /* Text */
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;

  /* Borders */
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.1);

  /* Sidebar */
  --sidebar-bg: #0B1120;
  --sidebar-surface: rgba(255, 255, 255, 0.04);
  --sidebar-border: rgba(255, 255, 255, 0.06);
  --sidebar-text: rgba(255, 255, 255, 0.5);
  --sidebar-text-active: #FFFFFF;
  --sidebar-w: 256px;

  /* Depth */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 0 1px var(--blue-glow), 0 4px 16px var(--blue-glow);

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* Timing */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
  font-family: 'Barlow', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-family: 'Calistoga', Georgia, serif; font-weight: 400; }

/* ============================================================================
   LOGIN SCREEN
   ============================================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #070B14;
}

.login-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.login-grid {
  position: absolute;
  inset: -50%;
  background-image:
    linear-gradient(rgba(37, 99, 235, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.07) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: gridDrift 20s linear infinite;
  transform: perspective(600px) rotateX(30deg);
  transform-origin: center 70%;
}

@keyframes gridDrift {
  0% { background-position: 0 0; }
  100% { background-position: 60px 60px; }
}

.login-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.5;
}

.login-glow--1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.4), transparent 70%);
  top: 10%; left: 20%;
  animation: glowFloat1 8s ease-in-out infinite alternate;
}

.login-glow--2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(249, 115, 22, 0.25), transparent 70%);
  bottom: 10%; right: 15%;
  animation: glowFloat2 10s ease-in-out infinite alternate;
}

@keyframes glowFloat1 {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, -30px) scale(1.15); }
}

@keyframes glowFloat2 {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-30px, 20px) scale(1.1); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 380px;
  max-width: calc(100vw - 48px);
  padding: 48px 36px 40px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--r-xl);
  backdrop-filter: blur(24px);
  text-align: center;
  animation: cardIn 0.8s var(--ease-out) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-badge {
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-logo-img {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.login-title {
  font-size: 1.625rem;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.login-sub {
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.8125rem;
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r-md);
  color: #fff;
  font-size: 0.9375rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.login-input:focus {
  border-color: rgba(37, 99, 235, 0.5);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-input::placeholder { color: rgba(255, 255, 255, 0.25); }

.login-submit {
  width: 100%;
  padding: 14px;
  background: var(--blue);
  border: none;
  border-radius: var(--r-md);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.1s var(--ease);
}

.login-submit:hover { background: var(--blue-dark); }
.login-submit:active { transform: scale(0.98); }

.login-submit.loading {
  pointer-events: none;
  opacity: 0.7;
}

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

.login-error {
  color: #F87171;
  font-size: 0.8125rem;
  margin-top: 14px;
  animation: shakeIn 0.4s var(--ease);
}

@keyframes shakeIn {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* ============================================================================
   DASHBOARD LAYOUT
   ============================================================================ */
.dashboard {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ============================================================================
   SIDEBAR
   ============================================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s var(--ease);
  overflow-y: auto;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 22px 18px 18px;
}

.sidebar-logo-img {
  height: 22px;
  width: auto;
  object-fit: contain;
}

.sidebar-section-label {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.2);
  padding: 20px 20px 8px;
}

.sidebar-nav {
  flex: 1;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  border: 1px solid transparent;
  background: none;
  font-family: inherit;
  width: 100%;
  text-align: left;
}

.nav-link:hover {
  color: rgba(255, 255, 255, 0.8);
  background: var(--sidebar-surface);
}

.nav-link.active {
  color: var(--sidebar-text-active);
  background: rgba(37, 99, 235, 0.15);
  border-color: rgba(37, 99, 235, 0.2);
}

.nav-link.active svg { color: var(--blue-light); }

.nav-link--muted {
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.75rem;
}
.nav-link--muted:hover { color: rgba(255, 255, 255, 0.6); }

.sidebar-bottom {
  padding: 12px 10px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ============================================================================
   TOPBAR
   ============================================================================ */
.main {
  grid-column: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 32px;
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.page-title {
  font-size: 1.1875rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

.date-range {
  display: flex;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}

.date-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}

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

.date-btn.active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: var(--shadow-xs);
}

/* ============================================================================
   SECTIONS
   ============================================================================ */
.section {
  display: none;
  padding: 28px 32px 40px;
  animation: sectionIn 0.4s var(--ease-out);
}

.section.active { display: block; }

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

/* ============================================================================
   STAT CARDS
   ============================================================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card--blue .stat-icon { background: var(--blue-glow); color: var(--blue); }
.stat-card--orange .stat-icon { background: var(--orange-glow); color: var(--orange); }
.stat-card--green .stat-icon { background: var(--green-glow); color: var(--green); }
.stat-card--purple .stat-icon { background: var(--purple-glow); color: var(--purple); }

.stat-content { display: flex; flex-direction: column; min-width: 0; }

.stat-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.stat-value--sm {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
}

.stat-sub {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  margin-top: 3px;
}

/* ============================================================================
   PANELS (Cards)
   ============================================================================ */
.panel {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  margin-bottom: 24px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  letter-spacing: -0.005em;
}

.panel-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.legend-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  margin-right: 4px;
}

.legend-dot--blue { background: var(--blue); }
.legend-dot--orange { background: var(--orange); }

.panel-body { padding: 20px; min-height: 60px; }
.panel-body--chart { padding: 16px 16px 12px; }
.panel-body--scroll { max-height: 360px; overflow-y: auto; }

.panel-body--chart canvas {
  width: 100%;
  display: block;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.grid-2 > .panel { margin-bottom: 0; }

.placeholder {
  color: var(--text-tertiary);
  font-size: 0.8125rem;
  text-align: center;
  padding: 32px 20px;
}

/* ============================================================================
   BAR LISTS
   ============================================================================ */
.bar-list { list-style: none; }

.bar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  font-size: 0.8125rem;
}

.bar-item + .bar-item { border-top: 1px solid var(--border); }

.bar-label {
  flex: 1;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  font-weight: 500;
}

.bar-count {
  font-weight: 600;
  color: var(--text-tertiary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6875rem;
  white-space: nowrap;
}

.bar-track {
  width: 80px;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.6s var(--ease-out);
}

/* ============================================================================
   DEVICE BARS
   ============================================================================ */
.device-list { list-style: none; }

.device-item { margin-bottom: 14px; }
.device-item:last-child { margin-bottom: 0; }

.device-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  margin-bottom: 6px;
}

.device-name { font-weight: 500; text-transform: capitalize; color: var(--text-primary); }
.device-pct {
  color: var(--text-tertiary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 500;
}

.device-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.device-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s var(--ease-out);
}

/* ============================================================================
   LEADS
   ============================================================================ */
.leads-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-select {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.2s var(--ease);
}

.toolbar-select:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.toolbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  flex: 1;
  max-width: 280px;
  transition: border-color 0.2s var(--ease);
  color: var(--text-tertiary);
}

.toolbar-search:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.toolbar-search input {
  border: none;
  background: none;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  width: 100%;
}

.toolbar-search input::placeholder { color: var(--text-tertiary); }

.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.leads-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg);
}

.leads-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.leads-table tbody tr {
  transition: background 0.15s var(--ease);
}

.leads-table tbody tr:hover { background: var(--surface-hover); }

.lead-name { font-weight: 600; color: var(--text-primary); }
.lead-company { color: var(--text-secondary); }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-new { background: #DBEAFE; color: #1E40AF; }
.badge-contacted { background: #FEF3C7; color: #92400E; }
.badge-quoted { background: #EDE9FE; color: #5B21B6; }
.badge-won { background: #D1FAE5; color: #065F46; }
.badge-lost { background: #FEE2E2; color: #991B1B; }

/* ============================================================================
   EMPTY STATE
   ============================================================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-tertiary);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 0.8125rem; line-height: 1.6; }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 1100px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { grid-column: 1; }
  .mobile-menu-btn { display: block; }
  .section { padding: 20px 16px 32px; }
  .topbar { padding: 0 16px; height: 56px; }
  .stats-row { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-icon { display: none; }
  .leads-toolbar { flex-wrap: wrap; }
  .toolbar-search { max-width: none; }
  .leads-table th:nth-child(3), .leads-table td:nth-child(3),
  .leads-table th:nth-child(5), .leads-table td:nth-child(5) { display: none; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.375rem; }
  .date-range { overflow-x: auto; }
}

/* ============================================================================
   PRINT & ACCESSIBILITY
   ============================================================================ */
@media print {
  .sidebar, .topbar, .leads-toolbar { display: none !important; }
  .dashboard { grid-template-columns: 1fr; }
  .main { grid-column: 1; }
  .section { padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
