:root {
  --ink: #2b211c;
  --muted: #7a6a62;
  --paper: #f6efe6;
  --cream: rgba(255, 250, 244, 0.78);
  --rose: #c45c6a;
  --rose-deep: #8f3b48;
  --gold: #c4a35a;
  --gold-soft: #e7d7a3;
  --sage: #3f6f66;
  --line: rgba(43, 33, 28, 0.08);
  --shadow: 0 24px 60px rgba(88, 48, 42, 0.12);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Outfit", sans-serif;
  color: var(--ink);
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background:
    radial-gradient(1200px 600px at 10% -10%, #f8d9c8 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #e7f0e4 0%, transparent 46%),
    var(--paper);
  overflow-x: hidden;
}

h1,
h2,
.brand strong,
.login-badge {
  font-family: "Cormorant Garamond", serif;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(2.4rem, 5vw, 4.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

h2 {
  margin: 0 0 12px;
  font-size: 2rem;
  font-weight: 600;
}

p {
  color: var(--muted);
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

.aurora {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.55;
  animation: float 14s ease-in-out infinite;
}

.orb-one {
  width: 340px;
  height: 340px;
  background: #f3c1b0;
  top: -80px;
  left: -40px;
}

.orb-two {
  width: 280px;
  height: 280px;
  background: #d7c48b;
  right: -60px;
  top: 120px;
  animation-delay: -4s;
}

.orb-three {
  width: 260px;
  height: 260px;
  background: #cfe0d4;
  bottom: -70px;
  left: 30%;
  animation-delay: -8s;
}

.topbar,
.page,
.login-page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 22px 0 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--rose), var(--gold));
  color: white;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.5rem;
  box-shadow: 0 10px 24px rgba(196, 92, 106, 0.28);
}

.brand strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1;
}

.brand small,
.eyebrow,
.muted {
  color: var(--muted);
}

.brand small,
.eyebrow {
  display: block;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.nav {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}

.nav a {
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 500;
  transition: 0.25s ease;
}

.nav a.is-active,
.nav a:hover {
  background: var(--ink);
  color: #fffaf4;
}

.nav a.ghost:hover {
  background: rgba(196, 92, 106, 0.12);
  color: var(--rose-deep);
}

.page {
  padding: 18px 0 64px;
  animation: rise 0.7s ease both;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 18px 0 24px;
}

.calendar-head {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
}

.calendar-head h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
}

.lede {
  margin: 0;
  max-width: 42ch;
}

.glass-card {
  background: var(--cream);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stat-strip article {
  padding: 8px 10px;
}

.stat-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-strip strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card {
  padding: 22px;
  animation: rise 0.8s ease both;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.7rem;
  font-family: "Cormorant Garamond", serif;
}

.stat-card small {
  display: inline-block;
  margin-top: 8px;
  font-weight: 600;
}

.up {
  color: var(--sage);
}

.down {
  color: var(--rose-deep);
}

.month-switch {
  display: flex;
  gap: 8px;
}

.icon-btn,
.btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow);
  font-size: 1.6rem;
}

.icon-btn:hover,
.btn:hover {
  transform: translateY(-2px);
}

.calendar-card {
  padding: 22px;
  overflow: hidden;
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.weekday-row {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.weekday-row span {
  min-width: 0;
  overflow: hidden;
  text-align: center;
}

.day-cell {
  min-width: 0;
  min-height: 92px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  animation: pop 0.5s ease both;
  animation-delay: var(--delay, 0ms);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.day-cell:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 16px 30px rgba(88, 48, 42, 0.12);
}

.day-cell.has-data {
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.9), rgba(231, 215, 163, 0.55));
  border-color: rgba(196, 163, 90, 0.35);
}

.day-cell.is-today {
  box-shadow: inset 0 0 0 2px var(--gold);
}

.day-cell.is-outside {
  opacity: 0.28;
}

.day-number {
  font-weight: 600;
}

.day-amount {
  font-size: 0.78rem;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 22px;
  border-radius: 999px;
  font-weight: 600;
}

.btn-primary {
  color: #fffaf4;
  background: linear-gradient(135deg, var(--rose), var(--rose-deep) 55%, #a56a32);
  box-shadow: 0 12px 24px rgba(143, 59, 72, 0.25);
}

.btn-danger {
  background: rgba(196, 92, 106, 0.12);
  color: var(--rose-deep);
}

.btn-full {
  width: 100%;
}

.login-page {
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: 40px 0;
}

.login-shell {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 40px;
  align-items: center;
}

.login-card,
.form-card,
.side-note,
.chart-card,
.table-card {
  padding: 28px;
}

.login-badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(196, 163, 90, 0.18);
  color: #8a6a24;
  letter-spacing: 0.08em;
}

label {
  display: block;
  margin: 16px 0;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  font: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(196, 163, 90, 0.16);
}

.money-input {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 4px 4px 4px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
}

.money-input span {
  color: var(--gold);
  font-weight: 700;
}

.money-input input {
  margin: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.field-error {
  display: block;
  margin-top: 6px;
  color: var(--rose-deep);
  font-size: 0.88rem;
}

.split {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--sage);
  font-weight: 600;
}

.big-number {
  font-family: "Cormorant Garamond", serif;
  font-size: 2.4rem;
  color: var(--ink);
  margin: 8px 0 0;
}

blockquote {
  margin: 16px 0 0;
  padding: 12px 16px;
  border-left: 3px solid var(--gold);
  background: rgba(255, 255, 255, 0.45);
  border-radius: 0 16px 16px 0;
  color: var(--ink);
}

.report-head {
  margin: 4px 0 10px;
}

.report-head h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.35rem, 4.5vw, 2.2rem);
}

.results {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.result-hero {
  padding: 16px 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.95), rgba(231, 215, 163, 0.45));
  border: 1px solid rgba(196, 163, 90, 0.35);
}

.result-hero span {
  display: block;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.result-hero strong {
  display: block;
  margin-top: 4px;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 600;
  line-height: 1;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.result-metrics article {
  padding: 12px 10px;
}

.result-metrics span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-metrics strong {
  display: block;
  margin-top: 4px;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(1.15rem, 4vw, 1.55rem);
  font-weight: 600;
  line-height: 1.1;
}

.result-metrics small {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 600;
}

.filter-bar {
  display: grid;
  gap: 10px;
  padding: 10px;
  margin: 0 0 14px;
}

.vista-pills {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.pill {
  margin: 0;
  padding: 8px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: 0.2s ease;
  font-size: 0.82rem;
  text-align: center;
  min-width: 0;
}

.pill input {
  display: none;
}

.pill.is-active,
.pill:hover {
  background: var(--ink);
  color: #fffaf4;
}

.filter-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.filter-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.filter-grid input,
.filter-grid select {
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.btn-compact {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.filter-grid[data-vista="annuale"] .filter-month,
.filter-grid[data-vista="annuale"] .filter-week,
.filter-grid[data-vista="annuale"] .filter-from,
.filter-grid[data-vista="annuale"] .filter-to,
.filter-grid[data-vista="mensile"] .filter-week,
.filter-grid[data-vista="mensile"] .filter-from,
.filter-grid[data-vista="mensile"] .filter-to,
.filter-grid[data-vista="settimanale"] .filter-year,
.filter-grid[data-vista="settimanale"] .filter-month,
.filter-grid[data-vista="settimanale"] .filter-from,
.filter-grid[data-vista="settimanale"] .filter-to,
.filter-grid[data-vista="periodo"] .filter-year,
.filter-grid[data-vista="periodo"] .filter-month,
.filter-grid[data-vista="periodo"] .filter-week {
  display: none;
}

.earn-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 420px;
  overflow: auto;
}

.earn-list a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.earn-list small {
  display: block;
  color: var(--muted);
  font-weight: 400;
}

.earn-list .is-muted {
  opacity: 0.45;
}

.toasts {
  position: sticky;
  top: 12px;
  z-index: 5;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.toast {
  padding: 12px 16px;
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow);
  animation: toast-in 0.4s ease both;
}

.toast-success {
  border-left: 4px solid var(--sage);
}

.toast-error {
  border-left: 4px solid var(--rose);
}

.toast-info {
  border-left: 4px solid var(--gold);
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(24px) scale(1.05);
  }
}

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

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .topbar,
  .page,
  .login-page {
    width: min(1120px, calc(100% - 16px));
  }

  .topbar {
    flex-wrap: wrap;
    padding: 12px 0 4px;
    gap: 10px;
  }

  .brand small {
    display: none;
  }

  .nav {
    width: 100%;
    justify-content: space-between;
  }

  .nav a {
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .page {
    padding: 8px 0 32px;
  }

  .login-shell,
  .split {
    grid-template-columns: 1fr;
  }

  .result-hero {
    padding: 14px 12px;
  }

  .chart-card,
  .table-card {
    padding: 16px;
  }

  .vista-pills {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .filter-grid .btn-compact,
  .filter-grid[data-vista="annuale"] .filter-year,
  .filter-grid[data-vista="settimanale"] .filter-week {
    grid-column: 1 / -1;
    width: 100%;
  }

  .filter-grid input,
  .filter-grid select {
    width: 100%;
  }

  .filter-year select,
  .filter-month select,
  .filter-week input,
  .filter-from input,
  .filter-to input {
    width: 100%;
  }

  .hero-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .calendar-head {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    margin: 4px 0 10px;
  }

  .calendar-head h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .calendar-head .icon-btn {
    width: 40px;
    height: 40px;
  }

  .calendar-card {
    padding: 10px;
  }

  .weekday-row,
  .calendar-grid {
    gap: 4px;
  }

  .weekday-row {
    font-size: 0.68rem;
    letter-spacing: 0;
    margin-bottom: 6px;
  }

  .day-cell {
    min-height: 52px;
    padding: 6px 4px;
    border-radius: 12px;
  }

  .day-number {
    font-size: 0.85rem;
  }

  .day-amount {
    font-size: 0.58rem;
  }

  .stat-strip article {
    padding: 6px 7px;
  }

  .stat-strip span {
    font-size: 0.58rem;
  }

  .stat-strip strong {
    font-size: 0.82rem;
  }
}

@media (hover: none) {
  .day-cell:hover,
  .icon-btn:hover,
  .btn:hover {
    transform: none;
    box-shadow: none;
  }
}

body.pwa-open .login-page {
  min-height: calc(100vh - 92px - env(safe-area-inset-bottom));
  box-sizing: border-box;
}

body.pwa-open .page {
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

.pwa-prompts {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  justify-content: center;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}

.pwa-prompts[hidden] {
  display: none;
}

.pwa-banner {
  pointer-events: auto;
  display: flex;
  width: min(28rem, 100%);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.96);
  box-shadow: 0 18px 40px rgba(88, 48, 42, 0.18);
  animation: pwa-slide-up 0.35s ease;
}

.pwa-banner[hidden] {
  display: none;
}

.pwa-banner-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(196, 92, 106, 0.15);
  color: var(--rose-deep);
}

.pwa-banner-copy {
  min-width: 0;
  flex: 1;
}

.pwa-banner-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
}

.pwa-banner-text {
  margin-top: 2px;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.pwa-banner-text[hidden] {
  display: none;
}

.pwa-share {
  display: inline-block;
  vertical-align: -2px;
}

.pwa-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.85rem;
  box-shadow: 0 8px 16px rgba(143, 59, 72, 0.22);
}

.pwa-btn[hidden] {
  display: none;
}

.pwa-close {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.pwa-close:hover {
  background: rgba(196, 92, 106, 0.12);
  color: var(--rose-deep);
}

@keyframes pwa-slide-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
