/* OMEGA Compute Network — Cross-platform stylesheet
   Targets: iOS Safari, Android Chrome, Samsung Internet, Firefox, Edge, Desktop Chrome */

/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --violet: #7c3aed;
  --cyan: #06b6d4;
  --green: #10b981;
  /* Safe area insets for notch/home-bar (iOS) */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

html {
  scroll-behavior: smooth;
  /* Prevent font size inflation on iOS rotation */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
               Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  /* Remove tap highlight on Android/iOS */
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
  /* Smooth font rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-smoothing: antialiased;
  /* Prevent horizontal overflow */
  overflow-x: hidden;
  /* iOS momentum scrolling */
  -webkit-overflow-scrolling: touch;
}

/* ── Typography ───────────────────────────────────────────────────────── */
.font-mono, code, pre {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code',
               'Consolas', 'Liberation Mono', monospace;
}

/* ── Navigation — iOS safe area ──────────────────────────────────────── */
nav.fixed-nav {
  padding-top: calc(0.75rem + var(--sat));
  padding-left: calc(1.5rem + var(--sal));
  padding-right: calc(1.5rem + var(--sar));
}

/* Footer safe area */
footer {
  padding-bottom: calc(3rem + var(--sab));
}

/* ── Backdrop blur — needs -webkit- prefix for Safari/iOS ────────────── */
.backdrop-blur,
[class*="backdrop-blur"] {
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* ── Touch targets — minimum 44×44px (Apple HIG / Google Material) ────── */
a, button, [role="button"], select, input[type="range"],
input[type="checkbox"], input[type="radio"] {
  min-height: 44px;
  min-width: 44px;
}

/* Override for inline links that shouldn't stretch */
p a, .inline-link { min-height: unset; min-width: unset; }

/* ── Inputs — font-size ≥16px prevents iOS auto-zoom ─────────────────── */
input, select, textarea {
  font-size: 16px !important;
  /* iOS inner shadow removal */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0.75rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--violet);
  cursor: pointer;
  margin-top: -9px;
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--violet);
  cursor: pointer;
  border: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #374151;
  border-radius: 2px;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: #374151;
  border-radius: 2px;
}

/* Select arrow on Android Chrome */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px !important;
}

/* ── Scrollbars ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 2px; }

/* Hide scrollbar on mobile (still scrollable) */
@media (max-width: 768px) {
  ::-webkit-scrollbar { display: none; }
  * { scrollbar-width: none; }
}

/* ── Cards & interactive elements ────────────────────────────────────── */
.stat-card { transition: transform 0.2s, border-color 0.2s; }
@media (hover: hover) {
  .stat-card:hover { transform: translateY(-2px); border-color: rgba(124,58,237,0.5); }
}

/* Active state for touch (replaces hover on mobile) */
.stat-card:active { transform: scale(0.98); }

/* ── iOS 100vh fix — use dvh where supported ─────────────────────────── */
.min-h-screen {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height — collapses browser chrome */
}
.h-screen {
  height: 100vh;
  height: 100dvh;
}

/* ── Dashboard sidebar transition ────────────────────────────────────── */
#sidebar {
  will-change: transform;
  /* Hardware-accelerated slide on iOS */
  -webkit-transform: translateX(-100%);
  transform: translateX(-100%);
  transition: -webkit-transform 0.25s ease-in-out;
  transition: transform 0.25s ease-in-out;
}
#sidebar.open {
  -webkit-transform: translateX(0);
  transform: translateX(0);
}
@media (min-width: 1024px) {
  #sidebar {
    -webkit-transform: translateX(0) !important;
    transform: translateX(0) !important;
  }
}

/* ── Gradient text (WebKit prefix for older Safari) ─────────────────── */
.gradient-text,
[class*="bg-clip-text"] {
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Animations — respect reduced motion preference ─────────────────── */
@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;
  }
  .animate-pulse { animation: none !important; }
}

/* ── Line clamp (cross-browser) ───────────────────────────────────────── */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Skeleton loading ─────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #1f2937 25%, #374151 50%, #1f2937 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Focus ring — accessibility ───────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--violet);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── Modal bottom sheet on mobile ────────────────────────────────────── */
@media (max-width: 640px) {
  #detail-modal > div {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 90vh;
    padding-bottom: calc(1.5rem + var(--sab));
  }
}

/* ── Prevent text selection on UI elements ───────────────────────────── */
nav, button, .stat-card {
  -webkit-user-select: none;
  user-select: none;
}

/* ── Samsung Internet / older Android fix for flex ───────────────────── */
.flex { display: -webkit-box; display: -ms-flexbox; display: flex; }
.grid { display: grid; }

/* ── Global overflow control ──────────────────────────────────────────── */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Text overflow everywhere ─────────────────────────────────────────── */
p, h1, h2, h3, h4, span, div {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ── Webkit-specific: fix 100% width sections ─────────────────────────── */
section, main, article, header, footer, nav {
  max-width: 100%;
  box-sizing: border-box;
}
