/* Pefida Executive Command Center — styles */
:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-2: #0f1830;
  --border: rgba(255,255,255,0.07);
  --text: #e6edf7;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-2: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --gold: #d4af37;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* Touch targets - minimum 44px */
button, [role="button"], .btn, .chip, a, input, select, textarea {
  min-height: 44px;
  min-width: 44px;
}

/* Cards */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.card-soft { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }

/* Stats */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.1; }
.stat-sub { font-size: 11px; color: var(--muted); }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip-good { color: var(--accent-2); border-color: rgba(16,185,129,0.35); background: rgba(16,185,129,0.08); }
.chip-warn { color: var(--warn); border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.08); }
.chip-bad  { color: var(--danger); border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.08); }
.chip-info { color: #60a5fa; border-color: rgba(96,165,250,0.35); background: rgba(96,165,250,0.08); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s ease;
  text-decoration: none;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: transparent; }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* Progress bars */
.progress { height: 6px; border-radius: 999px; background: rgba(255,255,255,0.07); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; transition: width 0.4s ease; }

/* Charts - responsive */
canvas { max-width: 100%; height: auto !important; }

/* Animations */
.flash { animation: flash 0.6s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(37,99,235,0.5); } 70% { box-shadow: 0 0 0 12px rgba(37,99,235,0); } 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); } }

/* Toast */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  left: 20px;
  max-width: 400px;
  margin: 0 auto;
  z-index: 50;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }

/* Tabs */
.tab-active { background: var(--accent); border-color: transparent; color: #fff; }

/* Grid helpers */
.grid-auto-fit { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* Links */
a.link { color: #60a5fa; text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ============================================================
   MOBILE OPTIMIZATIONS
   ============================================================ */

/* Base mobile adjustments */
@media (max-width: 639px) {
  body { font-size: 15px; }
  
  /* Sidebar drawer */
  #sidebar {
    width: 280px;
    max-width: 85vw;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  #sidebar.nav-open { transform: translateX(0) !important; }
  
  /* Overlay */
  #overlay.overlay-visible { display: block !important; }
  
  /* Top bar */
  header { padding: 0 12px; }
  #menuBtn { min-width: 44px; min-height: 44px; }
  #refreshBtn { min-width: 44px; min-height: 44px; }
  #clock { display: none !important; }
  #pageTitle { font-size: 16px; }
  #pageSubtitle { font-size: 11px; }
  
  /* Content area */
  main > div { padding: 12px !important; }
  
  /* Vitals banner - stack on mobile */
  #vitalsBanner {
    grid-template-columns: 1fr !important;
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-value { font-size: 28px; }
  .stat-label { font-size: 11px; }
  
  /* Cards - tighter padding */
  .card { padding: 14px; border-radius: 12px; }
  .card-soft { padding: 10px; border-radius: 10px; }
  
  /* Grid helpers - single column */
  .grid-auto-fit { grid-template-columns: 1fr !important; }
  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr !important; }
  
  /* Chips - larger touch targets */
  .chip { padding: 8px 12px; font-size: 11px; }
  
  /* Buttons - full width on mobile */
  .btn { width: 100%; justify-content: center; }
  .btn-group { display: flex; flex-direction: column; gap: 8px; }
  .btn-group .btn { width: 100%; }
  
  /* Tables - horizontal scroll */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  th, td { padding: 10px 8px; font-size: 12px; }
  
  /* Forms */
  input, select, textarea {
    font-size: 16px !important; /* prevents zoom on iOS */
    padding: 12px 14px;
    border-radius: 10px;
  }
  
  /* Toasts - full width */
  #toast { left: 12px; right: 12px; max-width: none; bottom: 12px; }
  
  /* Footer */
  footer { padding: 16px 12px; font-size: 11px; }
  footer > span { width: 100%; text-align: center; }
}

/* Tablet adjustments */
@media (min-width: 640px) and (max-width: 1023px) {
  #sidebar { width: 260px; }
  .grid-auto-fit { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  #vitalsBanner { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 24px; }
}

/* Desktop */
@media (min-width: 1024px) {
  #sidebar { width: 256px; }
  .btn { width: auto; }
  .btn-group { flex-direction: row; }
  .btn-group .btn { width: auto; }
}

/* Large desktop */
@media (min-width: 1280px) {
  .stat-value { font-size: 26px; }
}

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

/* High contrast */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(255,255,255,0.2);
    --muted: #cbd5e1;
  }
  .btn { border-width: 2px; }
  .chip { border-width: 2px; }
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Chart containers - prevent layout shift */
.chart-container {
  position: relative;
  width: 100%;
  min-height: 200px;
}
@media (max-width: 639px) {
  .chart-container { min-height: 180px; }
}

/* Scroll snap for horizontal sections */
.scroll-snap-x {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.scroll-snap-x > * {
  flex: 0 0 auto;
  scroll-snap-align: start;
  min-width: 200px;
}
@media (max-width: 639px) {
  .scroll-snap-x > * { min-width: 160px; }
}

/* Responsive text clamp */
.text-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.text-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Print styles */
@media print {
  #sidebar, header, #overlay, #toast, .btn { display: none !important; }
  main { margin-left: 0 !important; }
  body { background: white; color: black; }
  .card { border: 1px solid #ddd; background: white; }
}