/* =========================================================
   RiverSync DS — Calendar layer
   Week grid · continuous month grid · year overview · events.
   Light/dark via app-ui tokens; no hardcoded colors.
   Work hours read --cal-work-bg, everything else --cal-off-bg.
   ========================================================= */

:root{
  --cal-work-bg: var(--surface);
  --cal-off-bg: var(--surface-2);
  --cal-hour-h: 44px;
  --cal-gutter-w: 56px;
}

/* ---------- frame + header ---------- */
.rs-calendar{display:flex; flex-direction:column; min-height:0; height:100%;
  background:var(--surface); border:1px solid var(--border); border-radius:8px; overflow:hidden;}
.rs-calendar__head{display:flex; align-items:center; gap:10px; padding:10px 14px;
  border-bottom:1px solid var(--border); flex:none; background:var(--surface);}
.rs-calendar__title{font-size:15px; font-weight:600; color:var(--fg); min-width:170px;}
.rs-calendar__title small{font-weight:400; color:var(--fg3); margin-left:6px; font-size:12.5px;}
.rs-calendar__nav{display:flex; align-items:center; gap:2px;}
.rs-calendar__spacer{flex:1 1 auto;}
.rs-calendar__body{position:relative; flex:1 1 auto; min-height:0; display:flex; flex-direction:column;}

/* view zoom transitions (drill down / up) */
.rs-calendar__view{flex:1 1 auto; min-height:0; display:flex; flex-direction:column;}
@media (prefers-reduced-motion: no-preference){
  .rs-calendar__view[data-zoom="in"]{animation:rs-cal-zoom-in .22s var(--rs-ease, cubic-bezier(.4,0,.2,1));
    transform-origin:var(--cal-zoom-x,50%) var(--cal-zoom-y,50%);}
  .rs-calendar__view[data-zoom="out"]{animation:rs-cal-zoom-out .22s var(--rs-ease, cubic-bezier(.4,0,.2,1));
    transform-origin:var(--cal-zoom-x,50%) var(--cal-zoom-y,50%);}
}
@keyframes rs-cal-zoom-in{from{opacity:0; transform:scale(.92);} to{opacity:1; transform:scale(1);}}
@keyframes rs-cal-zoom-out{from{opacity:0; transform:scale(1.06);} to{opacity:1; transform:scale(1);}}

/* ---------- event block (shared week/month idiom) ---------- */
.rs-calevent{position:relative; display:flex; flex-direction:column; gap:1px; overflow:hidden;
  border-radius:3px; padding:3px 6px 3px 8px; cursor:pointer; text-align:left; border:none;
  background:var(--accent-soft); color:var(--fg); font:inherit;
  outline:1px solid var(--surface); outline-offset:0;}
.rs-calevent::before{content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background:var(--accent);}
.rs-calevent:hover{filter:brightness(.97);}
[data-theme="dark"] .rs-calevent:hover{filter:brightness(1.12);}
.rs-calevent.is-selected{box-shadow:0 0 0 1px var(--accent) inset;}
.rs-calevent__time{font-family:var(--rs-font-mono); font-size:10px; letter-spacing:.01em;
  color:var(--fg2); white-space:nowrap; font-variant-numeric:tabular-nums; line-height:1.2;}
.rs-calevent__title{font-size:11.5px; font-weight:500; line-height:1.25; color:var(--fg);
  overflow:hidden; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical;}
.rs-calevent__title .rs-ic{width:11px; height:11px; vertical-align:-1.5px; margin-right:3px; color:var(--fg2);}
.rs-calevent.is-done .rs-calevent__title{color:var(--fg3); text-decoration:line-through;}
/* semantic tones */
.rs-calevent[data-tone="success"]{background:var(--success-soft);} .rs-calevent[data-tone="success"]::before{background:var(--success);}
.rs-calevent[data-tone="warning"]{background:var(--warning-soft);} .rs-calevent[data-tone="warning"]::before{background:var(--warning);}
.rs-calevent[data-tone="danger"]{background:var(--danger-soft);} .rs-calevent[data-tone="danger"]::before{background:var(--danger);}
.rs-calevent[data-tone="info"]{background:var(--info-soft);} .rs-calevent[data-tone="info"]::before{background:var(--info);}
.rs-calevent[data-tone="maintenance"]{background:var(--maintenance-soft);} .rs-calevent[data-tone="maintenance"]::before{background:var(--maintenance);}
.rs-calevent[data-tone="neutral"]{background:var(--surface-3);} .rs-calevent[data-tone="neutral"]::before{background:var(--neutral);}

/* compact single-line variant (month-view agenda rows) */
.rs-calevent--row{flex-direction:row; align-items:center; gap:5px; padding:1px 5px 1px 8px; border-radius:2px;
  min-height:18px; width:100%; box-sizing:border-box; outline:none;}
.rs-calevent--row .rs-calevent__title{display:block; -webkit-line-clamp:unset; white-space:nowrap;
  text-overflow:ellipsis; flex:1 1 auto; min-width:0; font-size:11px;}
.rs-calevent--row .rs-calevent__time{font-size:9.5px;}

/* ---------- week view ---------- */
.rs-calweek{flex:1 1 auto; min-height:0; display:flex; flex-direction:column;}
.rs-calweek__cols{display:grid; grid-template-columns:var(--cal-gutter-w) repeat(7, 1fr);}
.rs-calweek__headrow{flex:none; border-bottom:1px solid var(--border); background:var(--surface);}
.rs-calweek__dayhead{padding:7px 8px 6px; text-align:left; border-left:1px solid var(--border); min-width:0;}
.rs-calweek__dayhead .rs-calweek__dow{font-size:10px; font-weight:600; letter-spacing:.08em;
  text-transform:uppercase; color:var(--fg3); display:block;}
.rs-calweek__dayhead .rs-calweek__date{font-size:16px; font-weight:600; color:var(--fg);
  font-variant-numeric:tabular-nums; line-height:1.3;}
.rs-calweek__dayhead.is-off .rs-calweek__date{color:var(--fg2);}
.rs-calweek__dayhead.is-today .rs-calweek__date{display:inline-grid; place-items:center; min-width:24px;
  height:24px; padding:0 4px; border-radius:5px; background:var(--accent); color:#fff;}
.rs-calweek__allday{border-left:1px solid var(--border); padding:2px 3px; display:flex; flex-direction:column; gap:2px;
  min-height:0;}
.rs-calweek__alldaylab{font-family:var(--rs-font-mono); font-size:9.5px; color:var(--fg3);
  display:flex; align-items:center; justify-content:flex-end; padding:0 8px 2px 0;}
.rs-calweek__alldayrow{flex:none; border-bottom:1px solid var(--border); background:var(--surface);}
.rs-calweek__scroll{flex:1 1 auto; min-height:0; overflow-y:auto; position:relative;}
.rs-calweek__grid{position:relative;}
.rs-calweek__gutter{position:relative; height:var(--cal-hour-h);}
.rs-calweek__gutter span{position:absolute; top:-6px; right:8px; font-family:var(--rs-font-mono);
  font-size:10px; color:var(--fg3); font-variant-numeric:tabular-nums; background:var(--surface);
  padding:0 2px; line-height:12px;}
.rs-calweek__col{position:relative; border-left:1px solid var(--border); min-width:0;}
.rs-calweek__slot{height:var(--cal-hour-h); box-sizing:border-box; border-bottom:1px solid var(--border);
  background:var(--cal-work-bg); cursor:pointer;}
.rs-calweek__slot.is-off{background:var(--cal-off-bg);}
.rs-calweek__slot:hover{background:var(--accent-soft);}
.rs-calweek__slot:last-child{border-bottom:none;}
.rs-calweek__events{position:absolute; inset:0 4px 0 1px; pointer-events:none;}
.rs-calweek__events .rs-calevent{position:absolute; pointer-events:auto; min-height:18px;}
.rs-calweek__now{position:absolute; left:0; right:0; height:0; border-top:2px solid var(--danger);
  pointer-events:none; z-index:3;}
.rs-calweek__now::before{content:""; position:absolute; left:-2px; top:-5px; width:8px; height:8px;
  border-radius:50%; background:var(--danger);}

/* ---------- month view (continuous week-by-week scroll) ---------- */
.rs-calmonth{flex:1 1 auto; min-height:0; display:flex; flex-direction:column;}
.rs-calmonth__dows{display:grid; grid-template-columns:repeat(7, 1fr); flex:none;
  border-bottom:1px solid var(--border); background:var(--surface);}
.rs-calmonth__dows span{padding:6px 10px; font-size:10px; font-weight:600; letter-spacing:.08em;
  text-transform:uppercase; color:var(--fg3); border-left:1px solid var(--border);}
.rs-calmonth__dows span:first-child{border-left:none;}
.rs-calmonth__scroll{flex:1 1 auto; min-height:0; overflow-y:auto; scroll-behavior:auto; position:relative;
  scroll-snap-type:y proximity;}
.rs-calmonth__week{display:grid; grid-template-columns:repeat(7, 1fr); border-bottom:1px solid var(--border);
  scroll-snap-align:start;}
.rs-calmonth__day{position:relative; min-height:0; border-left:1px solid var(--border); padding:30px 4px 4px;
  background:var(--cal-work-bg); display:flex; flex-direction:column; gap:2px; overflow:hidden; cursor:pointer;
  box-sizing:border-box;}
.rs-calmonth__day:first-child{border-left:none;}
.rs-calmonth__day.is-off{background:var(--cal-off-bg);}
.rs-calmonth__day:hover .rs-calmonth__num{color:var(--accent);}
.rs-calmonth__num{position:absolute; top:5px; left:6px; right:6px; display:flex; align-items:center; gap:6px;
  font-size:12px; font-weight:600; color:var(--fg2); font-variant-numeric:tabular-nums; line-height:18px;}
.rs-calmonth__day.is-out .rs-calmonth__num{color:var(--fg3); font-weight:400;}
.rs-calmonth__num .rs-calmonth__mon{font-size:10.5px; font-weight:600; letter-spacing:.05em;
  text-transform:uppercase; color:var(--accent);}
.rs-calmonth__day.is-today .rs-calmonth__num i{display:inline-grid; place-items:center; min-width:20px; height:20px;
  padding:0 3px; border-radius:5px; background:var(--accent); color:#fff; font-style:normal;}
.rs-calmonth__num i{font-style:normal;}
.rs-calmonth__more{border:none; background:none; padding:1px 6px 1px 11px; text-align:left; cursor:pointer;
  font-size:10.5px; font-weight:600; color:var(--fg3); border-radius:3px;}
.rs-calmonth__more:hover{color:var(--accent); background:var(--accent-soft);}

/* ---------- year view ---------- */
.rs-calyear{flex:1 1 auto; min-height:0; overflow-y:auto; padding:18px;
  display:grid; grid-template-columns:repeat(4, 1fr); gap:14px; align-content:start;}
@media (max-width: 1100px){ .rs-calyear{grid-template-columns:repeat(3, 1fr);} }
@media (max-width: 760px){ .rs-calyear{grid-template-columns:repeat(2, 1fr);} }
.rs-calyear__month{border:1px solid var(--border); border-radius:6px; background:var(--surface);
  padding:10px 12px 12px; cursor:pointer; text-align:left; font:inherit; color:var(--fg);
  transition:border-color .12s, box-shadow .12s;}
.rs-calyear__month:hover{border-color:var(--accent-border); box-shadow:var(--shadow-sm);}
.rs-calyear__month.is-current{border-color:var(--accent-border);}
.rs-calyear__name{font-size:12.5px; font-weight:600; color:var(--fg); margin-bottom:8px; display:flex; align-items:center; gap:8px;}
.rs-calyear__name .rs-calyear__count{margin-left:auto; font-family:var(--rs-font-mono); font-size:10px;
  color:var(--fg3); font-weight:400;}
.rs-calyear__grid{display:grid; grid-template-columns:repeat(7, 1fr); gap:1px;}
.rs-calyear__dow{font-size:8.5px; font-weight:600; color:var(--fg3); text-align:center; text-transform:uppercase;
  padding-bottom:3px;}
.rs-calyear__day{position:relative; height:20px; display:grid; place-items:center; font-size:10px;
  color:var(--fg2); font-variant-numeric:tabular-nums; border-radius:3px;}
.rs-calyear__day.is-out{visibility:hidden;}
.rs-calyear__day.is-off{color:var(--fg3); background:var(--cal-off-bg);}
.rs-calyear__day.is-busy::after{content:""; position:absolute; left:50%; bottom:1px; width:3px; height:3px;
  margin-left:-1.5px; border-radius:50%; background:var(--accent);}
.rs-calyear__day.is-today{background:var(--accent); color:#fff;}
.rs-calyear__day.is-today.is-busy::after{background:#fff;}
.rs-calyear__day:not(.is-out):hover{box-shadow:0 0 0 1px var(--accent-border) inset; color:var(--fg);}
.rs-calyear__day.is-today:hover{color:#fff;}

/* ---------- day-glance popover (year view hover) ---------- */
.rs-calglance{position:fixed; z-index:80; width:252px; visibility:hidden; pointer-events:none;
  background:var(--surface); border:1px solid var(--border); border-radius:6px;
  box-shadow:var(--shadow-lg); overflow:hidden;}
@media (prefers-reduced-motion: no-preference){
  .rs-calglance{animation:rs-calpop-in .14s var(--rs-ease, cubic-bezier(.4,0,.2,1));}
}
.rs-calglance__head{display:flex; align-items:baseline; gap:6px; padding:4px 7px 3px;
  border-bottom:1px solid var(--border);}
.rs-calglance__date{font-size:12px; font-weight:600; color:var(--fg);}
.rs-calglance__today{font-size:9.5px; font-weight:600; letter-spacing:.06em; text-transform:uppercase;
  color:var(--accent);}
.rs-calglance__count{margin-left:auto; font-family:var(--rs-font-mono); font-size:10px; color:var(--fg3);
  font-variant-numeric:tabular-nums;}
.rs-calglance__allday{display:flex; flex-direction:column; gap:1px; padding:2px 2px 0;}
.rs-calglance__allday .rs-calevent__time{margin-left:auto;}
.rs-calglance__hours{position:relative; margin:0; padding-left:28px;}
.rs-calglance__hour{height:16px; box-sizing:border-box; border-top:1px solid var(--border);
  background:var(--cal-work-bg); position:relative;}
.rs-calglance__hour:last-child{border-bottom:none;}
.rs-calglance__hour.is-off{background:var(--cal-off-bg);}
.rs-calglance__hour:first-child{border-top:none;}
.rs-calglance__hour:first-child span{display:none;}
.rs-calglance__hour span{position:absolute; left:-26px; top:-5px; width:22px; text-align:right;
  font-family:var(--rs-font-mono); font-size:9px; color:var(--fg3); font-variant-numeric:tabular-nums;
  line-height:11px;}
.rs-calglance__events{position:absolute; top:0; bottom:0; left:28px; right:1px;}
.rs-calglance__events .rs-calevent{position:absolute; min-height:12px; padding:1px 4px 1px 7px;
  border-radius:2px; outline:none; gap:0;}
.rs-calglance__events .rs-calevent .rs-calevent__title{font-size:9.5px; line-height:1.25; -webkit-line-clamp:1;}
.rs-calglance__events .rs-calevent .rs-calevent__time{font-size:8.5px;}
.rs-calglance__now{position:absolute; left:0; right:0; height:0; border-top:2px solid var(--danger); z-index:3;}
.rs-calglance__now::before{content:""; position:absolute; left:-2px; top:-4px; width:6px; height:6px;
  border-radius:50%; background:var(--danger);}
.rs-calglance__empty{position:absolute; inset:0; padding-left:28px; display:grid; place-items:center;
  font-size:10.5px; color:var(--fg3);}

/* ---------- event detail popover ---------- */
.rs-calpop{position:fixed; z-index:80; width:300px; background:var(--surface); border:1px solid var(--border);
  border-radius:6px; box-shadow:var(--shadow-lg); padding:12px 14px;
  display:flex; flex-direction:column; gap:8px;}
@media (prefers-reduced-motion: no-preference){
  .rs-calpop{animation:rs-calpop-in .14s var(--rs-ease, cubic-bezier(.4,0,.2,1));}
}
@keyframes rs-calpop-in{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;}}
.rs-calpop__top{display:flex; align-items:flex-start; gap:8px;}
.rs-calpop__title{font-size:13.5px; font-weight:600; color:var(--fg); line-height:1.35; flex:1 1 auto; text-wrap:pretty;}
.rs-calpop__x{flex:none; display:grid; place-items:center; width:22px; height:22px; border:none; background:none;
  padding:0; color:var(--fg3); cursor:pointer; border-radius:4px;}
.rs-calpop__x:hover{background:var(--surface-3); color:var(--fg);}
.rs-calpop__when{font-family:var(--rs-font-mono); font-size:11px; color:var(--fg2);
  font-variant-numeric:tabular-nums; display:flex; align-items:center; gap:6px;}
.rs-calpop__when .rs-ic{width:13px; height:13px; color:var(--fg3);}
.rs-calpop__row{display:flex; align-items:center; gap:6px; flex-wrap:wrap; font-size:12px; color:var(--fg2);}
.rs-calpop__row .rs-ic{width:13px; height:13px; color:var(--fg3);}
.rs-calpop__refs{display:flex; flex-wrap:wrap; gap:5px;}
.rs-calpop__link{display:flex; align-items:center; gap:8px; padding:7px 9px; border:1px solid var(--border);
  border-radius:5px; background:var(--surface-2); cursor:pointer; font:inherit; text-align:left; width:100%;
  box-sizing:border-box; color:var(--fg);}
.rs-calpop__link:hover{border-color:var(--border-strong); background:var(--surface-3);}
.rs-calpop__link .rs-calpop__linkmain{flex:1 1 auto; min-width:0; display:flex; flex-direction:column; gap:1px;}
.rs-calpop__link .rs-calpop__linktitle{font-size:12px; font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}

/* ---------- schedule detail editor (off-canvas body) ---------- */
.rs-evedit{display:flex; flex-direction:column; gap:14px;}
.rs-evedit__row{display:grid; grid-template-columns:1fr 1fr; gap:12px; align-items:start;}
.rs-evedit .rs-calpop__refs{display:flex; flex-wrap:wrap; gap:5px;}

