:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --accent: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, -apple-system, sans-serif; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 84px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top)) 14px 10px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.header-top h1 { font-size: 1.25rem; font-weight: 700; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.tab {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.date-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.nav-arrow {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.current-label {
  font-weight: 600;
  font-size: 0.95rem;
  text-transform: capitalize;
  text-align: center;
  flex: 1;
}

.app-content {
  padding: 12px;
  flex: 1;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

/* Vista Oraria */
.hour-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  border-bottom: 1px solid var(--border);
  min-height: 54px;
}

.hour-label {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 6px 0 0;
  text-align: right;
}

.hour-slot {
  padding: 6px 8px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.hour-slot:hover { background: rgba(255, 255, 255, 0.03); }

/* Card Impegno */
.event-card {
  background: var(--surface);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.event-card.done {
  opacity: 0.55;
  border-left-color: var(--success);
}

.event-card.done .ev-title { text-decoration: line-through; }

.ev-main { flex: 1; }
.ev-title { font-weight: 600; font-size: 0.95rem; }
.ev-meta { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }
.ev-notes { font-size: 0.82rem; color: #cbd5e1; margin-top: 4px; }

.ev-check {
  width: 22px;
  height: 22px;
  accent-color: var(--success);
  cursor: pointer;
  margin-top: 2px;
}

.badge {
  display: inline-block;
  background: var(--surface-2);
  color: #93c5fd;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  margin-left: 6px;
}

.daily-list { display: flex; flex-direction: column; gap: 10px; }
.empty-msg { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 0.92rem; }

/* Vista Settimanale */
.week-day-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}

.week-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.88rem;
  text-transform: capitalize;
  cursor: pointer;
}

.week-day-header.is-today { color: #60a5fa; }
.week-day-events { padding: 8px; display: flex; flex-direction: column; gap: 6px; }

/* Vista Mensile */
.month-weekdays, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.month-weekdays div {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding-bottom: 6px;
  font-weight: 600;
}

.month-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 54px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.month-cell.other-month { opacity: 0.35; }
.month-cell.today { border-color: var(--accent); }
.month-cell.selected { background: var(--primary); border-color: var(--primary); }

.cell-num { font-size: 0.85rem; font-weight: 600; }
.cell-dot {
  font-size: 0.7rem;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

.month-day-list { margin-top: 16px; }
.month-day-list h3 { font-size: 0.95rem; margin-bottom: 10px; text-transform: capitalize; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.9rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  z-index: 20;
}

/* Modale */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.hidden { display: none !important; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  padding: 18px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
}

form label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 0 4px;
}

form input, form textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.95rem;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.quick-mins {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-mins button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.78rem;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  margin-right: auto;
}

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  z-index: 50;
  max-width: 92%;
  text-align: center;
}