:root {
  --primary: #ef6f6c;
  --primary-dark: #d4504d;
  --accent: #2bb3a3;
  --bg: #fff8f3;
  --card: #ffffff;
  --text: #2d2a32;
  --muted: #8a8391;
  --line: #f0e6df;
  --ok: #2e9e5b;
  --warn: #e69a1c;
  --bad: #d64545;
  --me: #ffe1dc;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(80, 40, 30, .07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-dark); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.splash { display: grid; place-items: center; height: 100vh; font-size: 64px; }
.small { font-size: .82rem; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; word-wrap: break-word; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 14px; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 10px 8px;
  background: var(--primary); color: #fff; flex-shrink: 0;
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .t1 { font-weight: 700; font-size: 1.08rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t2 { font-size: .78rem; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { font-size: 26px; padding: 0 4px; }
.icon-btn {
  position: relative; background: none; border: 0; color: #fff; font-size: 22px; width: 42px; height: 42px;
  border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.icon-btn.back { font-size: 34px; line-height: 1; }
.badge {
  position: absolute; top: 2px; right: 0; background: #ffd23f; color: #3a2b00; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
.badge.dot { min-width: 10px; width: 10px; height: 10px; padding: 0; top: -2px; right: -6px; background: var(--primary); }
.content { flex: 1; overflow-y: auto; padding: 14px 14px 24px; -webkit-overflow-scrolling: touch; }
.bottomnav {
  display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); flex-shrink: 0;
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 0 6px; color: var(--muted); font-size: .72rem; }
.bottomnav a .ic { font-size: 22px; position: relative; }
.bottomnav a .ic .emo { filter: grayscale(.8); opacity: .75; }
.bottomnav a.active { color: var(--primary-dark); font-weight: 600; }
.bottomnav a.active .ic .emo { filter: none; opacity: 1; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
a.card { display: block; color: inherit; }
.card.highlight { background: #fff4d6; }
.card.alert { background: #ffe9e7; color: #8f2a26; font-weight: 600; }
.card.error { background: #ffe9e7; color: #8f2a26; }
.card.info { background: #e7f6f4; color: #1f6f66; font-size: .9rem; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.sec-head h3 { margin: 0; }
.li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); color: inherit; }
.li:first-child { border-top: 0; padding-top: 2px; }
.li .ttl { font-weight: 600; }
.av {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex-shrink: 0;
  background: #fde7e1;
}
.date-badge {
  width: 48px; border-radius: 12px; background: #fde7e1; text-align: center; padding: 5px 0; flex-shrink: 0; color: var(--primary-dark);
}
.date-badge .d { font-size: 1.25rem; font-weight: 800; line-height: 1; }
.date-badge .m { font-size: .7rem; text-transform: uppercase; font-weight: 700; }
.chip {
  display: inline-block; font-size: .74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #f2ecf7; color: #4a3f55;
  white-space: nowrap;
}
.chip.ok { background: #e2f5e9; color: var(--ok); }
.chip.warn { background: #fff0d6; color: #9a6200; }
.chip.bad { background: #ffe3e3; color: var(--bad); }
.chip.pri { background: var(--primary); color: #fff; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .big { font-size: 46px; }
.hello h2 { margin-bottom: 2px; }
details summary { cursor: pointer; color: var(--primary-dark); font-weight: 600; padding: 4px 0; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px;
  padding: 10px 16px; font-size: .95rem; font-weight: 600; cursor: pointer; background: #f3ebe6; color: var(--text);
  font-family: inherit; text-align: center;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.danger { background: #ffe3e3; color: var(--bad); }
.btn.ghost { background: transparent; color: var(--primary-dark); padding: 6px 8px; }
.btn.small { padding: 6px 11px; font-size: .82rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; }
.btn.on { background: var(--accent); color: #fff; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > .btn { flex: 1; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .lbl { font-size: .85rem; font-weight: 600; color: #5b5361; }
.field .hint { font-size: .78rem; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 11px 12px; border: 1.5px solid #eadfd8; border-radius: 12px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0; }
.check { display: flex; align-items: center; gap: 10px; font-size: .95rem; padding: 4px 0; }
.checks { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; border: 1.5px solid #eadfd8; border-radius: 12px; padding: 6px 10px; background: #fff; }
.seg { display: flex; background: #f3ebe6; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; font: inherit; font-size: .88rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow); }
.fab {
  position: fixed; right: max(18px, calc(50% - 362px)); bottom: calc(78px + var(--safe-b)); width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 30px; border: 0; box-shadow: 0 6px 16px rgba(239,111,108,.45); display: grid; place-items: center; z-index: 5;
}
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 1.5rem; font-weight: 800; letter-spacing: 4px; color: var(--primary-dark); }
.templates { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.templates .btn { white-space: nowrap; flex: none; }

/* ---------- welcome ---------- */
.welcome { min-height: 100vh; padding: calc(30px + var(--safe-t)) 18px 30px; max-width: 460px; margin: 0 auto; }
.hero { text-align: center; margin-bottom: 22px; }
.hero-logo { font-size: 72px; }
.hero h1 { color: var(--primary-dark); font-size: 2rem; }
.hero p { color: var(--muted); margin: 0; }
.tagline { color: var(--accent); font-weight: 700; letter-spacing: .5px; margin: -4px 0 8px; }
.welcome-box { display: flex; flex-direction: column; gap: 16px; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 24px; text-align: center; font-size: .78rem; color: var(--muted); }
.features div span { display: block; font-size: 26px; }

/* ---------- chat ---------- */
.chat-mode .content { background: #f7efe9; padding: 10px 10px 6px; }
.msgs { display: flex; flex-direction: column; gap: 3px; }
.day-sep { align-self: center; background: #fff; color: var(--muted); font-size: .75rem; padding: 3px 12px; border-radius: 999px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.msg { max-width: 82%; padding: 6px 10px 4px; border-radius: 14px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); align-self: flex-start; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); }
.msg.cont { margin-top: -1px; }
.msg .author { font-size: .78rem; font-weight: 700; margin-bottom: 1px; }
.msg .text { white-space: pre-wrap; }
.msg .time { font-size: .68rem; color: var(--muted); text-align: right; margin-top: 1px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + var(--safe-b)); background: #f7efe9; border-top: 1px solid var(--line); flex-shrink: 0; }
.composer textarea { resize: none; max-height: 140px; border-radius: 22px; padding: 10px 14px; }
.composer .send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 20px; flex-shrink: 0; cursor: pointer; }
.chat-banner { background: #fff4d6; border-radius: 12px; padding: 8px 12px; font-size: .82rem; text-align: center; margin: 4px 0 8px; }
.unread-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* ---------- weather ---------- */
.wx-card { border-left: 6px solid var(--ok); }
.wx-card.lvl-attenzione { border-left-color: var(--warn); background: #fffaf0; }
.wx-card.lvl-difficile { border-left-color: var(--bad); background: #fff3f2; }
.wx-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.wx-verdict { font-size: 1.3rem; font-weight: 800; }
.wx-windows { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 6px; }
.wx-win { display: flex; flex-direction: column; gap: 2px; background: rgba(255,255,255,.75); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.wx-ic { font-size: 28px; }
.wx-advice { margin: 4px 0 0; padding-left: 20px; font-size: .92rem; }
.hours { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.hour { flex: none; width: 58px; text-align: center; background: #fff; border-radius: 12px; padding: 8px 2px; font-size: .78rem; box-shadow: var(--shadow); }
.hour.school { outline: 2px solid var(--primary); }
.hour .ic { font-size: 22px; }

/* ---------- calendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-nav b { text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .7rem; color: var(--muted); font-weight: 700; }
.cal-cell {
  aspect-ratio: 1; border: 0; background: #fbf6f2; border-radius: 10px; font: inherit; font-size: .85rem; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--text); padding: 0;
}
.cal-cell.empty { background: transparent; }
.cal-cell.has { background: #ffe1dc; font-weight: 700; cursor: pointer; }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-cell .cake { font-size: .75rem; line-height: 1; }
.cal-detail { margin-top: 10px; font-size: .92rem; }

/* ---------- gifts ---------- */
.progress { height: 10px; background: #f3ebe6; border-radius: 6px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: #fbf6f2; border-radius: 12px; padding: 8px 4px; }
.stats b { display: block; font-size: 1.2rem; }
.idea { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.idea:first-child { border-top: 0; }
.vote { border: 0; background: #fde7e1; border-radius: 12px; padding: 6px 10px; font: inherit; font-weight: 700; cursor: pointer; min-width: 52px; }
.vote.on { background: var(--primary); color: #fff; }
.pay { background: #e7f6f4; border-radius: 12px; padding: 10px 12px; margin-top: 12px; }
.pay-info { margin-top: 4px; font-weight: 600; word-break: break-word; white-space: pre-wrap; }
.pay-edit { display: flex; flex-direction: column; gap: 6px; }
.plist { margin: 4px 0 0; padding-left: 20px; }
.plist li + li { margin-top: 4px; }
.privacy p { margin: 0; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 8px; }
.danger-zone summary { color: var(--bad); }
.filters-box { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; display: flex; flex-direction: column; gap: 12px; }
.filters-box h3 { margin: 0; }
.phrase { background: linear-gradient(135deg, #fff1e8, #ffe7ef); }
.phrase.bimbi { background: linear-gradient(135deg, #e9f7ff, #eefbe9); }
.phrase-tag { font-weight: 700; color: var(--primary-dark); }
.phrase.bimbi .phrase-tag { color: #2b7a8f; }
.phrase-text { font-size: 1.12rem; font-style: italic; margin-top: 6px; line-height: 1.45; }
.composer .attach { width: 42px; height: 46px; border: 0; background: none; font-size: 24px; cursor: pointer; flex-shrink: 0; }
.chat-img { display: block; max-width: 100%; width: 240px; max-height: 320px; object-fit: cover; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; background: #eee; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: calc(100% - 70px); object-fit: contain; border-radius: 8px; }
.lb-bar { display: flex; gap: 10px; margin-top: 12px; }
.diary { border-left: 5px solid var(--accent); }
.diary-day { font-weight: 700; text-transform: capitalize; }
.diary-time { font-size: .85rem; color: var(--muted); margin-top: 1px; }
.diary-img { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; margin-top: 8px; cursor: zoom-in; }
a.card.row { color: inherit; }
.reps-card { background: linear-gradient(135deg, #fff7d9, #fff); }
.prefs .checks { max-height: none; }
.sheet-bg { position: fixed; inset: 0; background: rgba(20,10,20,.45); z-index: 55; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 760px; max-height: 88vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b)); box-shadow: 0 -6px 24px rgba(0,0,0,.2); display: flex; flex-direction: column; gap: 12px; }
.quote { background: #f6efe9; border-left: 4px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.poll { min-width: 230px; display: flex; flex-direction: column; gap: 6px; margin: 2px 0; }
.msg.has-poll { max-width: 92%; }
.poll-q { font-weight: 700; }
.poll-opt { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1.5px solid var(--line);
  background: #fff; border-radius: 10px; padding: 8px 10px; font: inherit; cursor: pointer; overflow: hidden; text-align: left; color: var(--text); }
.poll-opt.on { border-color: var(--accent); font-weight: 700; }
.poll-opt:disabled { cursor: default; }
.poll-bar { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(43,179,163,.16); z-index: 0; transition: width .3s; }
.poll-txt, .poll-n { position: relative; z-index: 1; }
.poll-n { font-weight: 700; color: var(--muted); }
.poll-inputs { display: flex; flex-direction: column; gap: 6px; }
.hidden-msg { color: var(--muted); font-style: italic; }
.report.open { border-left: 5px solid var(--warn); }
.cal-cell { position: relative; }
.cal-cell.has-items { background: #fff4ec; font-weight: 700; cursor: pointer; }
.cal-cell .dots { display: flex; gap: 2px; height: 6px; margin-top: 2px; }
.cal-cell .dots i, .cal-legend i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: .74rem; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 4px; }
.menu-today { font-size: 1.02rem; font-weight: 600; margin-top: 4px; }
.mensa-card { border-left: 5px solid #e69a1c; }
.menu-edit { margin-top: 10px; }
.menu-day { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: 6px; margin-bottom: 4px; font-size: .85rem; }
.menu-day input { padding: 8px 10px; }
.meal-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.secret { background: #2d2a32; color: #fff; border-radius: 12px; padding: 8px 12px; font-size: .85rem; }

/* ---------- board / feed ---------- */
.ann.unread { border-left: 5px solid var(--primary); }
.ann h3 { margin: 8px 0 4px; }
.ann .body { margin: 6px 0 8px; }
.for-date { display: inline-block; background: #fff4d6; color: #8a5a00; font-weight: 700; border-radius: 8px; padding: 3px 9px; font-size: .85rem; }
.feed-item.important { border-left: 5px solid var(--bad); }
.feed-item h3 a { color: var(--text); }

/* ---------- toast ---------- */
#toasts { position: fixed; left: 0; right: 0; top: calc(64px + var(--safe-t)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 50; pointer-events: none; }
.toast { background: #2d2a32; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 92%; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: auto; animation: tin .2s ease-out; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1a20; --card: #2a262e; --text: #f3eef5; --muted: #a59dac; --line: #3a3540; --me: #5a3431; }
  .bottomnav { background: #241f27; }
  input, select, textarea, .checks { background: #241f27; border-color: #3d3743; }
  .btn { background: #3a3540; }
  .seg { background: #2f2a34; } .seg button.on { background: #463f4d; }
  .chat-mode .content, .composer { background: #19161b; }
  .msg { background: #2f2a34; }
  .day-sep, .hour { background: #2f2a34; }
  .card.highlight, .chat-banner { background: #3d3420; }
  .card.alert, .card.error { background: #4a2624; color: #ffc9c4; }
  .card.info, .pay { background: #1e3a37; color: #a9e6dd; }
  .reps-card { background: #3d3420; }
  .quote { background: #2f2a34; } .poll-opt { background: #241f27; } .cal-cell.has-items { background: #4a2f2d; }
  .phrase, .phrase.bimbi { background: linear-gradient(135deg, #3a2a2e, #2a3238); }
  .wx-card.lvl-attenzione { background: #3a3120; } .wx-card.lvl-difficile { background: #3d2322; }
  .wx-win { background: rgba(0,0,0,.2); }
  .cal-cell { background: #2f2a34; color: var(--text); } .cal-cell.has { background: #5a3431; }
  .stats div, .progress { background: #2f2a34; }
  .av, .date-badge, .vote { background: #4a2f2d; }
  .chip { background: #3a3540; color: #e0d8e6; }
  .for-date { background: #3d3420; color: #ffd98a; }
}
