/* ==========================================================================
   Pieter's Toolbox - Unified Modern Design System & CSS Styles
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Color Palette - Light Theme */
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --surface-hover: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --border-focus: #818cf8;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark {
  /* Color Palette - Dark Theme */
  --primary-color: #6366f1;
  --primary-hover: #818cf8;
  --primary-light: #1e1b4b;
  --bg-color: #0f172a;
  --surface-color: #1e293b;
  --surface-hover: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border-color: #334155;
  --border-focus: #a5b4fc;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* --------------------------------------------------------------------------
   2. Base & Layout Structure
   -------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 80px;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.page-wrapper {
  display: flex;
  width: 100%;
  max-width: 1440px;
  justify-content: center;
  position: relative;
}

.main-content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 100px);
}

.container {
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   3. Header & Navigation Controls
   -------------------------------------------------------------------------- */
.header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.header h1 {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.header p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 750px;
  margin: 0 auto;
}

/* Fixed Navigation Buttons */
.theme-toggle,
.back-button {
  position: fixed;
  top: 20px;
  z-index: 1000;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
}

.theme-toggle {
  right: 20px;
}

.back-button {
  left: 20px;
}

.theme-toggle:hover,
.back-button:hover {
  box-shadow: var(--shadow-md);
  background-color: var(--surface-hover);
}

.back-button a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
}

.theme-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

/* Switch Toggle Styling */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  background-color: var(--text-muted);
  border-radius: 34px;
  top: 0; left: 0; right: 0; bottom: 0;
  transition: 0.3s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* --------------------------------------------------------------------------
   4. Search Bar Component
   -------------------------------------------------------------------------- */
.search-bar-wrapper {
  position: relative;
  max-width: 550px;
  margin: 0 auto 2.5rem auto;
  width: 100%;
}

.search-bar-wrapper input {
  width: 100%;
  padding: 14px 20px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-color);
  background-color: var(--surface-color);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: var(--transition);
}

.search-bar-wrapper input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  z-index: 900;
  display: none;
}

.search-results li {
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 500;
  transition: background-color 0.15s ease;
}

.search-results li:last-child {
  border-bottom: none;
}

.search-results li:hover {
  background-color: var(--surface-hover);
  color: var(--primary-color);
}

/* --------------------------------------------------------------------------
   5. Tool Navigation Grid & Tiles
   -------------------------------------------------------------------------- */
.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 3rem;
}

.nav-tile {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem 1rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  min-height: 120px;
}

.nav-tile:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
  background-color: var(--surface-hover);
  color: var(--primary-color);
}

.nav-tile .icon {
  width: 2rem;
  height: 2rem;
  color: var(--primary-color);
}

/* --------------------------------------------------------------------------
   6. Tool Card & Form Layouts
   -------------------------------------------------------------------------- */
.tool-container,
.calculator-container {
  max-width: 800px;
  margin: 0 auto 2.5rem auto;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 2.25rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
}

.tool-container h2,
.calculator-container h2 {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.form-group,
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

input[type="number"],
input[type="text"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: inherit;
  transition: var(--transition);
}

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

button,
.calculator-btn {
  background-color: var(--primary-color);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
}

button:hover,
.calculator-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

/* Secondary & Action Buttons */
.btn-secondary {
  background-color: var(--surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

/* --------------------------------------------------------------------------
   7. Tool Specific Components & Output Display
   -------------------------------------------------------------------------- */
.result-box {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1.05rem;
}

.result-box p {
  margin-bottom: 0.5rem;
}

.result-box p:last-child {
  margin-bottom: 0;
}

/* Interactive Tabs & Radio Groups */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.tabs button {
  background: none;
  color: var(--text-secondary);
  border: none;
  padding: 8px 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  width: auto;
}

.tabs button.active {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.horizontal-radio {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Data Tables & Charts */
table {
  width: 100%;
  margin-top: 1.5rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
}

th {
  background-color: var(--bg-color);
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

td {
  text-align: right;
  color: var(--text-secondary);
}

canvas {
  margin-top: 1.5rem;
  width: 100% !important;
  max-height: 380px;
}

/* File Upload & Dropzone */
#dropZone {
  border: 2px dashed var(--primary-color);
  border-radius: var(--radius-md);
  padding: 2.5rem 1.5rem;
  background-color: var(--bg-color);
  color: var(--text-secondary);
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

#dropZone.dragover,
#dropZone:hover {
  background-color: var(--primary-light);
  border-color: var(--primary-hover);
  color: var(--primary-color);
}

/* Preview Cards */
.preview {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.25rem;
}

.card {
  background-color: var(--surface-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-3px);
}

.card img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   8. AdSense Containers & CLS Prevention
   -------------------------------------------------------------------------- */
.ad-wrapper {
  width: 100%;
  margin: 1.5rem 0;
  min-height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.side-ad {
  position: fixed;
  top: 100px;
  width: 160px;
  min-height: 600px;
  z-index: 10;
}

.left-ad {
  left: 20px;
}

.right-ad {
  right: 20px;
}

@media (max-width: 1350px) {
  .side-ad {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   9. FAQ Section Component
   -------------------------------------------------------------------------- */
.faq-section {
  margin-top: 3rem;
  margin-bottom: 3rem;
  padding: 2rem;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.faq-section h2 {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  color: var(--primary-color);
  margin-bottom: 1.5rem;
}

.faq-item {
  margin-bottom: 1.5rem;
}

.faq-item:last-child {
  margin-bottom: 0;
}

.faq-section h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.faq-section p,
.faq-section ul {
  color: var(--text-secondary);
  font-size: 1rem;
}

.faq-section ul {
  padding-left: 1.5rem;
  margin-top: 0.5rem;
}

/* --------------------------------------------------------------------------
   10. Footer & Cookie Banner
   -------------------------------------------------------------------------- */
.footer {
  margin-top: auto;
  padding: 2rem 1rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
  width: 100%;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.75rem;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

.cookie-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  display: none;
}

.cookie-banner.show {
  display: block;
}

.cookie-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.cookie-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.cookie-buttons {
  display: flex;
  gap: 0.5rem;
}

.cookie-buttons button {
  width: auto;
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   11. Responsive Breakpoints
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    padding-top: 70px;
  }

  .header h1 {
    font-size: 1.85rem;
  }

  .header p {
    font-size: 1rem;
  }

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

  .nav-tile {
    padding: 1rem 0.75rem;
    font-size: 0.9rem;
    min-height: 100px;
  }

  .theme-toggle,
  .back-button {
    top: 12px;
    padding: 6px 10px;
  }

  .theme-toggle {
    right: 12px;
  }

  .back-button {
    left: 12px;
  }

  .theme-label {
    display: none;
  }

  .tool-container,
  .calculator-container {
    padding: 1.5rem;
  }
}

@media (max-width: 480px) {
  .back-button span {
    display: none;
  }

  .cookie-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .cookie-buttons {
    flex-direction: column;
  }

  .cookie-buttons button {
    width: 100%;
  }
}