/* ═══════════════════════════════════════════════════════════════
   AGROS — style.css
   Font: Syne (display) + DM Mono (body/mono)
   Theme: dark industrial/naturale
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Syne:wght@700;800&display=swap');

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variabili ──────────────────────────────────────────────── */
:root {
  --bg:        #0e110d;
  --surface:   #161a14;
  --surface2:  #1c211a;
  --border:    #2a3026;
  --green:     #7db87a;
  --green-dim: #4a7047;
  --green-hi:  #8ecc8b;
  --amber:     #c9a84c;
  --red:       #e07a5f;
  --text:      #d4dbd0;
  --muted:     #6b7a66;
  --font-head: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

/* ── Base ───────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%; /* evita zoom automatico su iOS */
}

/* ── Layout page shell ──────────────────────────────────────── */
.page {
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height — corregge barra browser mobile */
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* ════════════════════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════════════════════ */
header.agros-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
}

.topbar .logo       { height: 30px; width: auto; flex-shrink: 0; }
.topbar .site-title {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--green);
  flex: 1;
  user-select: none;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.userbox .username {
  font-size: 0.75rem;
  color: var(--green);
  letter-spacing: 0.05em;
}

.userbox .logout {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  border-radius: 2px;
  transition: border-color 0.2s, color 0.2s;
  /* area tap minima 44px su mobile */
  min-height: 32px;
  display: flex;
  align-items: center;
}
.userbox .logout:hover { border-color: var(--green-dim); color: var(--green); }

/* ── Nav ────────────────────────────────────────────────────── */
nav.mainnav {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 0 1.25rem;
}

nav.mainnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.6rem 0;
  margin-right: 1.75rem;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  /* area tap generosa su mobile */
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
nav.mainnav a:hover,
nav.mainnav a.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

/* ════════════════════════════════════════════════════════════
   FOOTER
   ════════════════════════════════════════════════════════════ */
footer {
  padding: 0.6rem 1.25rem;
  font-size: 0.68rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ════════════════════════════════════════════════════════════
   TOOLBAR
   ════════════════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.toolbar form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  width: 100%;
}

.toolbar-label {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Inputs comuni ──────────────────────────────────────────── */
select,
input[type="date"],
input[type="text"],
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem; /* leggermente più grande su mobile */
  padding: 0.45rem 0.7rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 38px; /* area tap mobile */
}
select:focus,
input[type="date"]:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--green-dim);
  box-shadow: 0 0 0 3px rgba(125,184,122,0.08);
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
  cursor: pointer;
}

/* ── Bottoni ────────────────────────────────────────────────── */
button,
.btn {
  background: var(--green);
  color: var(--bg);
  border: none;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  min-height: 38px; /* area tap mobile */
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}
button:hover   { background: var(--green-hi); }
button:active  { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ════════════════════════════════════════════════════════════
   PAGE: LOGIN
   ════════════════════════════════════════════════════════════ */
body.page-login {
  display: flex;
  flex-direction: column;
}

body.page-login::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}

body.page-login::after {
  content: '';
  position: fixed;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(125,184,122,0.07) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
}

body.page-login .page {
  position: relative;
  z-index: 1;
}

.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2rem 1.75rem;
  animation: fadeUp 0.45s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-label {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 0.35rem;
}

.card-title {
  font-family: var(--font-head);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 1.6rem;
}
.card-title span { color: var(--green); }

.card-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 1.6rem;
}

.login-error {
  background: #2a1a14;
  border: 1px solid var(--red);
  border-left: 3px solid var(--red);
  color: var(--red);
  font-size: 0.8rem;
  padding: 0.7rem 0.9rem;
  border-radius: 2px;
  margin-bottom: 1.2rem;
  animation: shake 0.3s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}

.form-group { margin-bottom: 1.1rem; }

.form-group label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.form-group input { width: 100%; font-size: 1rem; } /* font-size 1rem evita zoom su iOS */

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.85rem;
  font-size: 0.85rem;
  min-height: 44px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}

/* ════════════════════════════════════════════════════════════
   PAGE: MAP
   ════════════════════════════════════════════════════════════ */
body.page-map .page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.page-map main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* #map e .map-panel-layout gestiti inline nell'EJS */

/* Popup Leaflet — override tema scuro */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
  color: var(--text) !important;
  font-family: var(--font-mono) !important;
  font-size: 0.82rem !important; /* leggermente più grande su mobile */
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 1rem 1.2rem !important;
  line-height: 2 !important;
  min-width: 240px;
}
.leaflet-popup-tip          { background: var(--surface) !important; }
.leaflet-popup-close-button {
  color: var(--muted) !important;
  padding: 8px 10px !important; /* area tap più grande */
  font-size: 1.1rem !important;
}

.popup-id {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--green);
  display: block;
  margin-bottom: 0.15rem;
}
.popup-ts {
  font-size: 0.72rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.7rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}
.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.1rem 0;
}
.popup-row .lbl  { color: var(--muted); white-space: nowrap; }
.popup-row .val  { color: var(--text); text-align: right; }
.popup-row .val.ok    { color: var(--green); }
.popup-row .val.warn  { color: var(--amber); }
.popup-row .val.error { color: var(--red); }

/* ════════════════════════════════════════════════════════════
   PAGE: CHART
   ════════════════════════════════════════════════════════════ */
body.page-chart main {
  padding: 1rem;
  padding-bottom: 2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* scroll fluido iOS */
}

.chart-error {
  font-size: 0.78rem;
  color: var(--red);
  margin-bottom: 0.5rem;
}

.charts-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem 1rem;
  /* Previene overflow del canvas su mobile */
  min-width: 0;
  overflow: hidden;
}

.chart-card canvas {
  width: 100% !important;
  max-width: 100%;
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — mobile first
   ════════════════════════════════════════════════════════════ */

/* ── Smartphone (< 480px) ── */
@media (max-width: 700px) {
  body.page-map .page {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  body.page-map main {
    overflow: visible;
    flex: none;
  }
}

@media (max-width: 480px) {
  html, body { font-size: 15px; } /* base leggermente più grande */

  .topbar { padding: 0.6rem 1rem; }
  .topbar .logo { height: 26px; }
  .topbar .site-title { font-size: 1rem; letter-spacing: 0.15em; }
  .userbox .username { display: none; } /* nasconde nome, resta solo logout */

  nav.mainnav { padding: 0 1rem; }
  nav.mainnav a { font-size: 0.75rem; margin-right: 1.25rem; }

  .toolbar { padding: 0.5rem 1rem; }

  /* Toolbar grafici: stack verticale su schermi stretti */
  .toolbar form {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar form select,
  .toolbar form input[type="date"],
  .toolbar form button { width: 100%; }
  .toolbar-label { margin-top: 0.3rem; }

  /* Login card full-width */
  .login-card { padding: 1.5rem 1rem; }
  .card-title { font-size: 1.5rem; }

  /* Popup più largo su mobile */
  .leaflet-popup-content { min-width: 200px; }
  .leaflet-popup-content-wrapper { font-size: 0.9rem !important; }

  /* Grafici: riduci padding */
  body.page-chart main { padding: 0.75rem; }
  .chart-card { padding: 0.75rem; }
}

/* ── Tablet (481px – 768px) ── */
@media (min-width: 481px) and (max-width: 768px) {
  .toolbar form {
    flex-wrap: wrap;
  }

  /* Toolbar grafici: date su riga separata */
  .toolbar form select { flex: 1 1 auto; }
  .toolbar form input[type="date"] { flex: 1 1 120px; }
}