/* ===========================================================
   ROOT VARIABLES
   =========================================================== */
:root {
  --bg: #0b0e14;
  --panel: #111522;
  --muted: #8a93a6;
  --text: #e7ecf3;
  --accent: #7dd3fc;
  --accent-2: #a78bfa;
  --ring: rgba(125, 211, 252, 0.4);
  --card: #0f1422;
  --border: #1b2236;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .03);
  --radius: 16px;

  /* Spacing system - using rem for scalability */
  --spacing-xs: 0.5rem;    /* 8px */
  --spacing-sm: 0.75rem;    /* 12px */
  --spacing-md: 1rem;       /* 16px */
  --spacing-lg: 1.25rem;    /* 20px */
  --spacing-xl: 1.75rem;    /* 28px */
  --spacing-2xl: 4rem;      /* 64px */
  
  /* Container settings */
  --container-max-width: 1100px;
  --container-padding-horizontal: var(--spacing-lg);  /* 20px */
  --container-padding-top: var(--spacing-sm);          /* 12px */
  --container-padding-bottom: var(--spacing-2xl);       /* 64px */
  
  /* Header settings */
  --header-padding-vertical: var(--spacing-md);         /* 16px */
  --header-padding-vertical-mobile: var(--spacing-sm);  /* 12px */
  --header-padding-horizontal: var(--spacing-lg);       /* 20px */

  /* Custom control width */
  --select-width: 120px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --muted: #5b6374;
    --text: #0f1222;
    --accent: #0284c7;
    --accent-2: #6d28d9;
    --ring: rgba(2, 132, 199, .24);
    --card: #ffffff;
    --border: #e6e8f0;
    --shadow: 0 10px 24px rgba(2, 6, 23, 0.06), 0 2px 8px rgba(2, 6, 23, 0.04);
  }
}

/* ===========================================================
   GLOBAL RESETS & BASE
   =========================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center; /* centra orizzontalmente tutto */
    background: var(--bg);
    color: var(--text);
}

.container {
    width: 100%;
    max-width: var(--container-max-width);
    padding: var(--container-padding-top) var(--container-padding-horizontal) var(--container-padding-bottom);
    display: flex;
    flex-direction: column;
    align-items: center; /* centra i card */
}

/* ===========================================================
   HEADER / NAVIGATION
   =========================================================== */
header, .site-header { 
    width: 100%;
    align-self: stretch;
    display: flex; 
    align-items: center; 
    justify-content: center;
    margin-bottom: var(--spacing-sm); 
    padding: var(--header-padding-vertical) 0;
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}

/* Header wrapper matches container boundaries */
.header-wrapper {
    width: 100%;
    max-width: var(--container-max-width);
    padding: 0 var(--header-padding-horizontal);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    box-sizing: border-box;
}

/* Mobile: smaller padding, elements at edges */
@media (max-width: 768px) {
    header, .site-header {
        padding: var(--header-padding-vertical-mobile) 0;
    }
    .header-wrapper {
        padding: 0 var(--header-padding-horizontal);
        gap: var(--spacing-sm);
        align-items: flex-start;
    }
    .brand {
        gap: var(--spacing-xs);
    }
    .logo {
        width: 32px;
        height: 42px;
    }
    .title {
        font-size: 0.9rem;
    }
    .site-nav {
        gap: var(--spacing-sm);
        flex: 1 1 auto;
        min-width: fit-content;
    }
    .site-nav a {
        font-size: 0.85rem;
    }
}

/* Desktop: match container boundaries */
@media (min-width: 769px) {
    header, .site-header {
        padding: var(--header-padding-vertical) 0;
    }
    .header-wrapper {
        padding: 0 var(--header-padding-horizontal);
    }
}
.brand { 
    display: flex; 
    align-items: center; 
    gap: var(--spacing-sm); 
    flex-shrink: 0;
}
.logo { width: 38px; height: 50px; display: inline-block; flex-shrink: 0; }
.title { 
    font-weight: 700; 
    letter-spacing: -0.01em; 
    font-size: 1.25rem; 
    margin: 0; 
}
.subtitle { color: var(--muted); font-size: .95rem; font-weight: 400; }

/* Navigation */
.site-nav { 
    display: flex; 
    gap: 20px; 
    flex-shrink: 0;
    align-items: center;
}
.site-nav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: color 0.2s ease, border-bottom 0.2s ease;
  position: relative;
}
.site-nav a::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0%;
  height: 2px;
  background: var(--accent);
  transition: width 0.2s ease;
}
.site-nav a:hover, .site-nav a:focus { color: var(--accent); }
.site-nav a:hover::after, .site-nav a:focus::after { width: 100%; }

/* ===========================================================
   INTRO SECTION
   =========================================================== */
.intro { margin-bottom: 20px; }
.intro-title { font-size: 1.1rem; font-weight: 600; margin: 0 0 10px; color: var(--text); }
.intro-text { font-size: .95rem; line-height: 1.6; color: var(--muted); margin: 0; }
.intro p a { color: var(--accent); text-decoration: underline; transition: color 0.2s ease; }
.intro p a:hover { color: var(--accent-2); }

/* ===========================================================
   FAQ SECTION
   =========================================================== */
.faq-item {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border);
}

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

.faq-question {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 var(--spacing-sm) 0;
}

.faq-answer {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--muted);
    margin: 0;
}

/* ===========================================================
   ABOUT US SECTION
   =========================================================== */
.about-content {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.about-subtitle {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 var(--spacing-sm) 0;
}

.about-content p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--muted);
    margin: 0 0 var(--spacing-md) 0;
}

.about-content p:last-child {
    margin-bottom: 0;
}

/* ===========================================================
   CARD / PANELS
   =========================================================== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 16px; }

/* ===========================================================
   TOOLBAR & CONTROLS
   =========================================================== */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.controls { display: flex; gap: 12px; flex-wrap: wrap; }
label { font-size: .85rem; color: var(--muted); font-weight: 500; }

/* ===========================================================
   INPUTS SECTION - All inputs together
   =========================================================== */
.inputs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
}

.inputs-section .field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.inputs-section .field label {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.9rem;
    color: var(--text);
    font-weight: 500;
}

.inputs-section .field input,
.inputs-section .field select {
    width: 100%;
    min-height: 44px; /* Better touch target for mobile */
}

.inputs-section .info-icon {
    display: inline-flex;
    align-items: center;
    cursor: help;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.inputs-section .info-icon:hover {
    opacity: 1;
}

/* Mobile: stack inputs vertically */
@media (max-width: 768px) {
    .inputs-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }
}

/* ===========================================================
   INPUTS & SELECTS
   =========================================================== */
.select-field,
select,
#runoff-coeff,
#cap-input,
input[type="search"],
.field input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.03));
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-family: 'Poppins', sans-serif;
  font-size: .9rem;
  transition: box-shadow .2s ease, border-color .2s ease, transform .02s ease;
}
.select-field,
select,
#runoff-coeff { width: var(--select-width); cursor: pointer; text-align: center; }
.select-field:focus,
select:focus,
#runoff-coeff:focus,
#cap-input:focus,
input[type="search"]:focus,
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}
.select-sm { --select-width: 90px; }
.select-md { --select-width: 120px; }
.select-lg { --select-width: 160px; }
#runoff-coeff { --select-width: 60px; }

/* ===========================================================
   FIELD LAYOUTS
   =========================================================== */
.field { display: flex; flex-direction: column; margin: 12px 0; flex: 1; min-width: 180px; }
.field.cap { flex: 2; min-width: 240px; }
.field label { font-size: 0.8rem; color: var(--text); margin-bottom: 6px; }

/* ===========================================================
   GRID & LAYOUT
   =========================================================== */
main { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid { grid-template-columns: 1.1fr 1.4fr; } }

/* ===========================================================
   CHARTS / DATA VISUALIZATION
   =========================================================== */
.section-title { font-size: .95rem; letter-spacing: .02em; color: var(--muted); margin: 0 0 10px; font-weight: 500; }
.chart-wrap { padding: 12px 12px 6px; }
canvas { width: 100%; height: 300px; display: block; }

/* ===========================================================
   PILLBAR (Filters / Toggles)
   =========================================================== */
.pillbar { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .02);
  font-size: .85rem;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}
.pill[data-active="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

/* ===========================================================
   AUTOCOMPLETE
   =========================================================== */
.awesomplete { position: relative; }
.awesomplete ul {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
  padding: 0;
  margin: 4px 0 0;
  list-style: none;
}
.awesomplete li {
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: .95rem;
  transition: background .2s ease, color .2s ease;
  background: var(--card);
}
.awesomplete li:hover,
.awesomplete li[aria-selected="true"] {
  background: linear-gradient(135deg, rgba(125, 211, 252, .25), rgba(167, 139, 250, .25));
  color: var(--accent);
}

/* ===========================================================
   WATER BUBBLE WIDGET
   =========================================================== */
#waterBubble { width: 180px; height: 180px; margin: 20px auto; border-radius: 50%; }

/* ===========================================================
   FOOTER
   =========================================================== */
footer, .site-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer a { color: var(--accent); text-decoration: none; transition: color 0.2s ease; }
.site-footer a:hover { color: var(--accent-2); }

/* ===========================================================
   RESPONSIVE ADJUSTMENTS
   =========================================================== */
@media (max-width: 600px) {
  .site-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .site-nav { flex-wrap: wrap; gap: 12px; }
  .site-footer { flex-direction: column; }
}

/* ===========================================================
   RESULT BOX / VALUES
   =========================================================== */
.result-box {
  text-align: center;
  background: linear-gradient(180deg, rgba(125, 211, 252, .08), rgba(167, 139, 250, .08));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  transition: all 0.3s ease;
}
.result-box.hidden {
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
}
.result-box.fade-in { opacity: 1; transform: scale(1); }
.liters-value { font-size: 1.2rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.collected-value { font-size: 1.2rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.savings-value { font-size: 1.0rem; color: var(--muted); }
.pulse { animation: pulseAnim 0.6s ease; }
@keyframes pulseAnim { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* ===========================================================
   TITLE TOOLTIP / POPUP
   =========================================================== */
.title-row { position: relative; display: flex; align-items: center; gap: 0.5rem; }
.title-row .info-icon { cursor: pointer; }
.title-row .tooltip-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--card);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  width: 300px;
  box-shadow: var(--shadow);
  z-index: 10;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  line-height: 1.4;
}
.title-row .tooltip-popup::after {
  content: '';
  position: absolute;
  top: -6px;
  left: 10px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent var(--card) transparent;
}

/* ===========================================================
   INPUT ROW CENTRATA
   =========================================================== */
.inputs-row {
    display: flex;
    gap: 1rem;
    justify-content: center; /* centra la riga */
    margin-top: 1rem;
    flex-wrap: wrap; /* evita overflow su mobile */
}

.inputs-row .field {
    flex: 0 0 180px; /* larghezza fissa */
    display: flex;
    flex-direction: column;
    align-items: center; /* centra label e input */
}

.inputs-row label {
    text-align: center;
    width: 100%;
}
.inputs-row input,
.inputs-row select {
    text-align: center;
}

/* ===========================================================
   FOOTER
   =========================================================== */
.site-footer {
    display: flex;
    justify-content: space-between; /* desktop: sinistra/destra */
    align-items: center;
    width: 100%;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--muted);
}

@media (max-width: 600px) {
    .site-footer {
        flex-direction: column; /* elementi uno sotto l'altro */
        align-items: center;
        gap: 4px;
    }
}