/* ===== CSS VARIABLES & THEME ===== */
:root {
  --container-w: 1200px;
  --accent: #2563EB;
  --accent-dark: #1d4ed8;
  --accent-light: #dbeafe;
  --bg: #ffffff;
  --bg2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --card: #ffffff;
  --header-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --radius: 8px;
  --pass-color: #16a34a;
  --fail-color: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --bg2: #0f172a;
  --text: #e6edf3;
  --muted: #94a3b8;
  --line: #1f2937;
  --card: #0f172a;
  --header-bg: #0b1220;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4);
  --accent-light: #1e3a5f;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ===== TOPBAR / HEADER ===== */
.topbar {
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 60px;
  padding: 0 1rem;
  max-width: var(--container-w);
  margin: 0 auto;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  flex-shrink: 0;
  letter-spacing: -.5px;
}
.brand:hover { text-decoration: none; opacity: .85; }

.nav-links {
  display: flex;
  gap: .25rem;
  list-style: none;
  flex: 1;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  padding: .35rem .6rem;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.nav-links a:hover {
  background: var(--bg2);
  color: var(--accent);
  text-decoration: none;
}

.theme-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  padding: .35rem .5rem;
  font-size: 1rem;
  color: var(--text);
  transition: border-color .15s;
  flex-shrink: 0;
}
.theme-btn:hover { border-color: var(--accent); }

/* Hamburger */
.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .5rem;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text);
  flex-shrink: 0;
}

.mobile-menu {
  display: none;
  background: var(--header-bg);
  border-top: 1px solid var(--line);
  padding: .5rem 1rem 1rem;
}
.mobile-menu.open { display: block; }
.mobile-menu a {
  display: block;
  padding: .5rem 0;
  color: var(--text);
  font-size: .9rem;
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}
.mobile-menu a:last-child { border-bottom: none; }

/* ===== CONTAINER ===== */
.container {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ===== TOOL PAGE LAYOUT ===== */
.tool-page { padding: 2rem 1rem; max-width: 860px; margin: 0 auto; }

.tool-hero { margin-bottom: 1.5rem; }
.tool-hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 700; line-height: 1.2; }
.tool-subtitle { color: var(--muted); margin-top: .4rem; font-size: 1.05rem; }

/* ===== TOOL CONTAINER ===== */
.tool-container {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

/* ===== FORM ELEMENTS ===== */
.field-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.field-group label { font-size: .875rem; font-weight: 600; color: var(--text); }

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 640px) { .form-row-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 400px) { .form-row-3 { grid-template-columns: 1fr; } }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  border: none;
  font-family: inherit;
}
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }

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

.btn-sm { padding: .35rem .75rem; font-size: .85rem; }

.btn-group {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* ===== RESULT CARDS ===== */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.result-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.result-card .label { font-size: .8rem; color: var(--muted); margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .04em; }
.result-card .value { font-size: 1.5rem; font-weight: 700; color: var(--accent); line-height: 1.2; }
.result-card .unit { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

.result-primary .value { font-size: 2rem; }

/* Pass/Fail badge */
.badge {
  display: inline-block;
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-pass { background: #dcfce7; color: var(--pass-color); }
.badge-fail { background: #fee2e2; color: var(--fail-color); }

:root[data-theme="dark"] .badge-pass { background: #14532d; color: #4ade80; }
:root[data-theme="dark"] .badge-fail { background: #7f1d1d; color: #f87171; }

/* ===== AD SLOTS ===== */
.ad-slot {
  background: var(--bg2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .8rem;
  margin: 1.5rem 0;
}
.ad-top { height: 90px; }
.ad-mid { height: 280px; max-width: 336px; }
.ad-bottom { height: 90px; }

/* ===== EXPLAINER & FAQ ===== */
.tool-explainer, .tool-faq {
  margin-bottom: 2rem;
}

.tool-explainer h2, .tool-faq h2, .related-tools h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: .75rem;
  padding-bottom: .4rem;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.tool-explainer p { color: var(--text); line-height: 1.7; }

.faq-item { margin-bottom: 1rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.faq-q {
  padding: .85rem 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.faq-q:hover { background: var(--accent-light); }
.faq-q::after { content: '+'; font-size: 1.2rem; color: var(--accent); }
.faq-item.open .faq-q::after { content: '−'; }
.faq-a { display: none; padding: .85rem 1rem; line-height: 1.7; }
.faq-item.open .faq-a { display: block; }

/* ===== RELATED TOOLS ===== */
.related-tools { margin-bottom: 2rem; }
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
  margin-top: .75rem;
}
.related-card {
  display: block;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: .9rem;
  transition: border-color .15s, background .15s;
  background: var(--card);
}
.related-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  text-decoration: none;
}

/* ===== HUB PAGES ===== */
.hub-page { padding: 2rem 1rem; max-width: 1100px; margin: 0 auto; }
.hub-hero { text-align: center; margin-bottom: 2.5rem; }
.hub-hero h1 { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 700; }
.hub-hero p { color: var(--muted); font-size: 1.1rem; margin-top: .5rem; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.tool-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  box-shadow: var(--shadow);
}
.tool-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--text);
}
.tool-card .card-icon { font-size: 2rem; margin-bottom: .5rem; }
.tool-card .card-title { font-size: 1rem; font-weight: 700; margin-bottom: .35rem; color: var(--accent); }
.tool-card .card-desc { font-size: .85rem; color: var(--muted); line-height: 1.5; }

/* ===== HOMEPAGE ===== */
.hero {
  text-align: center;
  padding: 4rem 1rem 3rem;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg2) 100%);
  border-bottom: 1px solid var(--line);
}
.hero h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); font-size: 1.15rem; margin: .75rem auto 1.5rem; max-width: 560px; }

.trust-strip {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
  font-size: .85rem;
  color: var(--muted);
}
.trust-strip span::before { content: '✓ '; color: var(--pass-color); }

.section-heading {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.homepage-section { padding: 2.5rem 1rem; max-width: 1100px; margin: 0 auto; }

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.cluster-card {
  display: block;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-decoration: none;
  color: var(--text);
  text-align: center;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  box-shadow: var(--shadow);
}
.cluster-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}
.cluster-card .cluster-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.cluster-card .cluster-name { font-weight: 700; color: var(--accent); margin-bottom: .25rem; }
.cluster-card .cluster-count { font-size: .8rem; color: var(--muted); }

/* ===== FOOTER ===== */
.footer {
  background: var(--bg2);
  border-top: 1px solid var(--line);
  padding: 2.5rem 1rem 1.5rem;
  margin-top: auto;
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, 1fr);
  gap: 2rem;
  max-width: var(--container-w);
  margin: 0 auto 1.5rem;
}
.footer-brand { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.footer-section h4 { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .6rem; }
.footer-section a { display: block; color: var(--muted); font-size: .875rem; margin-bottom: .3rem; }
.footer-section a:hover { color: var(--accent); text-decoration: none; }
.footer-tagline { color: var(--muted); font-size: .875rem; margin-top: .4rem; }
.footer-bottom {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  max-width: var(--container-w);
  margin: 0 auto;
}
@media (max-width: 768px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .footer-grid { grid-template-columns: 1fr; }
}

/* ===== TABS ===== */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--line); margin-bottom: 1.25rem; }
.tab-btn {
  padding: .6rem 1.2rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  font-family: inherit;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== TABLE ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-top: .75rem;
}
.data-table th {
  background: var(--bg2);
  padding: .5rem .75rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--line);
}
.data-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--line);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg2); }

/* ===== SLIDER ===== */
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== DONUT CHART ===== */
.donut-wrapper { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; margin-top: 1rem; }
.donut-chart { width: 140px; height: 140px; flex-shrink: 0; }
.donut-legend { display: flex; flex-direction: column; gap: .4rem; }
.legend-item { display: flex; align-items: center; gap: .5rem; font-size: .875rem; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ===== COPY BUTTON ===== */
.copy-btn {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .3rem .7rem;
  cursor: pointer;
  font-size: .8rem;
  color: var(--muted);
  font-family: inherit;
  transition: background .15s;
}
.copy-btn:hover { background: var(--accent-light); color: var(--accent); }

/* ===== TEXTAREA MONO ===== */
.mono-area {
  font-family: 'Courier New', monospace;
  font-size: .9rem;
  resize: vertical;
  min-height: 80px;
}

/* ===== HIGHLIGHT ===== */
.highlight-box {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  padding: .85rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1rem 0;
  font-size: .95rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .hamburger { display: block; }
  .tool-page { padding: 1.25rem .75rem; }
  .tool-container { padding: 1rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .result-grid { grid-template-columns: 1fr; }
}
