/* ==========================================================
   CalcuWorld — Global Styles
   Modern, responsive, dark-mode, accessible, CLS-safe
   ========================================================== */

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

:root {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-header: #ffffff;
  --bg-input: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --border-light: #e2e8f0;
  --accent: #0f766e;
  --accent-hover: #0b5e58;
  --accent-soft: #ccfbf1;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.03);
  --shadow-lg: 0 10px 30px -5px rgba(0,0,0,.08), 0 8px 12px -6px rgba(0,0,0,.04);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --transition: all .2s ease;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ad-min-height-desktop: 100px;
  --ad-min-height-mobile: 80px;
}

body.dark {
  --bg-page: #0b1120;
  --bg-card: #111827;
  --bg-header: #0f172a;
  --bg-input: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-light: #1e293b;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #134e4a;
  --accent-contrast: #042f2e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 30px -5px rgba(0,0,0,.6);
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color .25s, color .2s;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, select, button { font-family: inherit; font-size: 1rem; }

.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-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--accent); color: var(--accent-contrast);
  padding: .5rem 1rem; border-radius: 0 0 8px 8px; z-index: 1000;
  transition: top .2s;
}
.skip-link:focus { top: 0; }

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ============ HEADER ============ */
.site-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-light);
  position: sticky; top: 0; z-index: 100;
  transition: background .2s, border-color .2s;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: .9rem 0;
  flex-wrap: wrap;
}
.logo {
  display: flex; align-items: center; gap: .4rem;
  font-weight: 800; font-size: 1.4rem;
  letter-spacing: -.02em;
}
.logo-icon { font-size: 1.6rem; }
.logo-accent { color: var(--accent); }

.main-nav { flex: 1; display: flex; justify-content: center; }
.nav-list { display: flex; gap: 1.5rem; align-items: center; }
.nav-item { position: relative; }
.nav-link {
  background: none; border: none;
  font-weight: 500; font-size: .95rem;
  color: var(--text-primary);
  padding: .5rem 0;
  display: inline-flex; align-items: center; gap: .25rem;
  transition: color .15s;
}
.nav-link:hover, .nav-link:focus-visible { color: var(--accent); }
.caret { font-size: .7rem; opacity: .7; }

.dropdown {
  position: absolute; top: 100%; left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 190px;
  padding: .5rem 0;
  opacity: 0; visibility: hidden;
  transform: translateY(8px);
  transition: opacity .18s, transform .18s, visibility .18s;
  z-index: 200;
}
.nav-item:hover .dropdown,
.nav-item:focus-within .dropdown {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.dropdown a {
  display: block;
  padding: .5rem 1.2rem;
  font-size: .9rem;
  color: var(--text-secondary);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.dropdown a:hover, .dropdown a:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
}

.header-actions { display: flex; align-items: center; gap: .6rem; }

.header-search { position: relative; display: flex; align-items: center; }
.header-search input {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 40px;
  padding: .5rem 2.2rem .5rem 1rem;
  font-size: .9rem;
  color: var(--text-primary);
  width: 200px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, width .2s;
}
.header-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,148,136,.18);
  width: 240px;
}
.search-icon { position: absolute; right: .8rem; pointer-events: none; font-size: .9rem; opacity: .6; }

.lang-select {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 40px;
  padding: .45rem .7rem;
  color: var(--text-primary);
  font-size: .85rem;
  cursor: pointer;
  outline: none;
}
.lang-select:focus { border-color: var(--accent); }

.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 40px;
  padding: .45rem .7rem;
  font-size: 1.1rem;
  transition: var(--transition);
}
.theme-toggle:hover { background: var(--accent-soft); border-color: var(--accent); }

.mobile-menu-btn {
  display: none;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: .45rem .65rem;
  font-size: 1.2rem;
}

/* ============ HERO ============ */
.hero { padding: 3.5rem 0 2.5rem; text-align: center; }
.hero-inner { max-width: 900px; margin: 0 auto; }
.hero-title {
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
  margin-bottom: 1rem;
}
.hero-subtitle {
  color: var(--text-secondary);
  font-size: clamp(1rem, 2vw, 1.15rem);
  max-width: 680px;
  margin: 0 auto 2rem;
}
.hero-search {
  display: flex;
  max-width: 580px;
  margin: 0 auto 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 60px;
  padding: .35rem .35rem .35rem 1.4rem;
  box-shadow: var(--shadow-md);
  transition: border-color .2s, box-shadow .2s;
}
.hero-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(13,148,136,.15), var(--shadow-md);
}
.hero-search input {
  flex: 1; border: none; background: transparent;
  padding: .9rem .4rem; font-size: 1rem;
  color: var(--text-primary); outline: none;
}
.hero-search button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 50px;
  padding: .85rem 1.6rem;
  font-weight: 600;
  transition: background .18s;
  white-space: nowrap;
}
.hero-search button:hover { background: var(--accent-hover); }

.quick-links { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
.quick-link {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 40px;
  padding: .45rem 1.1rem;
  font-size: .85rem; font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
}
.quick-link:hover, .quick-link:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ============ ADS — CLS-safe (reserved height) ============ */
.ad-slot {
  background: var(--bg-input);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  min-height: var(--ad-min-height-desktop);
  display: flex; align-items: center; justify-content: center;
  margin: 1.5rem 0;
  position: relative;
  overflow: hidden;
  contain: layout style;
}
.ad-slot .ad-label {
  font-size: .7rem; letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  opacity: .6;
}
.ad-header { min-height: 100px; }
.ad-in-article { min-height: 120px; margin: 2rem 0; }
.ad-sidebar { min-height: 250px; margin: 0 0 1.5rem; }

/* ============ MAIN GRID ============ */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  gap: 2rem;
  padding-top: 1rem;
  padding-bottom: 3rem;
}
.content-col { min-width: 0; }

.section-title {
  font-size: 1.7rem; font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 1.5rem;
}

/* ============ CATEGORY CARDS ============ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.25rem;
}
.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.5rem 1.25rem;
  cursor: pointer;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform .18s, box-shadow .2s, border-color .2s;
}
.category-card:hover,
.category-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  outline: none;
}
.card-icon {
  font-size: 1.7rem;
  width: 3rem; height: 3rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: 14px;
  margin-bottom: 1rem;
}
.category-card h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: .4rem; }
.category-card p { font-size: .88rem; color: var(--text-secondary); flex: 1; margin-bottom: 1rem; }
.card-badge {
  align-self: flex-start;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .72rem; font-weight: 600;
  padding: .2rem .75rem;
  border-radius: 40px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ============ CALCULATOR PANEL ============ */
.calculator-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  margin-top: 2rem;
  box-shadow: var(--shadow-lg);
  animation: panelIn .25s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-light);
}
.panel-header h2 { font-size: 1.35rem; font-weight: 700; }
.panel-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.btn-ghost, .btn-close {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 30px;
  padding: .4rem .9rem;
  font-size: .82rem; font-weight: 500;
  color: var(--text-primary);
  transition: var(--transition);
  display: inline-flex; align-items: center; gap: .35rem;
}
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn-close { padding: .4rem .7rem; border-radius: 50%; font-size: .9rem; }
.btn-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ============ FORM ELEMENTS ============ */
.input-group { margin-bottom: 1.1rem; }
.input-group label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: .4rem;
}
.input-group input,
.input-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: .75rem 1rem;
  font-size: .95rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input-group input:focus,
.input-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}
.input-group input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,.15);
}
.input-error {
  color: var(--danger);
  font-size: .78rem;
  margin-top: .3rem;
  display: block;
  min-height: 1em;
}
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

/* ============ RESULTS ============ */
.result-box {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  margin-top: 1.25rem;
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; flex-wrap: wrap;
  font-weight: 600;
  font-size: 1rem;
}
.result-box .result-value {
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.result-box .result-unit { font-size: .85rem; opacity: .8; font-weight: 500; }

.steps-note {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
  font-size: .88rem;
  color: var(--text-secondary);
}
.steps-note strong { color: var(--text-primary); }
.steps-note code {
  background: var(--bg-input);
  padding: .1rem .4rem;
  border-radius: 4px;
  font-size: .85em;
}

/* ============ SIDEBAR ============ */
.sidebar { min-width: 0; }
.sidebar-nav {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}
.sidebar-nav h3 { font-size: 1rem; font-weight: 600; margin-bottom: .8rem; }
.sidebar-nav ul li a {
  display: block;
  padding: .45rem 0;
  font-size: .88rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  transition: color .15s;
}
.sidebar-nav ul li:last-child a { border-bottom: none; }
.sidebar-nav ul li a:hover { color: var(--accent); }

/* ============ EDUCATIONAL ============ */
.edu-section { margin-top: 3rem; }
.edu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
}
.edu-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
}
.edu-card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: .6rem; }
.edu-card p { font-size: .88rem; color: var(--text-secondary); line-height: 1.65; }

/* ============ FAQ ============ */
.faq-list { display: grid; gap: .8rem; }
.faq-item {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: .9rem 1.2rem;
  box-shadow: var(--shadow-sm);
}
.faq-item summary {
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-right: 1.5rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+';
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--accent);
  transition: transform .2s;
}
.faq-item[open] summary::after { content: '−'; }
.faq-item p { margin-top: .7rem; font-size: .9rem; color: var(--text-secondary); }

/* ============ STATIC VIEW (legal pages) ============ */
.static-view {
  max-width: 820px;
  padding: 3rem 1.5rem 4rem;
  line-height: 1.7;
}
.static-view h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
  margin-bottom: .5rem;
}
.static-view .updated {
  color: var(--text-secondary);
  font-size: .88rem;
  margin-bottom: 2rem;
}
.static-view h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 2rem 0 .8rem;
}
.static-view p, .static-view ul { margin-bottom: 1rem; color: var(--text-secondary); }
.static-view ul { padding-left: 1.4rem; list-style: disc; }
.static-view ul li { margin-bottom: .4rem; }
.static-view a { color: var(--accent); text-decoration: underline; }
.static-view code {
  background: var(--bg-input);
  padding: .1rem .4rem;
  border-radius: 4px;
  font-size: .9em;
}

/* ============ FOOTER ============ */
.site-footer {
  background: var(--bg-header);
  border-top: 1px solid var(--border-light);
  padding: 2.5rem 0 0;
  margin-top: auto;
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 2rem;
  padding-bottom: 2rem;
}
.footer-brand p {
  font-size: .88rem;
  color: var(--text-secondary);
  margin-top: .7rem;
  max-width: 280px;
}
.footer-links h4 { font-size: .95rem; font-weight: 600; margin-bottom: .8rem; }
.footer-links ul li a {
  display: block;
  padding: .3rem 0;
  font-size: .88rem;
  color: var(--text-secondary);
  transition: color .15s;
}
.footer-links ul li a:hover { color: var(--accent); }

.copyright {
  border-top: 1px solid var(--border-light);
  padding: 1.25rem 0;
  text-align: center;
  font-size: .82rem;
  color: var(--text-secondary);
}
.copyright .disclaimer { font-size: .78rem; opacity: .8; margin-top: .4rem; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .main-grid { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .ad-slot { min-height: var(--ad-min-height-mobile); }
}

@media (max-width: 860px) {
  .main-nav { display: none; }
  .main-nav.open { display: block; }
  .mobile-menu-btn { display: inline-flex; }
  .header-search input { width: 160px; }
  .header-search input:focus { width: 200px; }
}

@media (max-width: 640px) {
  .container { padding: 0 1rem; }
  .header-inner { gap: .6rem; }
  .header-search { display: none; }
  .hero { padding: 2.5rem 0 2rem; }
  .hero-search {
    flex-direction: column;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    gap: .6rem;
  }
  .hero-search input {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 60px;
    padding: .85rem 1.2rem;
  }
  .hero-search button { width: 100%; padding: .85rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .input-row { grid-template-columns: 1fr; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .footer-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  .result-box { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* RTL */
[dir="rtl"] .header-inner { direction: rtl; }
[dir="rtl"] .search-icon { right: auto; left: .8rem; }
[dir="rtl"] .header-search input { padding: .5rem 1rem .5rem 2.2rem; }
[dir="rtl"] .dropdown { left: auto; right: 0; }
[dir="rtl"] .result-box { border-left: none; border-right: 4px solid var(--accent); }
[dir="rtl"] .static-view ul { padding-left: 0; padding-right: 1.4rem; }