/* ============================================
   The Useful Pages — Global Stylesheet
   ============================================ */

:root {
  --primary: #236A77;
  --primary-dark: #1a4f59;
  --primary-light: #2d8699;
  --accent: #D6AA76;
  --accent-dark: #c49055;
  --bg: #FEFEFE;
  --bg-secondary: #f8fafc;
  --text: #262520;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --nav-bg: #ffffff;
  --footer-bg: #1e293b;
  --footer-text: #94a3b8;
  --mono-bg: #1e293b;
  --mono-text: #e2e8f0;
  --result-bg: #f0fafb;
  --result-border: #b2dce2;
  --table-th-bg: #f3f4f6;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --card-bg: #1e293b;
  --input-bg: #0f172a;
  --nav-bg: #1e293b;
  --footer-bg: #020617;
  --footer-text: #64748b;
  --mono-bg: #020617;
  --mono-text: #e2e8f0;
  --result-bg: #164e63;
  --result-border: #0e7490;
  --table-th-bg: #334155;
  --shadow: 0 1px 4px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.2);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  margin: 0;
  transition: background 0.2s, color 0.2s;
}

/* ── Typography ─────────────────────────────── */
h1, h2, h3, h4 { line-height: 1.25; color: var(--text); }
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ── Navigation ─────────────────────────────── */
.site-nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.2s, border-color 0.2s;
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.nav-logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-logo:hover { color: var(--primary-dark); }
.nav-right {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

/* ── All Tools mega-menu button ──────────────── */
.nav-all-tools-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  min-height: 40px;
  white-space: nowrap;
}
.nav-all-tools-btn:hover,
.nav-all-tools-btn.open { background: var(--primary); color: #fff; }
.nav-all-tools-btn .caret {
  font-size: 0.7rem;
  transition: transform 0.2s;
}
.nav-all-tools-btn.open .caret { transform: rotate(180deg); }

/* ── Mega-menu panel ─────────────────────────── */
.mega-menu {
  display: none;
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  z-index: 99;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}
.mega-menu.open { display: block; }
.mega-menu-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 1.75rem 2rem;
}
.mega-col {}
.mega-col-heading {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 0 0 0.6rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.mega-col a {
  display: block;
  font-size: 0.8125rem;
  color: var(--text);
  text-decoration: none;
  padding: 0.3rem 0.375rem;
  border-radius: 5px;
  transition: background 0.1s, color 0.1s;
  line-height: 1.4;
}
.mega-col a:hover { background: var(--bg-secondary); color: var(--primary); }

/* ── Dark mode toggle ────────────────────────── */
.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg-secondary); color: var(--primary); border-color: var(--primary); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Hamburger / mobile menu ─────────────────── */
.hamburger {
  display: none;
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text);
  border-radius: 8px;
}
.hamburger:hover { background: var(--bg-secondary); }
.mobile-menu {
  display: none;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 1rem;
  max-height: 70vh;
  overflow-y: auto;
}
.mobile-menu.open { display: block; }
.mobile-category { margin-bottom: 1rem; }
.mobile-category h3 {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 0.5rem;
  margin: 0 0 0.4rem 0;
}
.mobile-category a {
  display: flex;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  min-height: 44px;
  align-items: center;
}
.mobile-category a:hover { background: var(--result-bg); color: var(--primary); }

@media (max-width: 768px) {
  .nav-all-tools-btn { display: none; }
  .hamburger { display: flex; }
}
@media (min-width: 769px) {
  .hamburger { display: none; }
}

/* ── Page Layout ─────────────────────────────── */
.page-wrapper {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}
.tool-main { flex: 1; min-width: 0; }
.tool-sidebar { width: 300px; flex-shrink: 0; }
@media (max-width: 1024px) { .tool-sidebar { display: none; } }

/* ── Cards ───────────────────────────────────── */
.tool-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.instructions-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.result-card {
  background: var(--result-bg);
  border: 1px solid var(--result-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}
.related-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.5rem;
}
.related-card h3 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.75rem 0;
}
.related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.related-links a {
  font-size: 0.8125rem;
  color: var(--primary);
  background: var(--result-bg);
  border: 1px solid var(--result-border);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  text-decoration: none;
  transition: background 0.1s;
}
.related-links a:hover { opacity: 0.8; }

/* ── Forms & Inputs ─────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.2s, color 0.2s;
  font-family: inherit;
  min-height: 44px;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(35,106,119,0.12);
}
.form-textarea { resize: vertical; min-height: 120px; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}
.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.input-group .form-input { flex: 1; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-accent { background: var(--accent); color: var(--text); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--result-bg); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text); }
.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8125rem; min-height: 36px; }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ── Range input ─────────────────────────────── */
input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  accent-color: var(--primary);
  cursor: pointer;
  min-height: unset;
}

/* ── Results ─────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
}
.stat-box {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}
.result-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.result-row:last-child { border-bottom: none; }
.result-label { font-size: 0.875rem; color: var(--text-muted); }

/* ── Tabs ────────────────────────────────────── */
.tab-group {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.tab-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
  font-family: inherit;
}
.tab-btn:hover { border-color: var(--primary); color: var(--primary); }
.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-primary { background: #e0f2f5; color: var(--primary); }
.badge-accent { background: #fdf4e7; color: #8b5e1a; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .badge-primary { background: rgba(35,106,119,0.25); }
[data-theme="dark"] .badge-accent { background: rgba(214,170,118,0.2); color: var(--accent); }
[data-theme="dark"] .badge-green { background: rgba(22,101,52,0.3); color: #4ade80; }
[data-theme="dark"] .badge-red { background: rgba(153,27,27,0.3); color: #f87171; }

/* ── Strength meter ─────────────────────────── */
.strength-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.strength-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
}

/* ── Toast ───────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1e293b;
  color: #f1f5f9;
  padding: 0.625rem 1.125rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
[data-theme="dark"] #toast { background: #0f172a; border: 1px solid var(--border); }

/* ── Monospace areas ─────────────────────────── */
.mono-output {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875rem;
  background: var(--mono-bg);
  color: var(--mono-text);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}
.code-area {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875rem;
  min-height: 200px;
  background: var(--bg-secondary);
}

/* ── Table ───────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  background: var(--table-th-bg);
  padding: 0.6rem 0.875rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table td {
  padding: 0.6rem 0.875rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-secondary); }
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  overflow-x: auto;
}

/* ── Footer ──────────────────────────────────── */
.site-footer {
  background: var(--footer-bg);
  color: var(--footer-text);
  padding: 2rem 1rem;
  margin-top: 3rem;
  font-size: 0.875rem;
  transition: background 0.2s;
}
.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: space-between;
  align-items: center;
}
.footer-logo {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}
.footer-links { display: flex; flex-wrap: wrap; gap: 1rem; }
.footer-links a { color: var(--footer-text); text-decoration: none; transition: color 0.15s; }
.footer-links a:hover { color: #fff; }
.footer-copy { color: var(--footer-text); font-size: 0.8125rem; opacity: 0.7; }

/* ══════════════════════════════════════════════
   AD ZONES
   ══════════════════════════════════════════════ */
.ad-container {
  margin: 20px auto;
  text-align: center;
  min-height: 90px;
  max-width: 100%;
  overflow: hidden;
}
.ad-sidebar {
  position: sticky;
  top: 84px;
  margin: 0;
}
.ad-top-banner, .ad-footer-banner { margin: 20px auto; }
.ad-content-middle { margin: 30px auto; max-width: 100%; }

@media (max-width: 768px) {
  .ad-top-banner ins,
  .ad-footer-banner ins {
    width: 320px !important;
    height: 50px !important;
  }
  .ad-sidebar { display: none !important; }
}
@media (min-width: 769px) {
  .ad-container { margin: 30px auto; }
}

/* ── Hero (homepage) ─────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 3.5rem 1rem;
  text-align: center;
}
.hero h1 { color: #fff; font-size: 2.25rem; margin: 0 0 0.75rem 0; }
.hero p { font-size: 1.125rem; opacity: 0.9; max-width: 600px; margin: 0 auto 1.5rem; }
.hero-search {
  display: flex;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid rgba(255,255,255,0.3);
}
.hero-search input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.75rem 1rem;
  color: #fff;
  font-size: 0.9375rem;
  outline: none;
}
.hero-search input::placeholder { color: rgba(255,255,255,0.7); }
.hero-search button {
  background: var(--accent);
  border: none;
  padding: 0 1.25rem;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s;
}
.hero-search button:hover { background: var(--accent-dark); }

/* ── Tool cards (homepage) ───────────────────── */
.category-section { margin-bottom: 3rem; }
.category-heading {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.875rem;
}
.tool-chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.125rem;
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.tool-chip:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 12px rgba(35,106,119,0.12);
  transform: translateY(-1px);
  color: var(--text);
}
.tool-chip-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
  margin-top: 0.1rem;
}
.tool-chip-name { font-weight: 600; font-size: 0.9375rem; line-height: 1.3; }
.tool-chip-desc { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.15rem; line-height: 1.4; }
.tool-chip.hidden-tool { display: none; }

/* ── Recently Used ───────────────────────────── */
.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--result-bg);
  border: 1px solid var(--result-border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.1s;
}
.recent-chip:hover { opacity: 0.8; color: var(--primary); }
/* Dark mode: --primary on --result-bg is nearly invisible (~1.2:1); use high-contrast light text */
[data-theme="dark"] .recent-chip {
  color: #7dd3e0;
  border-color: #0e7490;
}
[data-theme="dark"] .recent-chip:hover { color: #a5f3fc; opacity: 1; }

/* ── Page title ──────────────────────────────── */
.page-title {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
  line-height: 1.2;
}
.page-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9375rem;
}

/* ── Disclaimer ──────────────────────────────── */
.disclaimer {
  background: var(--bg-secondary);
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

/* ── Misc utility ────────────────────────────── */
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent-dark); }
.text-muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.hidden { display: none !important; }

@media (max-width: 640px) {
  .hero h1 { font-size: 1.625rem; }
  .page-wrapper { padding: 1.25rem 0.875rem; }
  .tool-card, .instructions-card { padding: 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
