/* Design system tokens and components */
/* ApplyReady Design System — tokens and base component styles
   Light theme by default; dark via [data-theme="dark"]
   All values WCAG AA. Spacing on 4/8px scale. */

:root {
  /* Colour */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-active: #1e40af;
  --color-primary-soft: #eff6ff;
  --color-primary-focus: rgba(37, 99, 235, 0.32);

  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-surface-subtle: #f8fafc;
  --color-surface-muted: #f1f5f9;

  --color-text: #0f172a;
  --color-text-heading: #020617;
  --color-text-muted: #475569;
  --color-text-inverse: #ffffff;

  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;

  --color-success: #047857;
  --color-success-soft: #ecfdf5;
  --color-warning: #b45309;
  --color-warning-soft: #fffbeb;
  --color-error: #b91c1c;
  --color-error-soft: #fef2f2;

  /* Spacing (4/8px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --shadow-focus: 0 0 0 3px var(--color-primary-focus);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-devanagari: 'Noto Sans Devanagari', 'Inter', sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Motion */
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 320ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index */
  --z-dropdown: 40;
  --z-sticky: 50;
  --z-modal: 60;
  --z-toast: 70;
  --z-tooltip: 80;

  /* Layout */
  --header-height: 64px;
  --max-content: 1120px;
  --touch-target: 44px;
}

[data-theme="dark"] {
  --color-primary: #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-primary-active: #2563eb;
  --color-primary-soft: #1e293b;
  --color-primary-focus: rgba(59, 130, 246, 0.4);

  --color-surface: #0f172a;
  --color-surface-elevated: #1e293b;
  --color-surface-subtle: #0b1220;
  --color-surface-muted: #1e293b;

  --color-text: #e2e8f0;
  --color-text-heading: #f8fafc;
  --color-text-muted: #94a3b8;
  --color-text-inverse: #0f172a;

  --color-border: #334155;
  --color-border-strong: #475569;

  --color-success: #34d399;
  --color-success-soft: #064e3b;
  --color-warning: #fbbf24;
  --color-warning-soft: #451a03;
  --color-error: #f87171;
  --color-error-soft: #450a0a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
  }
}

/* Base */
[lang="hi"] body, .lang-hi { font-family: var(--font-devanagari); }

/* Focus */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-out),
              color var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
  user-select: none;
  text-decoration: none;
}
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn--primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn--primary:active:not(:disabled) { background: var(--color-primary-active); transform: translateY(1px); }
.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn--secondary:hover:not(:disabled) { background: var(--color-surface-muted); }
.btn--ghost {
  background: transparent;
  color: var(--color-primary);
}
.btn--ghost:hover:not(:disabled) { background: var(--color-primary-soft); }
.btn--danger {
  background: var(--color-error);
  color: white;
}
.btn--danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn--icon { padding: 0; width: var(--touch-target); }
.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  color: inherit;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inputs */
.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field__label { font-size: var(--text-sm); font-weight: 600; color: var(--color-text-heading); }
.field__helper { font-size: var(--text-xs); color: var(--color-text-muted); }
.field__error { font-size: var(--text-xs); color: var(--color-error); display: none; }
.field.is-error .field__error { display: block; }
.field.is-error .input { border-color: var(--color-error); }
.input, .select-native, textarea {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  transition: border-color var(--duration-normal) var(--ease-out), box-shadow var(--duration-normal) var(--ease-out);
}
.input:focus, .select-native:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
  outline: none;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 3.5rem; }
.input-group__suffix {
  position: absolute; right: var(--space-3);
  font-size: var(--text-sm); color: var(--color-text-muted); pointer-events: none;
}
.stepper { display: flex; align-items: center; gap: var(--space-1); }
.stepper .input { text-align: center; max-width: 100px; }
.stepper button { min-width: var(--touch-target); }

/* Custom select (enhanced) */
.custom-select { position: relative; }
.custom-select__button {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  text-align: left;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
}
/* The listbox is portalled to <body> by components.js, so it is styled and shown
   by its own [hidden] state, never by a .custom-select ancestor. */
.custom-select__list {
  position: fixed;
  max-height: 240px; overflow: auto;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}
.custom-select__list[hidden] { display: none; }
.custom-select__option {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  min-height: 36px;
  display: flex; align-items: center;
}
.custom-select__option[aria-selected="true"],
.custom-select__option.is-active,
.custom-select__option:hover { background: var(--color-primary-soft); }

/* Checkbox / Radio / Toggle */
.check, .radio, .toggle {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--touch-target);
  cursor: pointer;
  font-size: var(--text-sm);
}
.check input, .radio input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__box, .radio__dot {
  width: 20px; height: 20px;
  border: 2px solid var(--color-border-strong);
  border-radius: 4px;
  background: var(--color-surface);
  display: grid; place-items: center;
  transition: all var(--duration-fast);
}
.radio__dot { border-radius: 50%; }
.check input:checked + .check__box { background: var(--color-primary); border-color: var(--color-primary); }
.check input:checked + .check__box::after {
  content: ""; width: 10px; height: 6px; border: 2px solid white; border-top: 0; border-right: 0; transform: rotate(-45deg) translateY(-1px);
}
.radio input:checked + .radio__dot { border-color: var(--color-primary); }
.radio input:checked + .radio__dot::after {
  content: ""; width: 10px; height: 10px; background: var(--color-primary); border-radius: 50%;
}
.toggle { position: relative; }
.toggle__track {
  width: 44px; height: 24px;
  background: var(--color-border-strong);
  border-radius: var(--radius-full);
  position: relative;
  transition: background var(--duration-normal);
}
.toggle__thumb {
  position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--duration-normal) var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle__track { background: var(--color-primary); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateX(20px); }

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--color-surface-muted);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}
.segmented button, .segmented label {
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
}
.segmented button[aria-pressed="true"], .segmented input:checked + span {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* Range slider */
.range-wrap { position: relative; padding-top: 24px; }
.range-wrap input[type="range"] {
  width: 100%;
  height: 6px;
  appearance: none;
  background: var(--color-border);
  border-radius: var(--radius-full);
  outline: none;
}
.range-wrap input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px; height: 20px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
}
.range-bubble {
  position: absolute; top: 0;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: var(--text-xs);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  background: var(--color-surface);
  transition: border-color var(--duration-normal), background var(--duration-normal);
  cursor: pointer;
  min-height: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
}
.dropzone.is-dragover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.dropzone.is-error { border-color: var(--color-error); }
.dropzone__preview { max-width: 120px; max-height: 120px; border-radius: var(--radius-md); object-fit: cover; }

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card--interactive:hover { box-shadow: var(--shadow-md); }

/* Accordion */
.accordion__item { border-bottom: 1px solid var(--color-border); }
.accordion__button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: var(--space-4) 0;
  font: inherit;
  font-weight: 600;
  color: var(--color-text-heading);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  min-height: var(--touch-target);
}
.accordion__panel { padding-bottom: var(--space-4); display: none; }
.accordion__item.is-open .accordion__panel { display: block; }

/* Modal */
dialog.modal {
  border: 0;
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 480px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  background: var(--color-surface);
  color: var(--color-text);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.5); }

/* Toast */
.toast-container {
  position: fixed; bottom: var(--space-4); right: var(--space-4);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.toast {
  background: var(--color-text);
  color: var(--color-surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  max-width: 320px;
}

/* Progress / Spinner */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.progress {
  height: 6px;
  background: var(--color-surface-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__bar { height: 100%; background: var(--color-primary); width: 0; transition: width var(--duration-slow); }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-muted) 25%, var(--color-border) 50%, var(--color-surface-muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.badge--success { background: var(--color-success-soft); color: var(--color-success); }
.badge--warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge--error { background: var(--color-error-soft); color: var(--color-error); }

/* Steps */
.steps { display: flex; gap: var(--space-4); align-items: center; font-size: var(--text-sm); }
.steps__item { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); }
.steps__item.is-active { color: var(--color-primary); font-weight: 600; }
.steps__item.is-done { color: var(--color-success); }

/* Result panel */
.result-panel {
  display: grid; gap: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.result-status { font-weight: 600; }
.result-status.is-ok { color: var(--color-success); }
.result-status.is-out { color: var(--color-error); }

/* Header / Nav enhancements */
.nav-link:hover, .nav-link.active { background: var(--color-primary-soft); color: var(--color-primary); }

/* Tools menu */
.tools-menu { position: relative; }
.tools-menu__panel {
  position: absolute; top: 100%; left: 0;
  min-width: 280px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  display: none;
  z-index: var(--z-dropdown);
}
.tools-menu.is-open .tools-menu__panel { display: block; }
.tools-menu__group { padding: var(--space-1) 0; }
.tools-menu__group strong { display: block; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tools-menu a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text);
  font-size: var(--text-sm);
}
.tools-menu a:hover { background: var(--color-primary-soft); }

/* Mobile menu */
@media (max-width: 760px) {
  .nav-links.is-open { display: flex; }
}

/* Footer */
.site-footer {
  margin-top: var(--space-12);
  padding: var(--space-8) var(--space-4);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.footer-content { max-width: var(--max-content); margin: 0 auto; }
.footer-links { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.footer-link { color: var(--color-text-muted); text-decoration: none; font-size: var(--text-sm); }
.footer-link:hover { color: var(--color-primary); }

/* Guide layout */
.article { max-width: 70ch; margin: 0 auto; padding: var(--space-6) var(--space-4); }
.toc { background: var(--color-surface-muted); border-radius: var(--radius-md); padding: var(--space-4); margin-bottom: var(--space-6); font-size: var(--text-sm); }

/* Ad reserved areas (no shift when shown) */
.ad-slot {
  min-height: 90px;
  margin: var(--space-6) 0;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: transparent;
  font-size: 0;
}
/* Hidden for now as per requirements */
.ad-slot { visibility: hidden; height: 0; overflow: hidden; min-height: 0; }

/* Utility */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.text-center { text-align: center; }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.gap-4 { gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

.tools-menu > button.nav-link {
  background: transparent !important;
  border: 0;
  color: var(--text-main) !important;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
}
[data-theme="dark"] .tools-menu > button.nav-link {
  color: #f1f5f9 !important;
}
