/* ============================================================
   ASSISTENTE BG-AGRO — CSS
   Palette: verde scuro, verde, oro, neutri
   ============================================================ */

/* ---- Variabili ---- */
:root {
  --bg: #f4f7f2;
  --surface: #fff;
  --surface2: #f9fbf8;
  --text: #163022;
  --muted: #64776b;
  --line: #dce7de;
  --green: #1d6a44;
  --green2: #27583f;
  --greenDk: #12291d;
  --greenSoft: #edf6ef;
  --gold: #c6a35a;
  --goldSoft: #f6f0e3;
  --shadow: 0 12px 30px rgba(18,41,29,.08);
  --radius: 22px;
}

/* ---- Reset ---- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(29,106,68,.07), transparent 30%),
    radial-gradient(circle at top right, rgba(198,163,90,.08), transparent 25%),
    var(--bg);
  color: var(--text);
}

.container {
  max-width: 1020px;
  margin: 0 auto;
  padding: 24px 18px 60px;
}

/* ---- Hero ---- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 30px;
  background: linear-gradient(135deg, rgba(18,41,29,.98), rgba(29,106,68,.95));
  color: #fff;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.hero::before {
  content: "";
  position: absolute;
  inset: auto -80px -80px auto;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, rgba(198,163,90,.24), transparent 62%);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 0 57%, rgba(255,255,255,.05) 57% 58%, transparent 58% 100%);
  pointer-events: none;
}
.hero-inner {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.hero-left {
  display: flex;
  gap: 20px;
  align-items: center;
}
.hero-logo {
  display: block;
  max-width: 200px;
  width: 100%;
  height: auto;
  filter: brightness(0) invert(1);
}
.hero h1 {
  font-size: 34px;
  font-weight: 800;
  margin: 0 0 8px;
  line-height: 1.05;
}
.hero p {
  margin: 0;
  color: #d5e8db;
  font-size: 15px;
  line-height: 1.65;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ---- Typography ---- */
h2 { font-size: 22px; font-weight: 800; margin: 0 0 12px; }
h3 { font-size: 17px; font-weight: 700; margin: 0 0 8px; }

/* ---- Form elements ---- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  background: #fff;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(29,106,68,.45);
  box-shadow: 0 0 0 4px rgba(29,106,68,.08);
}
textarea {
  height: auto;
  min-height: 90px;
  padding: 12px 14px;
  resize: vertical;
}

/* ---- Buttons ---- */
.btn-main {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 22px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, var(--green), #25553d);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(29,106,68,.22);
  font-family: inherit;
}
.btn-main:hover { filter: brightness(1.06); }
.btn-main:disabled { opacity: .6; cursor: not-allowed; }

.btn-sec {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid rgba(29,106,68,.14);
  background: var(--greenSoft);
  color: var(--green);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn-sm.danger { border-color: #e6c9c9; color: #8a2e2e; background: #fff8f8; }
.btn-sm.green { border-color: rgba(29,106,68,.2); color: var(--green); background: var(--greenSoft); }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.btn-logout {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-green { background: var(--greenSoft); color: var(--green); }
.badge-gold { background: var(--goldSoft); color: #594622; }
.badge-tech {
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(198,163,90,.25);
  font-size: 11px;
  font-weight: 700;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--greenSoft);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 10px;
}

.chip {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--greenSoft);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.muted { color: var(--muted); font-size: 14px; line-height: 1.55; }
.link { color: var(--green); font-weight: 700; cursor: pointer; }
.hidden { display: none; }

/* ---- Navigation ---- */
.nav-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  height: 42px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.nav-btn.active {
  border: none;
  background: linear-gradient(180deg, var(--green), #25553d);
  color: #fff;
  box-shadow: 0 8px 18px rgba(29,106,68,.22);
}

.sub-nav { display: flex; gap: 6px; }
.sub-btn {
  display: inline-flex;
  align-items: center;
  height: 38px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.sub-btn.active {
  background: var(--greenSoft);
  color: var(--green);
  border-color: rgba(29,106,68,.2);
}

/* ---- Treatment cards ---- */
.treat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.treat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.treat-card.treat-overridden {
  border-color: var(--gold);
  background: linear-gradient(180deg, #fffdf5, #fff);
}
.treat-card h3 { margin: 14px 0 8px; font-size: 22px; }
.treat-card p { margin: 0 0 14px; color: var(--muted); line-height: 1.55; font-size: 14px; }

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.list-row:last-child { border-bottom: none; }
.list-row .k { color: var(--muted); }
.list-row strong { font-weight: 800; }

/* ---- Tech Editor (D2) ---- */
.tech-editor {
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  background: var(--goldSoft);
  border: 1px solid #ead8b1;
}
.tech-editor-label {
  font-size: 12px;
  font-weight: 800;
  color: #594622;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 10px;
}
.tech-editor-row {
  margin-bottom: 8px;
}
.tech-editor-row:last-child { margin-bottom: 0; }
.tech-editor-row label {
  font-size: 12px;
  margin-bottom: 4px;
  color: #594622;
}
.tech-editor-row input {
  height: 36px;
  font-size: 13px;
  font-weight: 700;
  border-color: #ead8b1;
  background: #fff;
}
.tech-editor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* ---- Field edit panel (D1 scelta C) ---- */
.field-edit-panel {
  padding: 14px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: var(--surface2);
  border: 1px solid var(--line);
}
.edit-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr;
  gap: 12px;
  align-items: end;
}
.edit-row input {
  height: 40px;
  font-size: 14px;
  font-weight: 700;
}

/* ---- Product notes ---- */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 18px;
}
.note-card {
  padding: 18px;
  background: linear-gradient(180deg, #fff, #f8fbf8);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.note-img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 14px;
  padding: 10px;
}
.note-card h4 { margin: 0 0 10px; font-size: 19px; }
.note-card p { margin: 0 0 10px; color: var(--muted); line-height: 1.55; font-size: 14px; }
.note-card ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }

/* ---- Field cards ---- */
.fcard {
  padding: 18px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #f8fbf8);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
}
.fcard:hover { border-color: rgba(29,106,68,.3); }
.fcard.selected {
  border-color: var(--green);
  background: linear-gradient(180deg, #f0f8f2, #e8f4eb);
  cursor: default;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
}
.fcard-name { font-size: 20px; font-weight: 800; margin: 0; }
.fcard-meta { color: var(--muted); font-size: 14px; margin-top: 4px; }

.field-detail {
  border: 2px solid var(--green);
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.field-summary {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--goldSoft);
  border: 1px solid #ead8b1;
  color: #594622;
  font-size: 14px;
  line-height: 1.55;
}

/* ---- Farm cards ---- */
.farm-card {
  padding: 22px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #fdfcf8);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.farm-card:hover {
  border-color: rgba(198,163,90,.5);
  transform: translateY(-1px);
}
.farm-card h3 { margin: 0 0 4px; font-size: 20px; }
.farm-card p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---- Order / Quote ---- */
.field-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 14px;
}
.field-meta-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.field-meta-item .k {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.field-meta-item .v {
  font-size: 18px;
  font-weight: 800;
  margin-top: 6px;
}

.buy-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 14px;
}
.buy-card {
  padding: 20px;
  background: linear-gradient(180deg, #fff, #f8fbf8);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.buy-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.buy-card h4 { margin: 0; font-size: 20px; }
.buy-qty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--greenSoft);
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.cta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 22px;
}
.cta-card {
  padding: 22px;
  background: linear-gradient(180deg, #fff, #f8fbf8);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- Note bubble ---- */
.note-bubble {
  padding: 12px;
  border-radius: 14px;
  background: var(--surface2);
  border: 1px solid var(--line);
  margin-bottom: 8px;
}
.note-bubble .note-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---- Infusion ---- */
.inf-result {
  padding: 22px;
  background: linear-gradient(180deg, #173726, #1f5138);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.inf-result h3 { margin: 0 0 12px; font-size: 24px; }
.inf-result .mini { color: #d5e8db; font-size: 14px; line-height: 1.6; }

.inf-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}
.inf-time-card {
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
}
.inf-time-card .k {
  font-size: 12px;
  color: #d5e8db;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.inf-time-card .v {
  font-size: 32px;
  font-weight: 800;
  margin-top: 8px;
}

.inf-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  margin-top: 16px;
}
.inf-badge.ok { background: #edf6ef; color: #1d6a44; }
.inf-badge.warning { background: #fdf0e8; color: #b45a1b; }

.timeline { margin-top: 18px; }
.timeline-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  overflow: hidden;
}
.timeline-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #c6a35a, #6bbf6f);
}
.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: #d5e8db;
}

.slider-field { display: flex; flex-direction: column; gap: 6px; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--line);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--green), #25553d);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(29,106,68,.25);
  cursor: pointer;
}
.slider-val {
  min-width: 52px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.slider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.inf-note {
  padding: 14px;
  border-radius: 16px;
  background: var(--goldSoft);
  border: 1px solid #ead8b1;
  color: #594622;
  font-size: 14px;
  line-height: 1.55;
  margin-top: 14px;
}

/* ---- Form layout ---- */
.form-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr .7fr .7fr auto;
  gap: 12px;
  align-items: end;
}

/* ---- Messages ---- */
.err-box {
  background: #fff0f0;
  border: 1px solid #f5c6c6;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  color: #8a2e2e;
  font-size: 13px;
}
.ok-box {
  background: #f0fff0;
  border: 1px solid #c6e6c6;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  color: #2e5a2e;
  font-size: 13px;
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.6;
}

/* ---- Loading overlay ---- */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(244,247,242,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: var(--radius);
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-overlay {
  flex-direction: column;
  gap: 12px;
}
.loading-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 10px 12px;
  text-align: center;
  font-weight: 800;
  background: #f6faf6;
  border-bottom: 1px solid var(--line);
}
th:first-child { text-align: left; }
td {
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
td:first-child { text-align: left; font-weight: 700; }
tr:nth-child(even) { background: #f9fbf8; }

/* ---- Auth ---- */
.auth-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 60px 16px 40px;
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Responsive ---- */
@media (max-width: 1040px) {
  .treat-grid,
  .notes-grid,
  .buy-grid,
  .field-meta,
  .cta-grid,
  .tech-editor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .form-row,
  .slider-grid,
  .inf-times,
  .edit-row,
  .dash-hero + div { grid-template-columns: 1fr !important; }
  .hero h1 { font-size: 24px; }
  .hero-left { flex-direction: column; gap: 12px; }
  .hero-logo { max-width: 160px; }

  /* D4: Nav bar mobile — scroll orizzontale */
  .nav-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 6px 10px;
  }
  .nav-btn { white-space: nowrap; font-size: 13px; padding: 8px 12px; flex-shrink: 0; }

  /* D4: Container compatto */
  .container { padding: 0 8px; }
  .card { padding: 14px; border-radius: 14px; }
  .hero-inner { padding: 14px 10px; gap: 10px; }

  /* D4: Sub-tab campo — scroll orizzontale */
  .sub-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 4px;
  }
  .sub-btn { white-space: nowrap; font-size: 12px; padding: 6px 10px; flex-shrink: 0; }

  /* D4: Bottoni touch-friendly */
  button, .btn-main, .btn-sec, .btn-sm { min-height: 40px; }

  /* D4: Tabelle scroll */
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  /* D4: Hero bar compatta */
  .hero { border-radius: 14px; }
  .hero h1 { font-size: 20px; }
  .hero p { font-size: 12px; }
  .btn-logout { font-size: 12px; padding: 6px 10px; }

  /* D4: Calendar timeline scroll */
  .cal-timeline { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 480px) {
  .hero-left { align-items: center; text-align: center; }
  .hero-logo { max-width: 120px; }
  .hero h1 { font-size: 18px; }
  .nav-btn { font-size: 12px; padding: 6px 10px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }
}
