*{box-sizing:border-box}
body{margin:0;background:#f5f7fb;color:#172033;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}
#app{max-width:1050px;margin:auto;padding:20px}h1{margin:0;font-size:25px}
#subtitle{color:#718096;font-size:13px;margin-top:4px}
.card{background:#fff;border:1px solid #e1e6ef;border-radius:16px;padding:15px;margin:12px 0}
.tabs{display:flex;gap:7px;margin-bottom:12px}.tab{padding:9px 14px;border-radius:10px;border:1px solid #e1e6ef;background:#fff;font-weight:750;color:#1683e8}
.tab.active{background:#172033;color:#fff}
.head{display:grid;grid-template-columns:40px 1fr 40px;align-items:center;gap:8px;margin-bottom:12px}
.month{text-align:center;font-size:20px;font-weight:800}.month-btn{border:1px solid #e1e6ef;background:#fff;border-radius:9px;width:36px;height:34px;font-size:20px;color:#536174}
.grid{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:6px;width:100%;min-width:0}.dow{text-align:center;color:#718096;font-size:11px;font-weight:800;padding:5px}
.empty{min-height:100px;min-width:0}.day{min-width:0;min-height:100px;border:1px solid #e1e6ef;border-radius:11px;background:#fafbfe;padding:8px;display:flex;flex-direction:column;cursor:pointer}
.day:hover{border-color:#aab7ca}.num{font-size:12px;font-weight:850}.who{display:block;margin-top:auto;text-align:center;padding:7px 3px;border-radius:8px;font-size:10px;font-weight:850}
.day.a_v_be .who{background:#bfdbfe;color:#1d4ed8}.day.a_v_rh .who{background:#bbf7d0;color:#166534}.day.tehila .who{background:#fbcfe8;color:#be185d}.day.both .who{background:#ddd6fe;color:#6d28d9}.day.other .who{background:#cbd5e1;color:#334155}
.legend{display:flex;flex-direction:column;align-items:flex-start;gap:8px;margin-top:13px;color:#718096;font-size:12px}.legend span{display:flex;align-items:center;gap:8px;line-height:1.35}
.dot{width:10px;height:10px;border-radius:50%;display:inline-block}.dot.a_v_be{background:#3b82f6}.dot.a_v_rh{background:#22c55e}.dot.tehila{background:#ec4899}.dot.both{background:#8b5cf6}.dot.other{background:#94a3b8}
.summary-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}.stat{border:1px solid #e1e6ef;border-radius:12px;padding:14px;background:#fafbfe}.stat b{display:block;font-size:23px}.stat span{color:#718096;font-size:12px}
.hidden{display:none!important}.modal{position:fixed;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;padding:18px}.shade{position:absolute;inset:0;background:rgba(23,32,51,.4)}
.editor{position:relative;z-index:2;background:#fff;border-radius:20px;padding:20px;width:min(410px,calc(100vw - 28px));box-shadow:0 24px 70px rgba(23,32,51,.3)}
.close{position:absolute;right:15px;top:15px;border:0;border-radius:50%;width:32px;height:32px;font-size:23px;background:#f1f4f8}.editor h2{margin:0 40px 4px 0;font-size:19px}.editor p{color:#718096;font-size:13px}
.choice{display:flex;align-items:center;gap:12px;padding:11px 6px;border-radius:9px;cursor:pointer}.choice:hover{background:#f5f7fb}.choice:has(input:checked){background:#f3f6fa}.choice input{position:absolute;opacity:0;width:1px;height:1px;pointer-events:none}.choice-dot{display:inline-block;flex:0 0 20px;width:20px;height:20px;border:3px solid var(--choice-color);border-radius:50%;background:#fff;position:relative}.choice input:checked + .choice-dot{border-color:var(--choice-color);background:var(--choice-color);box-shadow:inset 0 0 0 4px #fff}.choice input:focus-visible + .choice-dot{outline:3px solid #93c5fd;outline-offset:3px}.choice-a_v_be{--choice-color:#3b82f6}.choice-a_v_rh{--choice-color:#22c55e}.choice-tehila{--choice-color:#ec4899}.choice-both{--choice-color:#8b5cf6}.choice-other{--choice-color:#94a3b8}
.save{width:100%;margin-top:10px;border:0;background:#172033;color:#fff;padding:11px;border-radius:10px;font-weight:750;font-size:15px}.save:disabled{opacity:.65;cursor:wait}.save-status{margin:8px 0 0;font-size:13px;font-weight:650;text-align:center}.save-status.error{color:#b91c1c}.save-status.success{color:#15803d}
@media(max-width:650px){
  #app{width:100%;max-width:100%;padding:10px;overflow-x:hidden}
  header{min-width:0}
  h1{font-size:23px}
  #subtitle{font-size:12px}
  .card{padding:10px;border-radius:14px;min-width:0}
  .head{grid-template-columns:34px minmax(0,1fr) 34px;gap:5px}
  .month{font-size:clamp(15px,4.5vw,19px);white-space:nowrap}
  .month-btn{width:32px;height:32px}
  .grid{grid-template-columns:repeat(7,minmax(0,1fr));gap:3px;width:100%;min-width:0}
  .dow{font-size:clamp(9px,2.7vw,11px);padding:4px 0;min-width:0;overflow:hidden}
  .day,.empty{min-width:0;min-height:clamp(62px,19vw,82px)}
  .day{padding:5px 3px;border-radius:9px}
  .num{font-size:clamp(10px,3.2vw,12px)}
  .who{font-size:clamp(7px,2.15vw,9px);line-height:1.15;padding:5px 1px;overflow-wrap:anywhere;word-break:normal;border-radius:6px}
  .legend{gap:8px;font-size:11px}
  .legend span{gap:5px}
  .summary-grid{grid-template-columns:1fr 1fr}
}
@media(max-width:370px){
  #app{padding:7px}
  .card{padding:8px}
  .grid{gap:2px}
  .day{padding:4px 2px}
  .who{font-size:7px;letter-spacing:-.15px}
}

/* Mobile viewport hardening: keep every weekday inside the screen */
html, body { width:100%; max-width:100%; overflow-x:hidden; }
#app, main, .card, #calendarView, #summaryView { width:100%; max-width:100%; min-width:0; }
#calendar { display:grid; width:100%; max-width:100%; min-width:0; grid-template-columns:repeat(7,minmax(0,1fr)) !important; overflow:hidden; }
#calendar > * { min-width:0 !important; max-width:100%; }
.day, .empty, .dow { min-width:0 !important; max-width:100%; }
.day { overflow:hidden; }
.who { max-width:100%; white-space:normal; overflow-wrap:anywhere; }
@media (max-width:650px) {
  #app { padding-left:8px; padding-right:8px; }
  .card { padding:8px; }
  #calendar { column-gap:2px; row-gap:4px; }
  .day, .empty { min-height:clamp(56px,16vw,76px); }
  .day { padding:4px 2px; }
  .who { font-size:clamp(7px,1.9vw,9px); padding:4px 0; letter-spacing:-.25px; }
  .legend { gap:8px; font-size:10px; }
}
.view-controls{display:flex;justify-content:center;gap:6px;margin:0 0 12px}.view-toggle{border:1px solid #d8e0eb;background:#fff;color:#536174;border-radius:9px;padding:7px 16px;font-weight:750}.view-toggle.active{background:#172033;color:#fff;border-color:#172033}
.day.undefined{background:#fafbfe;border:1px solid #e1e6ef;border-radius:11px}.day.undefined .who{background:transparent;color:#172033;border:1px dashed #111827;border-radius:7px}
.dot.undefined{background:transparent;border:2px dashed #111827}
.day.readonly-day{cursor:default}.day.readonly-day:hover{border-color:inherit}

/* v10: week view is a genuinely larger, readable agenda layout */
#calendar.week-view{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;align-items:stretch;overflow:visible}
#calendar.week-view .week-day{min-height:190px;padding:16px;border-radius:14px;cursor:pointer;}
#calendar.week-view .week-day .num{font-size:17px;line-height:1.3;margin-bottom:16px}
#calendar.week-view .week-day .who{font-size:16px;line-height:1.35;padding:14px 12px;border-radius:10px;overflow-wrap:anywhere}
#calendar.week-view .week-day.undefined{background:#fafbfe;border:1px solid #e1e6ef}
#calendar.week-view .week-day.undefined .who{background:transparent;border:1px dashed #111827;color:#172033}
@media(max-width:650px){
 #calendar.week-view{grid-template-columns:minmax(0,1fr);gap:10px;overflow:visible}
 #calendar.week-view .week-day{min-height:142px;padding:14px;border-radius:13px}
 #calendar.week-view .week-day .num{font-size:16px;margin-bottom:12px}
 #calendar.week-view .week-day .who{font-size:16px;padding:12px;line-height:1.4}
}


/* v11: restrained, readable week agenda — one compact row per day */
#calendar.week-view {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 8px !important;
  overflow: visible !important;
  align-items: stretch;
}
#calendar.week-view .week-day {
  display: grid;
  grid-template-columns: minmax(105px, 0.85fr) minmax(0, 1.5fr);
  align-items: center;
  gap: 12px;
  min-height: 76px;
  height: auto;
  padding: 12px 14px;
  border: 1px solid #dfe5ed;
  border-radius: 12px;
  background: #fff;
  overflow: visible;
}
#calendar.week-view .week-day .num {
  display: block;
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 750;
  overflow-wrap: normal;
  word-break: normal;
}
#calendar.week-view .week-day .who {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 10px 12px;
  border-radius: 9px;
  text-align: center;
  font-size: 14px;
  line-height: 1.3;
  font-weight: 700;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: normal;
}
#calendar.week-view .week-day.undefined {
  background: #fff;
  border: 1px solid #dfe5ed;
}
#calendar.week-view .week-day.undefined .who {
  background: transparent;
  color: #172033;
  border: 1px dashed #111827;
}
@media (max-width: 420px) {
  #calendar.week-view .week-day {
    grid-template-columns: minmax(90px, 0.8fr) minmax(0, 1.4fr);
    gap: 8px;
    padding: 10px;
    min-height: 68px;
  }
  #calendar.week-view .week-day .num { font-size: 13px; }
  #calendar.week-view .week-day .who { font-size: 13px; padding: 9px 7px; }
}

/* v12 footer and undefined selection */
.choice-undefined{--choice-color:#111827}
.choice-undefined .choice-dot{border-style:dashed;background:transparent}
.choice-undefined input:checked + .choice-dot{background:#111827;border-style:solid}
.site-footer{max-width:1050px;margin:18px auto 0;padding:12px 20px 24px;text-align:center;color:#7b8798;font-size:12px;line-height:1.5}
.site-footer .copyright{font-weight:650;color:#536174}
@media(max-width:650px){.site-footer{padding:12px 10px 24px;font-size:11px}}

/* v12 footer and undefined selection */
.choice-undefined{--choice-color:#111827}
.choice-undefined .choice-dot{border-style:dashed;background:transparent}
.choice-undefined input:checked + .choice-dot{background:#111827;border-style:solid}
.site-footer{max-width:1050px;margin:18px auto 0;padding:12px 20px 24px;text-align:center;color:#7b8798;font-size:12px;line-height:1.5}
.site-footer .copyright{font-weight:650;color:#536174}
@media(max-width:650px){.site-footer{padding:12px 10px 24px;font-size:11px}}
