/* =========================
   BASE RESET
========================= */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  background: #f3f4f6;
  color: #111827;
}

img, svg, iframe, table {
  max-width: 100%;
}

/* =========================
   TOP BAR (LANG SWITCH)
========================= */
.top-banner {
  width: 100%;
  background: white;
  padding: 25px 20px;
  text-align: center;
  border-bottom: 1px solid #e5e7eb;
  position: relative;
}

.lang-switch {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.flag {
  width: 26px;
  cursor: pointer;
  border-radius: 4px;
  transition: 0.2s;
}

.flag:hover {
  transform: scale(1.1);
}

/* =========================
   HERO (LOGO HOME)
========================= */
.hero-center {
  max-width: 500px;
  width: 100%;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 12px;
}

/* =========================
   HOMEPAGE MAIN
========================= */
.main {
  padding: 30px 20px;
}

/* =========================
   HOMEPAGE / MAIN BANNER
========================= */
.highlight-box {
  width: 100%;
  max-width: 1010px;
  margin: 0 auto 30px auto;
  background: white;
  padding: 20px;
  border-radius: 16px;
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.main-banner {
  width: 100%;
  max-width: 970px;
  height: 250px;
  display: block;
  margin: 0 auto;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
}

@media (max-width: 768px) {
  .main-banner {
    max-width: 100%;
    height: 140px;
  }

  .main-banner-ad {
    max-width: 100%;
    min-height: 50px;
  }

  /* Homepage */
  .grid {
    grid-template-columns: 1fr;
  }

  .card-icon {
    font-size: 30px;
  }

  .card-label {
    font-size: 18px;
  }

  .main {
    padding: 16px;
  }

  /* Barra ricerca e logo */
  section div[style*="display:inline-block"] {
    width: 100% !important;
    display: block !important;
  }

  #search-input {
    width: 100% !important;
    box-sizing: border-box;
  }

  #search-results {
    width: 100% !important;
  }

  #hero-img {
    max-width: 70% !important;
  }

  /* Sidebar mobile */
  .geo-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 10px;
    padding: 10px;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    align-items: center;
  }

  .sidebar-logo {
    display: none;
  }

  .back-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.85em;
  }

  .tool-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
  }

  .tool-item {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.85em;
  }

  /* Content area */
  .content {
    padding: 12px;
  }

  /* Tool box */
  .tool-box {
    padding: 12px;
    margin-top: 10px;
  }

  /* Tool layout flex — colonna su mobile */
  .tool-box > div[style*="display:flex"],
  .tool-box > div[style*="display: flex"] {
    flex-direction: column !important;
  }

/* Tabelle tool */
  .excel-table td {
    padding: 8px 6px;
    white-space: normal;
    font-size: 0.9em;
  }

  .excel-table input,
  .excel-table select {
    width: 100%;
    max-width: 100%;
    font-size: 1em;
    padding: 8px;
  }

  /* Banner top categoria */
  .geo-top-banner {
    padding: 6px 0;
  }

  .geo-main-banner {
    border-radius: 8px;
    min-height: 60px;
  }

  /* Footer */
  .footer-banner {
    margin-top: 20px;
    padding: 10px 0;
  }

  .footer-ad {
    min-height: 50px;
  }
}

/* =========================
   HOMEPAGE / TOP ADSENSE BANNER
========================= */
.main-banner-ad {
  width: 100%;
  max-width: 970px;
  min-height: 90px;
  display: block;
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

@media (max-width: 768px) {
  .main-banner-ad {
    max-width: 100%;
    min-height: 50px;
  }
}

/* =========================
   GRID CATEGORIE
========================= */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 900px;
  margin: auto;
}

.card {
  background: #e5e7eb;
  padding: 18px;
  border-radius: 14px;
  text-align: center;
  text-decoration: none;
  color: #111827;
  border: 1px solid #d1d5db;
  transition: 0.2s;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

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

.card-icon {
  font-size: 40px;
  line-height: 1;
}

.card-label {
  font-size: 25px;
}

/* =========================
   FOOTER ADS
========================= */
.footer-banner {
  width: 100%;
  background: #f3f4f6;
  padding: 20px 0;
  margin-top: 40px;
  display: flex;
  justify-content: center;
  border-top: 1px solid #e5e7eb;
}

.footer-ad {
  width: 90%;
  max-width: 1000px;
  min-height: 90px;
  background: #e5e7eb;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================
   CATEGORY PAGE BASE LAYOUT
========================= */
.category-page {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid #e5e7eb;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.sidebar-logo {
  width: 100%;
  max-width: 160px;
  border-radius: 10px;
}

.back-btn {
  text-decoration: none;
  background: #e5e7eb;
  padding: 10px;
  border-radius: 10px;
  color: #111827;
  text-align: center;
  border: 1px solid #d1d5db;
  transition: 0.2s;
}

.back-btn:hover {
  background: #d1d5db;
}

.tool-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-item {
  text-decoration: none;
  padding: 10px;
  background: #f3f4f6;
  border-radius: 10px;
  color: #111827;
  border: 1px solid #e5e7eb;
  font-size: 0.95em;
}

.tool-item:hover {
  background: #e5e7eb;
}

.tool-item--active {
  background: #2563eb;
  color: white;
  border-color: #1e40af;
}

/* content area */
.content {
  flex: 1;
  min-width: 0;
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* =========================
   CATEGORY TOP LAYOUT
========================= */
.geo-header {
  position: relative;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}

.geo-lang {
  position: absolute;
  top: 10px;
  right: 15px;
  z-index: 10;
}

.geo-top-banner {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 10px 0;
  background: white;
}

.geo-main-banner {
  width: 100%;
  max-width: 970px;
  min-height: 90px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  margin: 0 auto;
  display: block;
}

/* =========================
   CATEGORY LAYOUT
========================= */
.geo-layout {
  display: flex;
  width: 100%;
  min-height: calc(100vh - 290px);
}

.geo-layout .sidebar {
  margin-top: 0;
}

/* =========================
   TOOL BOX
========================= */
.tool-box {
  width: 100%;
  max-width: 900px;
  background: white;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid #e5e7eb;
  margin-top: 20px;
}

/* =========================
   TOOL TABLE
========================= */
.excel-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 15px;
}

.excel-table td {
  padding: 10px;
  border: 1px solid #e5e7eb;
  white-space: normal;
}

.excel-table input, .excel-table select {
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95em;
}

.tool-box button {
  width: 100%;
  padding: 10px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.tool-box button:hover {
  background: #1e40af;
}

/* =========================
   TOOL LAYOUT A DUE COLONNE
   (input/risultati a sinistra, immagine a destra)
   -------------------------------------------------
   flex: 1 1 ... (grow shrink basis) invece di flex: 0 0 ...:
   le colonne possono restringersi su schermi piccoli, e con
   flex-wrap vanno a capo automaticamente sotto la somma delle
   due basi + gap, senza bisogno di nascondere nulla via media
   query.
========================= */
.tool-container {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.tool-column-left {
  flex: 1 1 400px;
  max-width: 100%;
}

.tool-column-right {
  flex: 1 1 300px;
  text-align: center;
}

/* Colonna "Passaggi" dei risolutori di equazioni: stessa logica
   flessibile di tool-column-right, ma SENZA il riordino su mobile,
   perché qui il contenuto sono i passaggi della risoluzione, che
   devono restare sotto l'area di input/risultati anche su schermi
   piccoli — a differenza dell'immagine, che invece va sopra. */
.tool-column-steps {
  flex: 1 1 300px;
}

@media (max-width: 480px) {
  .tool-column-right {
    order: -1;
  }

  .tool-column-right img {
    max-height: 250px;
  }
}

/* =========================
   STAMPA
========================= */
@media print {
  .geo-top-banner,
  .geo-header,
  .lang-switch,
  .back-btn,
  .footer-banner,
  .tool-list {
    display: none !important;
  }

  .geo-layout {
    display: block;
    min-height: auto;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .sidebar-logo {
    margin: 0 auto 20px auto;
  }

  .content {
    width: 100%;
    padding: 0;
    align-items: center;
  }

  .tool-box {
    box-shadow: none;
    border: none;
  }
}

/* =========================
   RESPONSIVE MOBILE
========================= */
@media (max-width: 768px) {

  /* Homepage */
  .grid {
    grid-template-columns: 1fr;
  }

  .card-icon {
    font-size: 30px;
  }

  .card-label {
    font-size: 18px;
  }

  .main {
    padding: 16px;
  }

  /* Sidebar mobile — diventa barra orizzontale scorrevole in cima */
  .geo-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 10px;
    padding: 10px;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    align-items: center;
  }

  .sidebar-logo {
    display: none;
  }

  .back-btn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.85em;
  }

  .tool-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
  }

  .tool-item {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 0.85em;
  }

  /* Content area */
  .content {
    padding: 12px;
  }

  /* Tool box */
  .tool-box {
    padding: 12px;
    margin-top: 10px;
  }

  /* Tool layout flex — colonna su mobile */
  .tool-box > div[style*="display:flex"],
  .tool-box > div[style*="display: flex"] {
    flex-direction: column !important;
  }

/* Tabelle tool */
  .excel-table td {
    padding: 8px 6px;
    white-space: normal;
    font-size: 0.9em;
  }

  .excel-table input,
  .excel-table select {
    width: 100%;
    max-width: 100%;
    font-size: 1em;
    padding: 8px;
  }

  /* Banner top categoria */
  .geo-top-banner {
    padding: 6px 0;
  }

  .geo-main-banner {
    border-radius: 8px;
    min-height: 60px;
  }

  /* Footer */
  .footer-banner {
    margin-top: 20px;
    padding: 10px 0;
  }

  .footer-ad {
    min-height: 50px;
  }
}

/* =========================
   FOOTER LINKS (About/Privacy/Cookie)
========================= */
.footer-banner-wrapper {
  width: 100%;
  background: #f3f4f6;
  border-top: 1px solid #e5e7eb;
}

.footer-links {
  width: 100%;
  padding: 20px 0 24px 0;
  text-align: center;
}

.footer-links-nav {
  margin-bottom: 8px;
}

.footer-links-nav a {
  color: #374151;
  text-decoration: none;
  font-size: 0.9em;
  transition: 0.2s;
}

.footer-links-nav a:hover {
  color: #2563eb;
  text-decoration: underline;
}

.footer-links-sep {
  color: #d1d5db;
  margin: 0 10px;
}

.footer-copyright {
  color: #9ca3af;
  font-size: 0.8em;
  margin: 0;
}

@media (max-width: 768px) {
  .footer-links-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .footer-links-sep {
    display: none;
  }
}
