/* =========================================================
   Robin — assistente di vita personale
   Design system mobile-first
   ========================================================= */

:root {
  --brand-1: #ff6b9d;
  --brand-2: #c471ed;
  --brand-3: #7c5cfc;
  --grad: linear-gradient(135deg, #ff6b9d 0%, #c471ed 52%, #7c5cfc 100%);
  --grad-soft: linear-gradient(135deg, rgba(255, 107, 157, .14), rgba(124, 92, 252, .14));

  --mint: #10b7a0;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --sky: #3b9df8;

  --bg: #f6f4fb;
  --bg-2: #efebf8;
  --surface: #ffffff;
  --surface-2: #faf8fe;
  --ink: #1d1930;
  --ink-2: #4a4463;
  --muted: #837da0;
  --line: #e9e4f4;
  --shadow: 0 2px 8px rgba(45, 27, 82, .05), 0 12px 28px -12px rgba(45, 27, 82, .16);
  --shadow-lg: 0 24px 60px -24px rgba(45, 27, 82, .38);

  --r-sm: 12px;
  --r: 18px;
  --r-lg: 26px;
  --tap: 46px;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: 66px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110e1c;
    --bg-2: #171327;
    --surface: #1c1830;
    --surface-2: #231e3a;
    --ink: #f4f1fb;
    --ink-2: #cdc7e2;
    --muted: #9791b4;
    --line: #2c2646;
    --shadow: 0 2px 8px rgba(0, 0, 0, .3), 0 12px 28px -12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 60px -24px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--brand-3); }

.hidden { display: none !important; }

/* ---------------------------------------------------------- utility */

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 700; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 12px; }

.gradient-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ============================================================ AUTH */

#auth {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(28px + var(--safe-t)) 22px calc(28px + var(--safe-b));
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#auth::before,
#auth::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .5;
  pointer-events: none;
}
#auth::before {
  width: 320px; height: 320px;
  top: -110px; right: -90px;
  background: radial-gradient(circle, var(--brand-1), transparent 70%);
}
#auth::after {
  width: 340px; height: 340px;
  bottom: -140px; left: -110px;
  background: radial-gradient(circle, var(--brand-3), transparent 70%);
}

.auth-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.brand-mark {
  width: 70px; height: 70px;
  border-radius: 22px;
  background: var(--grad);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg);
  font-size: 34px;
}

.brand h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -.6px;
  font-weight: 800;
}

.brand p { margin: 0; color: var(--muted); font-size: 14.5px; text-align: center; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-lg);
}

.seg {
  display: flex;
  background: var(--bg-2);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 20px;
}
.seg button {
  flex: 1;
  padding: 10px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  transition: .18s;
}
.seg button.on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------ form fields */

.field { display: flex; flex-direction: column; gap: 6px; }

.field > label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .2px;
}

.input,
select.input,
textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 16px;               /* evita lo zoom automatico su iOS */
  outline: none;
  transition: border-color .16s, box-shadow .16s;
  appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.4; }

select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23837da0' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.input:focus {
  border-color: var(--brand-3);
  box-shadow: 0 0 0 3.5px rgba(124, 92, 252, .16);
}

.input::placeholder { color: var(--muted); opacity: .75; }

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------------------------------------------------------- buttons */

.btn {
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--r-sm);
  font-size: 15.5px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.975); }
.btn[disabled] { opacity: .55; pointer-events: none; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 10px 24px -10px rgba(124, 92, 252, .75);
}

.btn-ghost { background: var(--bg-2); color: var(--ink-2); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-danger { background: rgba(244, 63, 94, .1); color: var(--rose); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 13.5px; border-radius: 10px; }

/* ============================================================= APP */

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

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(14px + var(--safe-t)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.appbar.scrolled { border-bottom-color: var(--line); }

.appbar h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.4px;
}
.appbar .sub { font-size: 13px; color: var(--muted); }

.avatar {
  width: 40px; height: 40px;
  border-radius: 14px;
  background: var(--grad);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  flex: none;
  box-shadow: 0 6px 16px -8px rgba(124, 92, 252, .9);
}

main {
  flex: 1;
  padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 84px);
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-flush { padding: 0; overflow: hidden; }

.hero {
  background: var(--grad);
  color: #fff;
  border: 0;
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 190px; height: 190px;
  right: -60px; top: -80px;
  background: rgba(255, 255, 255, .16);
  border-radius: 50%;
}
.hero > * { position: relative; z-index: 1; }
.hero h3 { margin: 0 0 2px; font-size: 19px; font-weight: 750; }
.hero .amount { font-size: 34px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 2px 10px;
}
.section-title h3 { margin: 0; font-size: 16.5px; font-weight: 750; letter-spacing: -.2px; }
.section-title button { font-size: 13px; font-weight: 600; color: var(--brand-3); }

/* ------------------------------------------------------ stat tiles */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform .12s;
}
.tile:active { transform: scale(.98); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.tile .ico { font-size: 18px; margin-bottom: 4px; }

/* ----------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  margin-bottom: 9px;
  transition: transform .12s, opacity .2s;
}
.item:active { transform: scale(.99); }
.item.is-done { opacity: .5; }
.item.is-done .item-title { text-decoration: line-through; }

.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 15.2px; font-weight: 620; letter-spacing: -.1px; }
.item-meta { font-size: 12.4px; color: var(--muted); display: flex; gap: 7px; flex-wrap: wrap; margin-top: 2px; }
.item-amount { font-size: 15.5px; font-weight: 750; white-space: nowrap; }

.check {
  width: 26px; height: 26px;
  border-radius: 9px;
  border: 2px solid var(--line);
  flex: none;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 14px;
  transition: .16s;
}
.check.on { background: var(--grad); border-color: transparent; color: #fff; }

.ico-badge {
  width: 42px; height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 19px;
  flex: none;
  background: var(--grad-soft);
}

/* ----------------------------------------------------------- chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  background: var(--bg-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.chip-danger { background: rgba(244, 63, 94, .13); color: var(--rose); }
.chip-warn   { background: rgba(245, 158, 11, .15); color: #b26a00; }
.chip-ok     { background: rgba(16, 183, 160, .14); color: #0a8574; }
.chip-info   { background: rgba(59, 157, 248, .14); color: #1c7ad4; }
.chip-neutral { background: var(--bg-2); color: var(--muted); }

@media (prefers-color-scheme: dark) {
  .chip-warn { color: #f0b23c; }
  .chip-ok   { color: #34d3bb; }
  .chip-info { color: #6ab6fb; }
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.filters::-webkit-scrollbar { display: none; }

.filters button {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 620;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  flex: none;
  transition: .16s;
}
.filters button.on {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px -10px rgba(124, 92, 252, .8);
}

/* ---------------------------------------------------------- charts */

.bar-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.bar-track {
  height: 9px;
  border-radius: 99px;
  background: var(--bg-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--grad);
  transition: width .5s cubic-bezier(.3, 1, .4, 1);
}
.bar-fill.over { background: linear-gradient(135deg, #fb7185, #e11d48); }

.spark {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  height: 108px;
  padding-top: 8px;
}
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.spark-bar {
  width: 100%;
  border-radius: 8px 8px 4px 4px;
  background: var(--grad-soft);
  min-height: 4px;
  transition: height .5s cubic-bezier(.3, 1, .4, 1);
}
.spark-col.now .spark-bar { background: var(--grad); }
.spark-lbl { font-size: 10.5px; color: var(--muted); font-weight: 600; }

.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 116px; height: 116px; flex: none; transform: rotate(-90deg); }
.donut-hole { fill: var(--surface); }

.legend { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ------------------------------------------------------- empty state */

.empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
}
.empty .e-ico { font-size: 42px; margin-bottom: 10px; }
.empty h4 { margin: 0 0 4px; color: var(--ink); font-size: 16px; font-weight: 700; }
.empty p { margin: 0 0 16px; font-size: 13.8px; }

/* ------------------------------------------------------------- FAB */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px;
  border-radius: 20px;
  background: var(--grad);
  color: #fff;
  font-size: 27px;
  display: grid;
  place-items: center;
  box-shadow: 0 14px 30px -10px rgba(124, 92, 252, .85);
  z-index: 40;
  transition: transform .16s;
}
.fab:active { transform: scale(.92) rotate(90deg); }

/* ------------------------------------------------------- bottom nav */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 45;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}

.nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 620;
  position: relative;
  transition: color .16s;
}
.nav button .n-ico { font-size: 21px; line-height: 1; transition: transform .18s; }
.nav button.on { color: var(--brand-3); }
.nav button.on .n-ico { transform: translateY(-2px) scale(1.1); }

.nav .badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--rose);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ----------------------------------------------------- bottom sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 12, 40, .5);
  backdrop-filter: blur(3px);
  z-index: 60;
  opacity: 0;
  transition: opacity .22s;
}
.sheet-backdrop.on { opacity: 1; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 61;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b));
  max-height: 92dvh;
  overflow-y: auto;
  transform: translateY(101%);
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
  box-shadow: 0 -18px 50px -18px rgba(20, 12, 40, .5);
  max-width: 560px;
  margin: 0 auto;
}
.sheet.on { transform: translateY(0); }

.sheet-grip {
  width: 40px; height: 4.5px;
  border-radius: 99px;
  background: var(--line);
  margin: 4px auto 14px;
}

.sheet h3 { margin: 0 0 16px; font-size: 19px; font-weight: 780; letter-spacing: -.3px; }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  position: sticky;
  bottom: 0;
  padding-top: 6px;
  background: linear-gradient(to top, var(--surface) 68%, transparent);
}
.sheet-actions .btn { flex: 1; }

/* choice grid usato per categorie / tipo */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button {
  padding: 9px 13px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  transition: .15s;
}
.choices button.on {
  border-color: transparent;
  background: var(--grad);
  color: #fff;
}

/* ----------------------------------------------------- guida iniziale */

.tour {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(18px + var(--safe-t)) 22px calc(22px + var(--safe-b));
  overflow: hidden;
  opacity: 0;
  transition: opacity .28s;
}
.tour.on { opacity: 1; }

.tour::before,
.tour::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .45;
  pointer-events: none;
}
.tour::before {
  width: 300px; height: 300px; top: -120px; right: -100px;
  background: radial-gradient(circle, var(--brand-1), transparent 70%);
}
.tour::after {
  width: 320px; height: 320px; bottom: -150px; left: -120px;
  background: radial-gradient(circle, var(--brand-3), transparent 70%);
}

.tour-top { position: relative; z-index: 1; display: flex; justify-content: flex-end; min-height: 34px; }
.tour-skip { font-size: 14px; font-weight: 600; color: var(--muted); padding: 6px 4px; }

.tour-stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow-y: auto;
  padding: 8px 0;
}

.tour-slide { animation: tourIn .34s cubic-bezier(.3, 1, .4, 1); width: 100%; max-width: 420px; }
@keyframes tourIn { from { opacity: 0; transform: translateX(22px); } to { opacity: 1; transform: none; } }

.tour-ico {
  width: 92px; height: 92px;
  border-radius: 30px;
  background: var(--grad);
  display: grid;
  place-items: center;
  font-size: 44px;
  margin: 0 auto 22px;
  box-shadow: var(--shadow-lg);
}

.tour-slide h2 {
  margin: 0 0 10px;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.tour-slide > p {
  margin: 0 auto 20px;
  color: var(--ink-2);
  font-size: 15.5px;
  line-height: 1.5;
  max-width: 340px;
}

.tour-ex {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}
.tour-ex span {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  box-shadow: var(--shadow);
}

.tour-tip {
  display: flex;
  gap: 10px;
  text-align: left;
  background: var(--grad-soft);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 13px 15px;
  font-size: 13.8px;
  line-height: 1.45;
  color: var(--ink-2);
  max-width: 380px;
  margin: 0 auto;
}
.tour-tip b { color: var(--ink); }

.tour-bottom { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 16px; }

.tour-dots { display: flex; gap: 7px; justify-content: center; }
.tour-dots i {
  width: 7px; height: 7px;
  border-radius: 99px;
  background: var(--line);
  transition: .24s;
}
.tour-dots i.on { width: 22px; background: var(--grad); }

.tour-nav { display: flex; gap: 10px; }
.tour-nav .btn { flex: 1; }

/* ----------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 84px);
  transform: translate(-50%, 20px);
  z-index: 80;
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  max-width: 88vw;
  text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--rose); color: #fff; }

/* --------------------------------------------------------- spinner */

.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.dark { border-color: var(--line); border-top-color: var(--brand-3); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: grid; place-items: center; padding: 60px 0; }

/* ------------------------------------------------------- desktop */

@media (min-width: 720px) {
  main { padding-bottom: 120px; }
  .nav { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0; }
  .fab { right: calc(50% - 280px + 18px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
