/* Dove siamo? — ente-inspired: crema + menta + pastelli, tondo e ciccio.
   Person colors (--martina, --martina-deep, …) are injected at boot by app.js
   from /api/people — the registry in server.py is the single source. */
:root {
  --bg: #FAF8F2;
  --ink: #1F3327;
  --ink-soft: #65736C;
  --mint: #35C08E;
  --mint-deep: #23996E;
  --mint-soft: #DCF3E9;
  --card: #FFFFFF;
  --line: #ECE7DB;
  --danger: #D96C6C;
  --line-faint: #F1EDE3;
  --r-lg: 20px; --r-md: 12px; --r-sm: 8px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --lane-h: 25px; --dayrow-h: 32px;
  --font: ui-rounded, -apple-system, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* person color plumbing: one motif, one rule pair per person */
.p-martina { --c: var(--martina); --cd: var(--martina-deep); }
.p-armando { --c: var(--armando); --cd: var(--armando-deep); }
.p-mattia  { --c: var(--mattia);  --cd: var(--mattia-deep); }
.p-michele { --c: var(--michele); --cd: var(--michele-deep); }

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  border-bottom: 1px solid var(--line);
}
.header-row { display: flex; align-items: center; gap: var(--sp-2); max-width: 1440px; margin: 0 auto; }
.header-row h1 { margin: 0; font-size: 23px; line-height: 1.15; font-weight: 800; flex: 1; }
#now {
  display: flex; gap: var(--sp-2); overflow-x: auto;
  max-width: 1440px; margin: var(--sp-3) auto 0;
  padding-bottom: var(--sp-1);
  scrollbar-width: none;
}
#now::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  background: var(--c);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px; font-weight: 700;
  white-space: nowrap;
  transition: opacity .15s, filter .15s;
  cursor: pointer;
}
.chip:focus-visible { outline: 2px solid var(--mint-deep); outline-offset: 2px; }
.chip.off { opacity: .38; filter: saturate(.25); }
.chip.off .place { text-decoration: line-through; }
.chip .place { font-weight: 600; opacity: .8; }
.chip-emoji {
  border: 0; background: none; padding: 0 2px 0 0;
  font-family: inherit; font-size: 15px;
  cursor: pointer;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid button {
  border: 0; background: none; cursor: pointer;
  font-size: 24px; line-height: 1; padding: 7px 0;
  border-radius: var(--r-sm);
}
.emoji-grid button:hover { background: var(--mint-soft); }
/* ---------- buttons ---------- */
.btn {
  font-family: var(--font);
  font-size: 15px; font-weight: 800;
  border: 0; border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--ink);
  background: var(--mint-soft);
}
.btn-primary { background: var(--mint); color: #fff; }
.btn-primary:active { background: var(--mint-deep); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-danger { background: #FBE3E3; color: var(--danger); }
.btn-mini { font-size: 13px; padding: 6px 14px; background: var(--mint-soft); color: var(--mint-deep); }
.view-toggle { min-width: 120px; }

/* ---------- calendar ---------- */
#cal { max-width: 1440px; margin: 0 auto; padding: var(--sp-5) var(--sp-3) 96px; }
.empty-banner {
  background: var(--mint-soft);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
  font-weight: 700; text-align: center;
}
.month {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-3);
  margin-bottom: var(--sp-4);
  box-shadow: 0 1px 4px rgba(31, 51, 39, .06);
}
.month h2 { margin: 0 0 var(--sp-3); font-size: 19px; font-weight: 800; }
.dow-row {
  display: grid; grid-template-columns: 112px repeat(7, 1fr);
  font-size: 12px; font-weight: 800; color: var(--ink-soft);
  text-align: center; text-transform: lowercase;
  margin-bottom: var(--sp-1);
}
.week {
  display: grid;
  grid-template-columns: 112px repeat(7, 1fr);
  /* one fixed lane per person, display order — same person, same row, every
     week; same-person overlaps spill into auto rows below */
  grid-template-rows: var(--dayrow-h);
  grid-auto-rows: var(--lane-h);
  row-gap: 3px;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line-faint);
  opacity: .72;
  transition: opacity .15s, background-color .15s, box-shadow .15s;
}
.week:hover, .week:focus-within { opacity: 1; }
.week.has-today {
  opacity: 1;
  background-color: rgba(255, 255, 255, .92);
  border-radius: var(--r-sm);
}
.week-empty { row-gap: 0; padding-bottom: var(--sp-1); }
.week:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.weekend-col {
  align-self: stretch;
  background: rgba(31, 51, 39, .05);
  pointer-events: none;
}
.day {
  grid-row: 1;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800;
}
.day.out { color: var(--ink-soft); opacity: .45; }
.day .today-dot {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--mint); color: #fff; font-weight: 800;
}
.lane-heading { text-align: left; padding-left: 5px; }
.lane-label {
  align-self: center;
  min-width: 0;
  padding: 0 6px 0 4px;
  color: var(--cd);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lane-emoji { margin-right: 4px; }
/* thin timeline rail + the place floating above it in the person's deep
   color; the label is written once, at the block's start segment */
.bar {
  position: relative; z-index: 1;
  background: none;
  margin-inline: 2px;
  color: var(--cd);
  font-size: 13px; font-weight: 800;
  line-height: 17px;
  padding: 0 2px;
  white-space: nowrap; overflow: visible;
  cursor: pointer;
  min-width: 0;
  transition: opacity .15s;
}
/* the rail: one geometry, shared by real blocks and the faint per-person
   guide tracks (an empty guide = that person is a casa that week) */
.bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 3px;
  height: 7px; border-radius: 4px;
  background: var(--c);
}
/* segment continues from the previous / into the next week: square that edge */
.bar.clip-l::after { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.clip-r::after { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar.clip-l { margin-left: 0; }
.bar.clip-r { margin-right: 0; }

/* thick mode (per-device toggle): filled bands like the pre-rails design,
   labels back on every week; guides become faint full-height lanes */
body.thick { --lane-h: 30px; }
body.thick .bar {
  background: var(--c);
  color: var(--ink);
  border-radius: var(--r-sm);
  font-size: 14px;
  line-height: calc(var(--lane-h) - 2px);
  padding: 0 6px;
  overflow: hidden; text-overflow: ellipsis;
}
body.thick .bar::after { display: none; }
body.thick .bar.clip-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
body.thick .bar.clip-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ---------- fab ---------- */
.fab-dock {
  position: fixed;
  right: var(--sp-4);
  bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  display: flex; align-items: stretch;
  min-height: 52px;
  padding: 3px;
  border: 1px solid rgba(31, 51, 39, .08);
  border-radius: 17px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 4px 12px rgba(35, 153, 110, .4);
  z-index: 20;
}
.fab-dock button {
  width: 48px;
  border: 0;
  border-radius: 13px;
  display: grid; place-items: center;
  padding: 0;
  cursor: pointer;
}
#fab {
  background: var(--mint);
  color: #fff;
}
#fab svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}
#fab:active { background: var(--mint-deep); }
#fabAI {
  margin-right: 3px;
  background: transparent;
  color: var(--ink);
}
#fabAI svg {
  display: block;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linejoin: round;
}
#fabAI:active { background: var(--mint-soft); }
.fab-dock button:focus-visible {
  outline: 2px solid var(--mint-deep);
  outline-offset: 1px;
}

/* ---------- editor sheet ---------- */
#scrim {
  position: fixed; inset: 0;
  background: rgba(31, 51, 39, .35);
  z-index: 30;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 500px; margin: 0 auto;
  background: var(--card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(31, 51, 39, .18);
  z-index: 40;
}
.sheet h2 { margin: 0 0 var(--sp-3); font-size: 18px; font-weight: 800; }
.field-label {
  display: block;
  font-size: 12px; font-weight: 800; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em;
  margin: var(--sp-3) 0 var(--sp-1);
}
#whoChips { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.who-chip {
  border: 0; cursor: pointer;
  background: var(--c); color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--font); font-size: 14px; font-weight: 800;
  opacity: .5;
}
.who-chip.sel { opacity: 1; box-shadow: 0 0 0 2.5px var(--cd); }
.sheet input {
  width: 100%;
  font-family: var(--font); font-size: 16px; font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 10px 12px;
}
.sheet input:focus { outline: 2px solid var(--mint); border-color: transparent; }
.date-row { display: flex; gap: var(--sp-3); }
.date-row > div { flex: 1; }
/* spells the range out in words — the native inputs' DD/MM vs MM/DD order
   follows the DEVICE locale and can't be forced, so this line disambiguates */
.date-words { font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: var(--sp-2) 0 0; min-height: 1em; }
.sheet-buttons { display: flex; gap: var(--sp-2); align-items: center; margin-top: var(--sp-4); }
.sheet-buttons .spacer { flex: 1; }

/* ---------- assistant sheet ---------- */
#aiText {
  width: 100%; min-height: 96px; resize: vertical;
  font-family: var(--font); font-size: 16px; font-weight: 600; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px;
}
#aiText:focus { outline: 2px solid var(--mint); border-color: transparent; }
#aiUnlock { margin-top: var(--sp-2); }
#aiCards { display: flex; flex-direction: column; gap: var(--sp-2); max-height: 52vh; overflow-y: auto; }
.ai-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3); background: var(--bg); }
.ai-card.off { opacity: .5; }
.ai-card-head { display: flex; align-items: center; gap: var(--sp-2); }
.ai-card-head input[type=checkbox] { width: 20px; height: 20px; flex: none; accent-color: var(--mint); }
.ai-who, .ai-place, .ai-dates input {
  font-family: var(--font); color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px 10px;
}
.ai-who { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; }
.ai-place { width: 100%; margin-top: var(--sp-2); font-size: 15px; font-weight: 600; }
.ai-dates { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.ai-dates input { flex: 1; min-width: 0; font-size: 14px; }
.ai-rm { flex: none; border: 0; background: transparent; color: var(--ink-soft); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px; font-weight: 700;
  max-width: 90vw;
  z-index: 50;
}

/* ---------- login ---------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(24px, 6vw, 88px);
  background:
    linear-gradient(90deg, transparent 49.9%, var(--line) 50%, transparent 50.1%),
    var(--bg);
}
.login-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 360px);
  align-items: center;
  gap: clamp(56px, 10vw, 160px);
  width: min(100%, 980px);
}
.login-kicker {
  margin: 0 0 var(--sp-4);
  color: var(--mint-deep);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.login-intro h1 {
  margin: 0;
  font-size: clamp(64px, 9vw, 112px);
  font-weight: 850;
  letter-spacing: -.065em;
  line-height: .78;
}
.login-copy {
  margin: var(--sp-5) 0 0;
  color: var(--ink-soft);
  font-size: 17px;
  font-weight: 650;
  line-height: 1.5;
}
.login-form {
  padding: 36px 0;
}
.login-form label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: 14px;
  font-weight: 800;
}
.login-form input {
  width: 100%;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 650;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  padding: 11px 2px;
  margin-bottom: var(--sp-4);
}
.login-form input:focus { outline: 0; border-color: var(--mint-deep); }
.login-form .btn {
  width: 100%;
  padding: 13px 18px;
  border-radius: var(--r-sm);
}
.login-err { color: var(--danger); font-size: 13px; font-weight: 700; margin: 0 0 var(--sp-3); }
.login-or {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-4) 0;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-link {
  display: block;
  width: 100%;
  margin-top: var(--sp-3);
  padding: 0;
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
}
.login-note { margin: var(--sp-3) 0 0; color: var(--ink-soft); font-size: 13px; font-weight: 650; }
.login-note.is-err { color: var(--danger); font-weight: 700; }

@media (max-width: 700px) {
  .login-body {
    place-items: start stretch;
    background: var(--bg);
  }
  .login-layout {
    grid-template-columns: 1fr;
    gap: 48px;
    margin: auto 0;
  }
  .login-intro h1 { font-size: clamp(64px, 22vw, 92px); }
  .login-copy { font-size: 16px; }
  .login-form {
    border-top: 1px solid var(--line);
    padding: var(--sp-5) 0 0;
  }
}

/* ---------- desktop ---------- */
@media (min-width: 700px) {
  :root { --lane-h: 27px; --dayrow-h: 34px; }
  body.thick { --lane-h: 32px; }
  .bar { font-size: 13.5px; line-height: 18px; }
  body.thick .bar { font-size: 14.5px; line-height: calc(var(--lane-h) - 2px); }
  .day { font-size: 15px; }
  .month { padding: var(--sp-5); }
}

@media (max-width: 699px) {
  .dow-row, .week { grid-template-columns: 84px repeat(7, 1fr); }
  .lane-heading { font-size: 10px; padding-left: 3px; }
  .lane-label { padding: 0 3px; font-size: 11px; }
  header { padding-inline: var(--sp-3); }
  .header-row { flex-wrap: nowrap; gap: 6px; }
  .header-row h1 { flex-basis: auto; font-size: 20px; white-space: nowrap; }
  .header-row .btn-mini { font-size: 12px; padding: 6px 10px; }
  .view-toggle { min-width: 0; }
  #now {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    margin-top: var(--sp-2);
  }
  .chip {
    min-width: 0;
    overflow: hidden;
    padding-inline: 10px;
    text-overflow: ellipsis;
  }
  #cal { padding-top: var(--sp-4); }
}

/* iOS zooms focused form controls whose computed text is below 16px. */
button, a, input, textarea, select { touch-action: manipulation; }
@media (pointer: coarse) {
  input, textarea, select { font-size: 16px; }
}
