/* ============================================================
   FG Note Spese — tema verde/bianco, ottimizzato mobile-first
   Si rimodula automaticamente per smartphone, tablet e desktop
   ============================================================ */

:root {
  --brand:        #1F5C4F;
  --brand-dark:   #16463C;
  --brand-soft:   #E4EEEA;
  --brand-light:  #F0F7F5;

  --bg:           #F7F9F8;
  --surface:      #FFFFFF;
  --border:       #E0E8E5;
  --border-soft:  #EEF3F1;

  --ink:          #1A2E29;
  --ink-soft:     #4A6560;
  --ink-faint:    #8AAAA3;

  --ok:           #2F7D4F;
  --ok-bg:        #E8F3EC;
  --warn:         #C98A2C;
  --warn-bg:      #FBF1E1;
  --danger:       #B0432E;
  --danger-bg:    #FBEAE5;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Login ──────────────────────────────────────────────── */
.login-screen {
  flex: 1; display: flex; align-items: center;
  justify-content: center; padding: 24px;
  background: linear-gradient(160deg, var(--brand-dark) 0%, var(--brand) 100%);
}
.login-box {
  background: var(--surface); border-radius: var(--radius);
  padding: 32px 28px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center; margin-bottom: 24px;
}
.login-logo .app-icon {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--brand); display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 28px; margin-bottom: 10px;
}
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--brand-dark); }
.login-logo p  { font-size: 13px; color: var(--ink-faint); margin-top: 2px; }

/* ── Header ─────────────────────────────────────────────── */
.topbar {
  background: var(--brand);
  padding: 0 16px;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar-title {
  font-size: 17px; font-weight: 600; color: #fff;
  display: flex; align-items: center; gap: 8px;
}
.topbar-title .icon { font-size: 20px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-btn {
  background: rgba(255,255,255,0.15); border: none;
  color: #fff; border-radius: 8px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; font-weight: 500;
}
.topbar-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Bottom nav (mobile) ─────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav button {
  flex: 1; background: none; border: none; cursor: pointer;
  padding: 8px 4px 6px;
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  color: var(--ink-faint); font-size: 10px; font-weight: 500;
}
.bottom-nav button .nav-icon { font-size: 22px; line-height: 1; }
.bottom-nav button.active { color: var(--brand); }
.bottom-nav button.active .nav-icon { transform: scale(1.1); }

/* ── Side nav (tablet/desktop) ───────────────────────────── */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  #app { flex-direction: row; }
  .side-nav {
    width: 220px; min-height: 100vh;
    background: var(--brand-dark);
    display: flex; flex-direction: column;
    padding: 20px 0;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .side-nav-logo {
    padding: 0 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 12px;
  }
  .side-nav-logo h2 { color: #fff; font-size: 15px; font-weight: 700; }
  .side-nav-logo p  { color: rgba(255,255,255,0.5); font-size: 11px; margin-top: 2px; }
  .side-nav button {
    width: 100%; background: none; border: none; cursor: pointer;
    padding: 11px 20px; text-align: left;
    display: flex; align-items: center; gap: 10px;
    color: rgba(255,255,255,0.7); font-size: 14px; font-weight: 500;
  }
  .side-nav button:hover { background: rgba(255,255,255,0.08); color: #fff; }
  .side-nav button.active { background: rgba(255,255,255,0.15); color: #fff; }
  .side-nav button .nav-icon { font-size: 18px; }
  .side-nav .nav-bottom {
    margin-top: auto; padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  .topbar { display: none; }
  #main-content { flex: 1; display: flex; flex-direction: column; }
}

/* ── Main content ────────────────────────────────────────── */
#view {
  flex: 1;
  padding: 16px 16px 90px; /* bottom padding per bottom nav */
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 768px) {
  #view { padding: 28px 32px 40px; max-width: 900px; }
}

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.card-title {
  font-size: 13px; font-weight: 600;
  color: var(--ink-faint); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 12px;
}

/* ── Stato badge ─────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-bozza        { background: var(--border); color: var(--ink-soft); }
.badge-inviata      { background: var(--warn-bg); color: var(--warn); }
.badge-approvata    { background: var(--ok-bg); color: var(--ok); }
.badge-rifiutata    { background: var(--danger-bg); color: var(--danger); }
.badge-pagata       { background: #E8F0FE; color: #1967D2; }
.badge-contabilizzata { background: var(--ok-bg); color: var(--ok); }

/* ── Form elements ───────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 15px; font-family: inherit;
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field-hint {
  font-size: 12px; color: var(--ink-faint); margin-top: 4px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 11px 18px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.btn-primary   { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--ink-soft); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 7px 13px; font-size: 13px; }
.btn-full      { width: 100%; }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* ── Lista spese ─────────────────────────────────────────── */
.spesa-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border-soft);
}
.spesa-row:last-child { border-bottom: none; }
.spesa-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--brand-light); display: flex;
  align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.spesa-info { flex: 1; min-width: 0; }
.spesa-info .nome { font-size: 14px; font-weight: 600; color: var(--ink); }
.spesa-info .sub  { font-size: 12px; color: var(--ink-faint); margin-top: 1px; }
.spesa-importo    { font-size: 16px; font-weight: 700; color: var(--ink); }
.spesa-actions    { display: flex; gap: 6px; }

/* ── Tappa km ────────────────────────────────────────────── */
.tappa-row {
  background: var(--brand-light);
  border: 1px solid var(--brand-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 8px;
}
.tappa-row .route {
  font-size: 14px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 6px;
}
.tappa-row .route .arrow { color: var(--brand); }
.tappa-row .sub {
  font-size: 12px; color: var(--ink-soft); margin-top: 4px;
  display: flex; gap: 12px;
}

/* ── Foto upload ─────────────────────────────────────────── */
.foto-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 20px; text-align: center;
  cursor: pointer; background: var(--bg);
  transition: border-color 0.15s;
}
.foto-upload:hover, .foto-upload.dragover {
  border-color: var(--brand); background: var(--brand-light);
}
.foto-upload .icon { font-size: 32px; margin-bottom: 6px; }
.foto-upload p { font-size: 13px; color: var(--ink-faint); }
.foto-preview {
  width: 100%; max-height: 200px; object-fit: cover;
  border-radius: var(--radius-sm); margin-top: 8px;
}

/* ── Summary totali ──────────────────────────────────────── */
.totali-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.totale-box {
  background: var(--brand-light);
  border: 1px solid var(--brand-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.totale-box .label { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; }
.totale-box .value { font-size: 20px; font-weight: 700; color: var(--brand-dark); margin-top: 4px; }

/* ── Trasferta header ────────────────────────────────────── */
.trasferta-header {
  background: var(--brand);
  color: #fff; border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.trasferta-header .nome { font-size: 14px; font-weight: 600; }
.trasferta-header .sub  { font-size: 11px; opacity: 0.75; margin-top: 2px; }

/* ── Mese selector ───────────────────────────────────────── */
.mese-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.mese-nav .mese-label {
  font-size: 18px; font-weight: 700; color: var(--ink);
}
.mese-nav button {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
  font-size: 18px; color: var(--ink-soft);
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--ink-faint);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Toast notification ──────────────────────────────────── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  z-index: 9999; opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.toast.show { opacity: 1; }
@media (min-width: 768px) {
  .toast { bottom: 24px; }
}

/* ── Overlay modale ──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 200; display: flex; align-items: flex-end;
}
@media (min-width: 768px) {
  .modal-overlay { align-items: center; justify-content: center; }
}
.modal-box {
  background: var(--surface); width: 100%;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 90vh; overflow-y: auto;
  padding: 20px 20px 32px;
}
@media (min-width: 768px) {
  .modal-box {
    max-width: 520px; border-radius: var(--radius);
    max-height: 80vh;
  }
}
.modal-handle {
  width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 0 auto 16px;
}
@media (min-width: 768px) { .modal-handle { display: none; } }
.modal-title {
  font-size: 17px; font-weight: 700; margin-bottom: 16px;
}

/* ── Sezione km calcolo ──────────────────────────────────── */
.km-result {
  background: var(--brand-light); border: 1.5px solid var(--brand-soft);
  border-radius: var(--radius-sm); padding: 12px;
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px;
}
.km-result .km-value { font-size: 22px; font-weight: 700; color: var(--brand-dark); }
.km-result .km-label { font-size: 12px; color: var(--ink-faint); }

/* ── Categorie griglia ───────────────────────────────────── */
.categorie-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 14px;
}
@media (min-width: 480px) {
  .categorie-grid { grid-template-columns: repeat(4, 1fr); }
}
.categoria-btn {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 6px;
  cursor: pointer; text-align: center; transition: all 0.15s;
}
.categoria-btn .icon { font-size: 24px; display: block; margin-bottom: 4px; }
.categoria-btn .label { font-size: 11px; color: var(--ink-soft); font-weight: 500; }
.categoria-btn.selected {
  border-color: var(--brand); background: var(--brand-light);
}
.categoria-btn.selected .label { color: var(--brand-dark); }

/* ── Responsive layout tablet/desktop ───────────────────── */
@media (min-width: 768px) {
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
}

/* ── Loading spinner ─────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  background: var(--danger-bg); color: var(--danger);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 13px; margin-bottom: 12px;
}
