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

:root {
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --success:   #16a34a;
  --bg:        #f1f5f9;
  --sidebar-w: 240px;
  --header-h:  60px;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: #1e293b;
  min-height: 100vh;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-split {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-split-left {
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.login-split-right {
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.login-split-right img {
  max-width: 100%;
  height: 60vh;
  width: 100%;
  object-fit: cover;
  border-radius: 16px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px 40px;
  width: 100%;
  max-width: 400px;
  height: 60vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-card-top {
  text-align: center;
  margin-top: 2.5rem;
}

.login-card-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.login-logo img { margin-bottom: 0; }

.login-logo h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.login-logo p {
  font-size: 13px;
  color: #64748b;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #d1d5db;
  border-radius: var(--radius);
  font-size: 15px;
  transition: border-color .2s;
  outline: none;
}

.form-control:focus { border-color: var(--primary); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { background: var(--danger-h); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover  { background: #15803d; }
.btn-outline  { background: transparent; border: 1.5px solid #d1d5db; color: #374151; }
.btn-outline:hover  { background: #f3f4f6; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Alert ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 20px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 24px;
  border-bottom: 1px solid #334155;
}

.sidebar-brand h2 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.sidebar-brand p {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 16px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: #334155;
  color: #e2e8f0;
}

.nav-item.active {
  background: #1e40af20;
  color: #60a5fa;
  border-left-color: #3b82f6;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid #334155;
}

.sidebar-user {
  font-size: 13px;
  color: #94a3b8;
  margin-bottom: 10px;
}

.sidebar-user span { color: #e2e8f0; font-weight: 600; }

/* Main */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 28px;
  box-shadow: var(--shadow);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
}

.page-content { padding: 28px; flex: 1; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid #e2e8f0;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.card-body { padding: 0; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr { background: #f8fafc; }

th {
  text-align: left;
  padding: 12px 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
}

td {
  padding: 14px 20px;
  font-size: 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #374151;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.actions { display: flex; gap: 8px; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
  transform: translateY(12px);
  transition: transform .2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: 22px; line-height: 1;
}
.modal-close:hover { color: #374151; }

.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px;
}

.modal-lg { max-width: 700px; }

#processaMap {
  height: 350px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 4px;
}

#processaMapPlaceholder {
  height: 350px;
  border-radius: 8px;
  background: #f1f5f9;
  border: 2px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  color: #94a3b8;
  font-size: 14px;
  text-align: center;
}

#osmInfo {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 12px;
  padding: 6px 10px;
  background: #f8fafc;
  border-radius: 6px;
}

/* ── Dashboard cards ──────────────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.dash-card {
  background: #fff;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  border: 1px solid #e2e8f0;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform .15s, box-shadow .15s;
}

.dash-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.dash-card-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}

.dash-card-icon svg { width: 26px; height: 26px; }

.dash-card h3 { font-size: 16px; font-weight: 700; }
.dash-card p  { font-size: 13px; color: #64748b; }

.icon-blue   { background: #dbeafe; color: #2563eb; }
.icon-green  { background: #dcfce7; color: #16a34a; }
.icon-purple { background: #ede9fe; color: #7c3aed; }
.icon-orange { background: #ffedd5; color: #ea580c; }

/* ── Placeholder ──────────────────────────────────────────────────────────── */
.placeholder-box {
  text-align: center;
  padding: 80px 20px;
  color: #94a3b8;
}
.placeholder-box svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: .4; }
.placeholder-box h2 { font-size: 20px; color: #64748b; margin-bottom: 8px; }
.placeholder-box p  { font-size: 14px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1;
}

/* ── Comuni ───────────────────────────────────────────────────────────────── */
.comuni-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.comune-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}

.comune-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,.11);
}

.comune-card-top {
  display: flex;
  align-items: center;
  gap: 16px;
}

.comune-card-icon {
  width: 56px; height: 56px;
  background: #dbeafe;
  color: #2563eb;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.comune-card-icon svg { width: 28px; height: 28px; }

.comune-card-top h3 {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.3;
}

.comune-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.comune-card-meta { display: flex; flex-wrap: wrap; gap: 5px; }

.comune-badge {
  font-size: 12px;
  font-weight: 500;
  background: #f1f5f9;
  color: #64748b;
  padding: 5px 12px;
  border-radius: 20px;
}

.comune-entra {
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}

/* ── Collapsible card ─────────────────────────────────────────────────────── */
.collapsible-header { user-select: none; }
.collapsible-header:hover { background: #f8fafc; }

.collapse-icon {
  font-size: 14px;
  color: #94a3b8;
  transition: color .15s, transform .2s;
}

.collapsible-header:hover .collapse-icon { color: #64748b; }

.collapsible-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  max-height: 2000px;
  transition: max-height .3s ease, opacity .2s ease;
  opacity: 1;
}

.collapsible-body .pagination-bar {
  margin-top: auto;
}

.collapsible-body.collapsed {
  max-height: 0;
  opacity: 0;
}

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid #f1f5f9;
}

.pagination-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-size-label {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
}

.page-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius);
  background: #fff;
  color: #374151;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s, border-color .15s;
}

.page-btn:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.page-btn:disabled {
  opacity: .35;
  cursor: default;
}

.page-info {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
}

.page-size-select {
  padding: 5px 8px;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius);
  font-size: 13px;
  color: #374151;
  background: #fff;
  cursor: pointer;
  outline: none;
}

.page-size-select:focus { border-color: var(--primary); }

/* ── Waypoint pausa badge ─────────────────────────────────────────────────── */
.wp-pausa-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  background: #16a34a;
  color: #fff;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: .3px;
}

/* ── Waypoints table selection ────────────────────────────────────────────── */
#waypointsBody tr { transition: background .15s; }
#waypointsBody tr:hover { background: #f8fafc; }
#waypointsBody tr.wp-row-pausa { background: #dcfce7; }
#waypointsBody tr.wp-row-pausa:hover { background: #bbf7d0; }
#waypointsBody tr.wp-selected { background: #dbeafe !important; outline: 2px solid #3b82f6; outline-offset: -2px; }

/* ── Percorsi row clickable ───────────────────────────────────────────────── */
#percorsiBody tr[onclick]:hover { background: #f0fdf4; }
.btn-delete-percorso {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0.4;
  transition: opacity .15s, background .15s;
}
.btn-delete-percorso:hover { opacity: 1; background: #fee2e2; }

/* ── Aggiungi Waypoint button (mappa) ────────────────────────────────────── */
.btn-add-wp {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  background: #fff;
  border: 2px solid #2563eb;
  color: #2563eb;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  transition: background .15s, color .15s, border-color .15s;
  display: none;
}
.btn-add-wp:hover { background: #2563eb; color: #fff; }
.btn-add-wp.active { background: #ef4444; border-color: #ef4444; color: #fff; }
.btn-add-wp.active:hover { background: #b91c1c; border-color: #b91c1c; }
#comuneMap.add-mode,
#comuneMap.add-mode .leaflet-interactive,
#comuneMap.add-mode .leaflet-container { cursor: crosshair !important; }

/* ── Forecast summary ────────────────────────────────────────────────────── */
.forecast-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
}
.forecast-summary strong { color: #0f172a; }
.fc-sep { color: #cbd5e1; }

/* ── Database tabs ────────────────────────────────────────────────────────── */
.db-tabs { display: flex; gap: 6px; }

.db-tab {
  padding: 6px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  transition: background .15s, color .15s, border-color .15s;
}

.db-tab:hover { background: #f1f5f9; color: #0f172a; }

.db-tab.active {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #1e293b;
}

/* ── Password rules ───────────────────────────────────────────────────────── */
.pwd-rule {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  transition: color .2s;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 999;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: slideIn .25s ease;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@keyframes slideIn {
  from { transform: translateX(60px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
