/* ==========================================================================
   CalcMaster — main.css
   Complete design system: reset, variables, typography, layout, utilities.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS RESET & BOX MODEL
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   2. ROOT VARIABLES (DESIGN TOKENS)
   -------------------------------------------------------------------------- */
:root {
  /* --- Colors --- */
  --bg:         #0a0a0f;           /* Deepest background             */
  --surface:    #12121a;           /* Card / panel surface           */
  --primary:    #6366f1;           /* Indigo — actions, links        */
  --primary-hi: #818cf8;           /* Lighter indigo — hover / grad  */
  --accent:     #22d3ee;           /* Cyan — highlights, values      */
  --text:       #e2e8f0;           /* Primary text                   */
  --muted:      #94a3b8;           /* Secondary / muted text         */
  --border:     rgba(99, 102, 241, .2);
  --glass:      rgba(18, 18, 26, .7);
  --danger:     #ef4444;
  --success:    #22c55e;
  --warning:    #f59e0b;

  /* --- Typography --- */
  --font-heading: 'Outfit', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body:    'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  /* --- Spacing scale (4px base) --- */
  --sp-1: 0.25rem;  /*  4px */
  --sp-2: 0.5rem;   /*  8px */
  --sp-3: 0.75rem;  /* 12px */
  --sp-4: 1rem;     /* 16px */
  --sp-5: 1.25rem;  /* 20px */
  --sp-6: 1.5rem;   /* 24px */
  --sp-8: 2rem;     /* 32px */
  --sp-10: 2.5rem;  /* 40px */

  /* --- Radii --- */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* --- Shadows --- */
  --shadow-glow: 0 8px 25px rgba(99, 102, 241, .35);

  /* --- Transitions --- */
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

/* --------------------------------------------------------------------------
   3. BASE TYPOGRAPHY
   -------------------------------------------------------------------------- */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  line-height: 1.25;
  font-weight: 600;
}

/* Gradient headline — matches existing calculator pages */
h1 {
  font-size: 2.2rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--sp-2);
}

h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

.subtitle {
  color: var(--muted);
  margin-bottom: var(--sp-8);
  font-size: 1rem;
}

/* Numeric values always use monospace for alignment */
.mono, .value, code, kbd, samp {
  font-family: var(--font-mono);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color .2s;
}
a:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   4. LAYOUT
   -------------------------------------------------------------------------- */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-4);
}

/* Wider container for index / card-grid pages */
.container--wide {
  max-width: 1100px;
}

/* Narrow container for single-purpose calculators (e.g. basic calc) */
.container--narrow {
  max-width: 480px;
}

/* --------------------------------------------------------------------------
   5. GLASSMORPHISM CARD
   -------------------------------------------------------------------------- */
.glass-card {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  margin-bottom: var(--sp-6);
  transition: border-color .25s var(--ease-out), box-shadow .25s var(--ease-out);
}

.glass-card:hover {
  border-color: var(--primary);
}

/* --------------------------------------------------------------------------
   6. FORMULA DISPLAY
   -------------------------------------------------------------------------- */
.formula {
  background: rgba(99, 102, 241, .1);
  border: 1px solid rgba(99, 102, 241, .25);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-6);
  text-align: center;
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   7. RESPONSIVE BREAKPOINTS
      Mobile-first: base styles are mobile.
      sm  ≥ 640px  (large phones / small tablets)
      md  ≥ 1024px (tablets / small desktops)
      lg  ≥ 1280px (desktops)
   -------------------------------------------------------------------------- */
@media (max-width: 639px) {
  h1 { font-size: 1.75rem; }
  .container { padding: var(--sp-4) var(--sp-4); }
  .glass-card { padding: var(--sp-5); }
}

@media (min-width: 640px) and (max-width: 1023px) {
  h1 { font-size: 2rem; }
}

@media (min-width: 1024px) {
  h1 { font-size: 2.5rem; }
}

/* --------------------------------------------------------------------------
   8. BREADCRUMB NAVIGATION
   -------------------------------------------------------------------------- */
nav.breadcrumb {
  margin-bottom: var(--sp-6);
  font-size: 0.85rem;
  color: var(--muted);
}
nav.breadcrumb a {
  color: var(--primary);
}
nav.breadcrumb a:hover {
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   9. AD PLACEHOLDERS
   -------------------------------------------------------------------------- */
.ad-header,
.ad-sidebar {
  background: rgba(99, 102, 241, .05);
  border: 1px dashed rgba(99, 102, 241, .2);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.ad-header {
  width: 100%;
  min-height: 90px;
  margin-bottom: var(--sp-6);
}

.ad-sidebar {
  min-height: 250px;
  margin-bottom: var(--sp-6);
  padding: var(--sp-4);
}

/* --------------------------------------------------------------------------
   10. SKELETON LOADER ANIMATIONS
   -------------------------------------------------------------------------- */
@keyframes skeleton-pulse {
  0%   { opacity: 0.4; }
  50%  { opacity: 0.8; }
  100% { opacity: 0.4; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(99, 102, 241, .06) 25%,
    rgba(99, 102, 241, .12) 50%,
    rgba(99, 102, 241, .06) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

.skeleton--text {
  height: 1em;
  margin-bottom: var(--sp-2);
}

.skeleton--heading {
  height: 1.6em;
  width: 60%;
  margin-bottom: var(--sp-3);
}

.skeleton--block {
  height: 120px;
  width: 100%;
}

/* --------------------------------------------------------------------------
   11. FOOTER
   -------------------------------------------------------------------------- */
footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: var(--sp-10);
  padding: var(--sp-8) 0;
  border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   12. ACCESSIBILITY
   -------------------------------------------------------------------------- */

/* Visible focus ring — keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect prefers-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;
  }
}

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

/* Skip-to-content link */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-4);
  background: var(--primary);
  color: #fff;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  z-index: 1000;
  font-weight: 600;
}
.skip-link:focus {
  top: var(--sp-4);
}

/* High-contrast mode support */
@media (forced-colors: active) {
  .glass-card {
    border: 2px solid CanvasText;
  }
  .btn {
    border: 2px solid ButtonText;
  }
}

/* --------------------------------------------------------------------------
   13. HEADER & NAVIGATION
   -------------------------------------------------------------------------- */
.header {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-4);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-icon {
  width: 2rem;
  height: 2rem;
}

.logo-text {
  font-family: var(--font-heading);
  font-size: 1.2rem;
}

.nav-main {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-2);
  color: var(--muted);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--text);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Search box */
.search-box {
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  padding-left: 2.8rem;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-size: 1rem;
  transition: border-color .2s, box-shadow .2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

.search-btn {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  display: flex;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: var(--sp-2);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-4);
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-4);
}

.footer-content nav {
  margin-top: var(--sp-2);
}

.footer-content nav a {
  color: var(--muted);
  font-size: 0.8rem;
}

.footer-content nav a:hover {
  color: var(--primary);
}

/* --------------------------------------------------------------------------
   14. DASHBOARD CATEGORY CARDS
   -------------------------------------------------------------------------- */
.category-card {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-6);
  transition: border-color .25s var(--ease-out), box-shadow .25s var(--ease-out), transform .25s var(--ease-out);
}

.category-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 30px rgba(99, 102, 241, .15);
  transform: translateY(-2px);
}

.category-icon {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: var(--sp-4);
  color: var(--primary);
}

.category-icon svg {
  width: 100%;
  height: 100%;
}

.category-title {
  font-size: 1.15rem;
  margin-bottom: var(--sp-2);
  color: var(--text);
}

.category-desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: var(--sp-4);
}

.calc-list {
  list-style: none;
  padding: 0;
}

.calc-list li {
  padding: var(--sp-1) 0;
}

.calc-list a {
  font-size: 0.9rem;
  color: var(--text);
  transition: color .15s;
}

.calc-list a:hover {
  color: var(--accent);
}

/* Hero section */
.hero {
  text-align: center;
  padding: var(--sp-8) 0 var(--sp-6);
}

.hero h1 {
  font-size: 2rem;
}

.hero-subtitle {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: var(--sp-6);
}

/* Categories grid */
.categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-5);
}

/* Sidebar */
.sidebar {
  margin-top: var(--sp-8);
}

.sidebar-content h3 {
  font-size: 1rem;
  margin-bottom: var(--sp-4);
  color: var(--text);
}

.popular-list {
  list-style: none;
  padding: 0;
}

.popular-list li {
  padding: var(--sp-2) 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}

.popular-list a {
  font-size: 0.9rem;
}

@media (max-width: 639px) {
  .hero h1 { font-size: 1.6rem; }
  .categories { grid-template-columns: 1fr; }
  .category-card { padding: var(--sp-4); }
  .category-icon { width: 2rem; height: 2rem; }
}

/* --------------------------------------------------------------------------
   15. UTILITY CLASSES
   -------------------------------------------------------------------------- */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-accent  { color: var(--accent); }
.text-muted   { color: var(--muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }

/* --------------------------------------------------------------------------
   16. GRID HELPERS
   -------------------------------------------------------------------------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-4);
}

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