:root{
  --bg:#f6f7f8;
  --panel:#ffffff;
  --line:#e6e7ea;
  --text:#111318;
  --muted:#5c6470;
  --accent:#1b6b6f;
  --accent-soft: rgba(27,107,111,0.12);
  --radius:14px;
  --shadow: 0 6px 18px rgba(0,0,0,0.06);

  --week-row-h: 56px; /* Week hour row height for legibility */
  --week-dow-h: 30px; /* Sticky offset for week all-day bars */

  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

*{ box-sizing:border-box; }

html, body{ height:100%; }

body{
  margin:0;
  font-family: var(--sans);
  color:var(--text);
  background:var(--bg);
  overflow:hidden;
}

.app{
  height:100vh;
  display:flex;
  flex-direction:column;
}

.topbar{
  height:54px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 16px;
  border-bottom:1px solid var(--line);
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px);
  flex:0 0 auto;
}

.brand{ font-weight:600; letter-spacing:0.2px; }
.badge{
  font-size:12px;
  padding:6px 10px;
  border:1px solid var(--line);
  border-radius:999px;
  color:var(--muted);
  background:#fff;
}

.layout{
  flex:1;
  display:flex;
  gap:12px;
  padding:12px;
  align-items:stretch;
  position:relative;
  min-height:0;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
  min-height:0;
}
.panel-inner{
  padding:14px;
  height:100%;
  overflow:auto;
}
.panel.left{ width:320px; }
.panel.right{ width:320px; }

.center{
  flex:1;
  min-width:560px;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.cal-header{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex:0 0 auto;
}

.nav{ display:flex; align-items:center; gap:10px; }
.title{ font-weight:600; min-width:240px; }

.controls{ display:flex; gap:10px; align-items:flex-end; flex-wrap:wrap; justify-content:flex-end; }
.control{ display:flex; flex-direction:column; gap:6px; }
.control label{ font-size:12px; color:var(--muted); }
.control select, .control input{
  height:34px;
  border:1px solid var(--line);
  border-radius:10px;
  padding:0 10px;
  background:#fff;
  color:var(--text);
}
.jump-row{ display:flex; gap:6px; align-items:center; }
.jump-row select{ width:110px; }
.jump-row input{ width:140px; font-family:var(--mono); }

.btn{
  height:34px;
  padding:0 12px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  cursor:pointer;
}
.btn:hover{ border-color:#d2d5da; }

.iconbtn{
  width:34px;
  height:34px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  cursor:pointer;
  font-size:18px;
  line-height:32px;
}
.iconbtn:hover{ border-color:#d2d5da; }

.dropdown{
  position:absolute;
  margin-top:6px;
  right:12px;
  top:56px;
  width:180px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  box-shadow:var(--shadow);
  z-index:40;
}

.chk{ display:flex; gap:8px; align-items:center; font-size:14px; }
.small{ font-size:12px; }
.muted{ color:var(--muted); }

/* Central scroll container */
.cal-surface{
  flex:1;
  min-height:0;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  position:relative;
  overflow:auto;
  overscroll-behavior:contain;
}

/* Month + Week wrappers */
.month,
.week{
  position:relative;
  display:flex;
  flex-direction:column;
}

/* Sticky weekday rows */
.dow{
  position:sticky;
  top:0;
  z-index:20;
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom:1px solid var(--line);
  background:#fbfbfc;
}

.dow div{
  padding:10px 10px;
  font-size:12px;
  color:var(--muted);
  border-right:1px solid var(--line);
}
.dow div:last-child{ border-right:none; }

.week-dow{
  position:sticky;
  top:0;
  z-index:20;
  display:grid;
  grid-template-columns: 70px repeat(7, 1fr);
  border-bottom:1px solid var(--line);
  background:#fbfbfc;
}

.week-dow-spacer{
  border-right:1px solid var(--line);
}

.week-dow-cell{
  padding:10px 10px;
  border-right:1px solid var(--line);
  background:#fbfbfc;
}
.week-dow-cell:last-child{ border-right:0; }

.week-dow-main{
  font-size:12px;
  color:var(--muted);
  white-space: normal;
  line-height: 1.2;
}
.week-dow-sub{
  margin-top:2px;
  font-size:11px;
  color:var(--muted);
  opacity:0.9;
}

/* Month grid */
.month-bars{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 22px;
  gap:2px 6px;
  padding:6px 6px 0 6px;
  position:relative;
  z-index:1;
}

.week{
  border-bottom:1px solid var(--line);
}
.week:last-child{ border-bottom:none; }

/* WEEK all-day bars: sticky under the week header */
.week-bars{
  display:grid;
  grid-template-columns: 70px repeat(7, 1fr);
  grid-auto-rows: 22px;
  gap:2px 6px;
  padding:6px 6px 0 6px;

  position:sticky;
  top: var(--week-dow-h);
  z-index:19;
  background:#fff;
  border-bottom:1px solid var(--line);
}

/* Hour grid scrolls under sticky header + bars */
.week-grid{
  display:grid;
  grid-template-columns: 70px repeat(7, 1fr);
  position:relative;
  z-index:1;
}

.time-label{
  position:relative;
  height: var(--week-row-h);
  border-right:1px solid var(--line);
  border-bottom:1px solid var(--line);
  background:#fbfbfc;
  font-family: var(--mono);
  font-size:12px;
  color:var(--muted);
}

.time-label .main{
  position:absolute;
  top:6px;
  left:8px;
}

.time-label .ov{
  position:absolute;
  bottom:6px;
  right:8px;
  font-size:11px;
  color:var(--muted);
  opacity:0.9;
}

.week-cell{
  height: var(--week-row-h);
  position:relative;
  border-right:1px solid var(--line);
  border-bottom:1px solid var(--line);
  background:white;
}
.week-cell:nth-child(8n){ border-right:0; }

.bar{
  border-radius:8px;
  padding:3px 8px;
  font-size:12px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  border:1px solid rgba(0,0,0,0.05);
  background: rgba(27,107,111,0.12);
  color:#0f3f42;
}
.bar.special{ background: rgba(120,90,30,0.12); color:#3f2e0d; }
.bar.standard{ background: rgba(40,110,70,0.12); color:#0f3a27; }
.bar.secondary{ background: rgba(27,107,111,0.07); }
.bar.oneoff{ background: rgba(90,80,160,0.12); color:#2e2a6b; border-color: rgba(90,80,160,0.18); }
.bar:hover{ border-color: rgba(27,107,111,0.25); }

/* Month day cells */
.week-days{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  position:relative;
  z-index:1;
}
.day{
  min-height:92px;
  border-right:1px solid var(--line);
  padding:8px 8px 6px 8px;
  position:relative;
}
.day:last-child{ border-right:none; }

.day .sd{
  font-family:var(--mono);
  font-size:12px;
  color:var(--text);
  opacity:0.85;
  white-space: normal;
  line-height: 1.2;
}
.day .g{
  font-size:11px;
  color:var(--muted);
  margin-top:2px;
}
.day .more{
  margin-top:6px;
  font-size:12px;
  color:var(--accent);
  cursor:pointer;
}
.day:hover{
  outline:2px solid rgba(27,107,111,0.15);
  outline-offset:-2px;
}
.day.today::after{
  content:"";
  position:absolute;
  right:8px;
  top:8px;
  width:8px;
  height:8px;
  border-radius:50%;
  background:var(--accent);
  opacity:0.9;
}
.day.highlight{
  background: var(--accent-soft);
}
.day.outside{
  background:#fafafb;
  opacity:0.72;
}
.day.outside .sd{ color: var(--muted); }

/* Inspector */
.seoian-big{
  font-family:var(--mono);
  font-size:22px;
  font-weight:700;
  letter-spacing:0.3px;
}
.gregorian-small{
  margin-top:6px;
  font-size:13px;
  color:var(--muted);
}
.toggle{
  display:flex;
  gap:8px;
  align-items:center;
  font-size:13px;
  color:var(--muted);
  margin-top:8px;
}
.section{ margin-top:16px; }
.section-title{
  font-size:12px;
  color:var(--muted);
  margin-bottom:8px;
  text-transform:uppercase;
  letter-spacing:0.08em;
}
.list{ display:flex; flex-direction:column; gap:6px; }
.pill{
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  font-size:13px;
}
.eventitem{
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
}
.eventitem .title{
  font-size:13px;
  font-weight:700;
}
.eventitem .note{
  margin-top:3px;
  font-size:12px;
  color:var(--muted);
}
.eventitem.songofday .songlink{
  display:block;
  margin-top:6px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.eventitem.songofday .songlink:hover{
  text-decoration: underline;
}

.facts{ display:flex; flex-direction:column; gap:6px; }
.factrow{
  display:flex;
  justify-content:space-between;
  gap:10px;
  font-size:13px;
}
.factrow span:first-child{ color:var(--muted); }

/* Clocks */
.clocks{ display:flex; flex-direction:column; gap:16px; }
.clock-block{ display:flex; flex-direction:column; gap:8px; }
.tzlabel{ font-size:12px; color:var(--muted); }
.tzselect{
  height:34px;
  border:1px solid var(--line);
  border-radius:10px;
  padding:0 10px;
  font-family:var(--mono);
}

.ampm{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
  text-align:right;
}
.clockface{
  width:100%;
  aspect-ratio: 1 / 1;
  border:1px solid var(--line);
  border-radius:16px;
  background:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
}
.superday-title{
  font-size:12px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:0.08em;
}
.superday-meta{
  font-size:13px;
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:6px;
}
.superday-meta span{ font-family:var(--mono); }

/* Popover */
.popover{
  position:fixed;
  min-width:260px;
  max-width:340px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:14px;
  box-shadow:var(--shadow);
  padding:10px;
  z-index:50;
}
.popover .pop-title{
  font-weight:600;
  margin-bottom:6px;
}
.popover .pop-close{
  position:absolute;
  right:10px;
  top:8px;
  cursor:pointer;
  color:var(--muted);
}
.popover .pop-item{
  padding:8px 8px;
  border-radius:10px;
  border:1px solid var(--line);
  margin-top:8px;
  font-size:13px;
}

/* Mobile bottom sheet */
.bottom-sheet{ display:none; }

@media (max-width: 1040px){
  body{ overflow:auto; }

  .panel.left, .panel.right{ display:none; }
  .center{ min-width:0; }
  .layout{
    padding-bottom:190px;
    min-height:auto;
  }

  .cal-surface{
    overflow:visible;
    min-height:auto;
    flex:none;
  }

  .dow,
  .week-dow{
    position:static;
  }

  .week-bars{
    position:static;
    top:auto;
  }

  .bottom-sheet{
    display:block;
    position:fixed;
    left:12px;
    right:12px;
    bottom:12px;
    background:#fff;
    border:1px solid var(--line);
    border-radius:16px;
    box-shadow:var(--shadow);
    overflow:hidden;
    z-index:40;
    height:170px;
    transition: height 0.2s ease;
  }
  .bottom-sheet.expanded{ height:66vh; }

  .sheet-handle{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:10px 12px;
    border-bottom:1px solid var(--line);
    cursor:pointer;
    background:#fbfbfc;
  }
  .sheet-handle-text{
    font-family:var(--mono);
    color:var(--muted);
    font-size:13px;
  }
  .sheet-tabs{
    display:flex;
    border-bottom:1px solid var(--line);
  }
  .tab{
    flex:1;
    padding:10px 12px;
    background:#fff;
    border:none;
    cursor:pointer;
    color:var(--muted);
    font-weight:600;
  }
  .tab.active{
    color:var(--text);
    border-bottom:2px solid var(--accent);
  }
  .sheet-body{
    height:calc(100% - 86px);
    overflow:auto;
  }
  .sheet-pane{
    display:none;
    padding:12px;
  }
  .sheet-pane.active{ display:block; }
}

/* One-Off timed events */
.day-items{
  margin-top:8px;
  display:flex;
  flex-direction:column;
  gap:4px;
}
.day-item{
  font-size:11px;
  color:var(--text);
  opacity:0.9;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.day-item .t{
  font-family:var(--mono);
  color:var(--muted);
  margin-right:6px;
}

.oneoff-block{
  position:absolute;
  left:4px;
  right:4px;
  min-height:18px; /* enough for one line */
  border-radius:6px;
  padding:2px 4px;
  font-size:11px;
  line-height:1.15;
  background: rgba(90,80,160,0.12);
  color:#2e2a6b;
  border:1px solid rgba(90,80,160,0.18);
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  pointer-events:none;
}
