/* ============================================================================
   IT Vedas Shared Stylesheet
   Common styles for all pages: typography, colors, layout, components
   Includes: Breadcrumbs, Related Content, Image Optimization, Lazy Loading
   ============================================================================ */

/* ── Design Tokens ────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  /* Colors */
  --bg:    #0A0A0F;
  --bg2:   #13131C;
  --bg3:   #1C1C2A;
  --card:  #111119;
  --text:  #F0F0F8;
  --muted: #8888A8;
  --sub:   #D0D0E8;
  --border: rgba(255,255,255,0.08);

  /* Category Colors */
  --net:   #FF6B35;
  --cld:   #3B82F6;
  --sec:   #10B981;
  --dev:   #8B5CF6;
  --db:    #F59E0B;
  --os:    #EF4444;
  --hw:    #06B6D4;
  --comp:  #EC4899;
  --news:  #14B8A6;

  /* Typography */
  --fd:    'Space Grotesk', sans-serif;
  --fb:    'Inter', sans-serif;
  --fl:    'Lexend', sans-serif;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

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

  /* Transitions */
  --transition-fast: 150ms ease-out;
  --transition-normal: 200ms ease-out;
  --transition-slow: 300ms ease-out;

  /* Z-Index Scale */
  --z-dropdown: 100;
  --z-sticky: 20;
  --z-fixed: 30;
  --z-modal: 50;
  --z-tooltip: 60;
}

/* ── Reset & Base ─────────────────────────────────────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--fl);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ───────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--fd);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: var(--spacing-md);
}

h1 {
  font-size: clamp(1.75rem, 5vw, 3.5rem);
}

h2 {
  font-size: clamp(1.35rem, 4vw, 2.5rem);
}

h3 {
  font-size: clamp(1.1rem, 3vw, 1.75rem);
}

h4 {
  font-size: 1.35rem;
}

h5 {
  font-size: 1.1rem;
}

h6 {
  font-size: 0.95rem;
}

p {
  margin-bottom: var(--spacing-md);
}

small {
  font-size: 0.875rem;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--net);
}

strong {
  font-weight: 600;
}

code {
  background: var(--bg3);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

/* ── Containers ───────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
}

.container-sm {
  max-width: 600px;
}

.container-lg {
  max-width: 1400px;
}

/* ── Grid & Flexbox Utilities ─────────────────────────────────────────── */
.grid {
  display: grid;
  gap: var(--spacing-md);
}

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

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

.grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-col {
  flex-direction: column;
}

.gap-sm {
  gap: var(--spacing-sm);
}

.gap-md {
  gap: var(--spacing-md);
}

.gap-lg {
  gap: var(--spacing-lg);
}

/* ── Button Reset ─────────────────────────────────────────────────────── */
button {
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  margin: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
input,
select,
textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--net);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

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

/* ── Cards & Surfaces ─────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.surface {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-lg);
  background: var(--net);
  color: white;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  text-decoration: none;
  font-family: var(--fd);
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--net);
  color: white;
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-small {
  padding: var(--spacing-xs) var(--spacing-md);
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--bg3);
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-primary {
  background: var(--net);
  color: white;
}

.badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--sec);
}

.badge-warning {
  background: rgba(251, 192, 45, 0.2);
  color: var(--medium);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #EF4444;
}

/* ── Responsive Text ──────────────────────────────────────────────────── */
.text-sm {
  font-size: 0.875rem;
}

.text-lg {
  font-size: 1.125rem;
}

.text-xl {
  font-size: 1.35rem;
}

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

.text-accent {
  color: var(--net);
}

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

/* ── Spacing Utilities ────────────────────────────────────────────────── */
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }
.mt-2xl { margin-top: var(--spacing-2xl); }

.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }
.mb-2xl { margin-bottom: var(--spacing-2xl); }

.py-md { padding: var(--spacing-md) 0; }
.py-lg { padding: var(--spacing-lg) 0; }
.px-md { padding: 0 var(--spacing-md); }
.px-lg { padding: 0 var(--spacing-lg); }

/* ── Visibility ───────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Accessibility ────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--net);
  outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--net);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* ── Responsive Tables ────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--spacing-lg) 0;
}

th {
  background: var(--bg3);
  padding: var(--spacing-md);
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

td {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ── Loading States ───────────────────────────────────────────────────── */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--net);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Media Queries ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    font-size: 15px;
  }

  .container {
    padding: 0 1rem;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.35rem;
  }

  .hidden-mobile {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 0.75rem;
  }

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

  .flex-col-mobile {
    flex-direction: column;
  }
}

/* ── Print Styles ─────────────────────────────────────────────────────── */
@media print {
  body {
    background: white;
    color: black;
  }

  .no-print {
    display: none;
  }
}

/* ── Reduced Motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================================
   Phase 2: Breadcrumbs, Related Content, Image Optimization
   ============================================================================ */

/* ── Breadcrumb Navigation ────────────────────────────────────────────────── */
.breadcrumb,
nav.breadcrumb {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  padding: 0.75rem 0;
}

.breadcrumb-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 0.25rem;
}

.breadcrumb-item {
  display: inline;
}

.breadcrumb-item a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.breadcrumb-item a:hover {
  color: var(--text);
}

.breadcrumb-item a:focus-visible {
  outline: 2px solid var(--net);
  outline-offset: 2px;
  border-radius: 4px;
}

.breadcrumb-item.current {
  color: var(--text);
  font-weight: 500;
}

.breadcrumb-separator {
  margin: 0 0.5rem;
  color: var(--border);
}

/* ── Related Content Section ──────────────────────────────────────────────── */
.related-content {
  margin: 3rem 0;
  padding: 2rem;
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.05), rgba(139, 92, 246, 0.05));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.related-title {
  font-family: var(--fd);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text);
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  --cols: 3;
}

@media (max-width: 768px) {
  .related-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .related-grid {
    grid-template-columns: 1fr;
  }
}

.related-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 0.3s ease;
}

.related-item:hover {
  border-color: var(--net);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.1);
}

.related-link {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  text-decoration: none;
  height: 100%;
  color: inherit;
  transition: color 0.2s ease;
}

.related-link:hover .related-item-title {
  color: var(--net);
}

.related-item-title {
  font-family: var(--fd);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
  line-height: 1.4;
  transition: color 0.2s ease;
}

.related-item-excerpt {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 1rem;
  flex-grow: 1;
}

.related-item-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.related-topic {
  background: rgba(255, 107, 53, 0.1);
  color: var(--net);
  padding: 0.25rem 0.75rem;
  border-radius: 100px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Image Optimization & Lazy Loading ────────────────────────────────────── */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

img[loading="lazy"] {
  background: linear-gradient(45deg, var(--bg2) 25%, transparent 25%, transparent 75%, var(--bg2) 75%, var(--bg2)),
              linear-gradient(45deg, var(--bg2) 25%, transparent 25%, transparent 75%, var(--bg2) 75%, var(--bg2));
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  background-color: var(--bg3);
  animation: skeleton-loading 1s infinite linear;
}

img[loading="lazy"].loaded {
  background: none;
  animation: none;
}

@keyframes skeleton-loading {
  0% {
    opacity: 0.8;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.8;
  }
}

.image-container {
  position: relative;
  overflow: hidden;
  background: var(--bg2);
  border-radius: var(--radius-md);
}

.image-container img {
  transition: opacity 0.3s ease;
}

.image-container img[loading="lazy"] {
  opacity: 0.7;
}

.image-container img.loaded {
  opacity: 1;
}

/* Responsive image wrapper */
picture {
  display: block;
}

/* ── Accessibility: Image Focus ───────────────────────────────────────────── */
img:focus-visible {
  outline: 2px solid var(--net);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Utility Classes ──────────────────────────────────────────────────────── */
.lazy-image {
  background: var(--bg2);
  border-radius: var(--radius-md);
}

.has-lazy-images {
  /* Applied to body when lazy images are present */
}

.breadcrumb-container {
  margin-bottom: 1.5rem;
}

/* ============================================================================
   Phase 3: Mobile Optimization & Accessibility
   ============================================================================ */

/* ── Mobile Navigation ────────────────────────────────────────────────────── */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.hamburger-line {
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }

  nav.mobile-menu-open {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100vh;
    background: var(--bg);
    z-index: 1000;
    flex-direction: column;
    padding-top: 80px;
    overflow-y: auto;
  }

  .mobile-menu-toggle.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
  }

  .mobile-menu-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
  }

  .mobile-menu-toggle.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
  }
}

/* ── Touch-Friendly Touch Targets ─────────────────────────────────────────── */
a, button, [role="button"], input, select, textarea {
  min-width: 44px;
  min-height: 44px;
  padding: max(8px, calc((44px - 1em) / 2)) max(12px, calc((44px - 1em) / 2));
}

/* Override for small inline elements */
.badge, .label-small, small a, small button {
  min-width: unset;
  min-height: unset;
  padding: unset;
}

/* ── Focus Styles for Keyboard Navigation ─────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--net);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove focus outline on click but keep on keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
}

/* ── Skip Link (accessibility) ────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--net);
  color: white;
  padding: 8px 12px;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 0;
}

.skip-link:focus-visible {
  top: 0;
}

/* ── Screen Reader Only Content ──────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Reduced Motion Styles ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto !important;
  }
}

/* ── High Contrast Mode Support ──────────────────────────────────────────── */
@media (prefers-contrast: more) {
  body {
    --border: rgba(255, 255, 255, 0.2);
    --muted: #aaaacc;
  }

  a {
    text-decoration: underline;
  }

  button {
    border: 2px solid var(--text);
  }
}

/* ── Forced Colors Mode (Windows High Contrast) ──────────────────────────── */
@media (forced-colors: active) {
  a {
    text-decoration: underline;
  }

  button {
    border: 1px solid;
  }

  img {
    border: 1px solid;
  }
}

/* ── Mobile-Specific Adjustments ─────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Increase font size for readability */
  body {
    font-size: 16px;
  }

  /* Reduce padding for smaller screens */
  .container, main, article, section {
    padding: 1rem;
  }

  /* Full-width buttons on mobile */
  button.full-width-mobile {
    width: 100%;
    display: block;
  }

  /* Stack form fields */
  .form-group {
    margin-bottom: 1rem;
  }

  input, select, textarea {
    width: 100%;
    max-width: 100%;
  }

  /* Larger tap targets */
  a, button, [role="button"] {
    min-height: 48px;
    padding: max(12px, calc((48px - 1em) / 2)) 16px;
  }
}

@media (max-width: 480px) {
  /* Single column layouts */
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }

  /* Reduce heading sizes */
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  h3 {
    font-size: 1.1rem;
  }

  /* Extra large touch targets for mobile */
  button, a, [role="button"] {
    min-height: 48px;
  }
}

/* ── Performance: Reduce Paint/Layout ──────────────────────────────────── */
.lazy-load {
  contain: content;
  content-visibility: auto;
}

/* Use transform for animations instead of top/left */
.slide-in {
  transform: translateX(0);
  transition: transform 0.3s ease;
}

.slide-in.hidden {
  transform: translateX(-100%);
}

/* ── Loading States ──────────────────────────────────────────────────── */
.loading {
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--border);
  border-top-color: var(--net);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Utility Classes for Accessibility ────────────────────────────────────── */
.has-tooltip {
  position: relative;
  cursor: help;
}

.has-tooltip[aria-describedby]::after {
  content: attr(aria-label);
  position: absolute;
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.875rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
}
