/* ===========================================================================
   kxd-sched · stylesheet
   A calm, modern, academic look. Light + dark via CSS variables.
   =========================================================================== */

:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eef0f3;
  --grid-line: #e6e8ec;
  --text: #1a1d23;
  --text-dim: #5b6470;
  --text-faint: #8a93a0;
  --border: #e2e5ea;
  --accent: #4f7cff;
  --accent-weak: #e9eefe;
  --busy: #98a2b3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1160px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
          "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

html[data-theme="dark"] {
  --bg: #0d1016;
  --bg-elev: #151a22;
  --bg-sunken: #10141b;
  --grid-line: #1f2630;
  --text: #e8ebf0;
  --text-dim: #a4adba;
  --text-faint: #6b7585;
  --border: #232b36;
  --accent: #6b91ff;
  --accent-weak: #1a2541;
  --busy: #525c6b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0d1016; --bg-elev: #151a22; --bg-sunken: #10141b; --grid-line: #1f2630;
    --text: #e8ebf0; --text-dim: #a4adba; --text-faint: #6b7585; --border: #232b36;
    --accent: #6b91ff; --accent-weak: #1a2541; --busy: #525c6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: 0 0 8px 0; z-index: 100;
}
.skip:focus { left: 0; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ---- Header --------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: saturate(1.4) blur(6px);
}
.header-inner {
  display: flex; align-items: center; gap: 20px;
  padding: 16px 20px; max-width: var(--maxw); margin: 0 auto; flex-wrap: wrap;
}
.identity { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.identity .name {
  font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: .2px;
  line-height: 1.1;
}
.identity .tagline { color: var(--text-dim); font-size: 13.5px; }
.identity .loc { color: var(--text-faint); font-size: 12.5px; }

.header-spacer { flex: 1 1 auto; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); background: var(--bg-sunken); white-space: nowrap;
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--busy); flex: none; }
.status-pill.free .dot { background: #2bb673; box-shadow: 0 0 0 4px rgba(43,182,115,.18); }
.status-pill.busy .dot { background: #e5484d; box-shadow: 0 0 0 4px rgba(229,72,77,.16); }
.status-pill .sub { color: var(--text-dim); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  cursor: pointer; user-select: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
.btn.icon { padding: 7px 9px; }
.link { color: var(--text-dim); font-size: 13px; padding: 4px 6px; }
.link:hover { color: var(--accent); }

/* ---- Toolbar -------------------------------------------------------------- */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 0 8px;
}
.seg {
  display: inline-flex; background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.seg button {
  border: 0; background: transparent; color: var(--text-dim); font: inherit; font-size: 13px;
  padding: 6px 14px; border-radius: 7px; cursor: pointer; font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

.nav { display: inline-flex; align-items: center; gap: 6px; }
.nav .range { font-weight: 600; min-width: 0; padding: 0 6px; }
.toolbar .spacer { flex: 1 1 auto; }
.muted { color: var(--text-faint); font-size: 12.5px; }

/* ---- Layout --------------------------------------------------------------- */
main { padding-bottom: 64px; }
.layout { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card .card-head { padding: 13px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13.5px; display:flex; align-items:center; gap:8px; }
.card .card-body { padding: 14px 16px; }

/* ---- Week grid ------------------------------------------------------------ */
.weekgrid { position: relative; overflow-x: auto; }
.weekgrid-inner { min-width: 720px; }
.allday-row {
  display: grid; grid-template-columns: var(--gutter, 56px) repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
}
.allday-row .corner { border-right: 1px solid var(--grid-line); }
.allday-cell { padding: 5px 6px; border-right: 1px solid var(--grid-line); min-height: 10px; display:flex; flex-direction:column; gap:4px; }
.allday-cell:last-child { border-right: 0; }
.chip {
  font-size: 11.5px; padding: 3px 7px; border-radius: 6px; font-weight: 600;
  color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--busy); cursor: pointer;
}

.daterow {
  display: grid; grid-template-columns: var(--gutter, 56px) repeat(7, 1fr);
  position: sticky; top: 0; background: var(--bg-elev); z-index: 5;
  border-bottom: 1px solid var(--border);
}
.daterow .corner { border-right: 1px solid var(--grid-line); }
.dayhead { text-align: center; padding: 8px 4px; border-right: 1px solid var(--grid-line); }
.dayhead:last-child { border-right: 0; }
.dayhead .dow { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.dayhead .dnum { font-size: 17px; font-weight: 600; line-height: 1.3; }
.dayhead.today .dnum { color: #fff; background: var(--accent); width: 30px; height: 30px; line-height: 30px; border-radius: 50%; display: inline-block; }
.dayhead.weekend { background: var(--bg-sunken); }
.dayhead.off .dow { color: var(--text-faint); }

.gridbody {
  display: grid; grid-template-columns: var(--gutter, 56px) repeat(7, 1fr);
  position: relative;
}
.timecol { border-right: 1px solid var(--grid-line); }
.timeslot { height: var(--hour-h, 52px); position: relative; }
.timeslot .lbl {
  position: absolute; top: -7px; right: 7px; font-size: 11px; color: var(--text-faint);
}
.daycol {
  position: relative; border-right: 1px solid var(--grid-line);
  background-image: repeating-linear-gradient(to bottom,
    var(--grid-line) 0, var(--grid-line) 1px,
    transparent 1px, transparent var(--hour-h, 54px));
}
.daycol:last-child { border-right: 0; }
.daycol.weekend { background-color: var(--bg-sunken); }
.hourline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid-line); }
.officeband { position: absolute; left: 0; right: 0; background: var(--accent-weak); opacity: .65; }

.event {
  position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 4px 7px;
  color: #fff; overflow: hidden; cursor: pointer; border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 2px rgba(0,0,0,.12); font-size: 12px;
}
.event .ev-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event .ev-time { opacity: .9; font-size: 11px; }
.event.tentative { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.18) 0 6px, transparent 6px 12px); }
.event.busy { background: var(--busy) !important; }

.nowline { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid #e5484d; z-index: 8; pointer-events: none; }
.nowline::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: #e5484d; }

/* ---- Agenda --------------------------------------------------------------- */
.agenda { display: flex; flex-direction: column; }
.agenda-day { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.agenda-day:last-child { border-bottom: 0; }
.agenda-date { color: var(--text-dim); }
.agenda-date .ad-dow { font-weight: 600; color: var(--text); }
.agenda-date.today .ad-dow { color: var(--accent); }
.agenda-items { display: flex; flex-direction: column; gap: 8px; }
.agenda-item { display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.agenda-item .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; transform: translateY(2px); background: var(--busy); }
.agenda-item .ai-time { color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 96px; font-size: 13px; }
.agenda-item .ai-title { font-weight: 500; }
.agenda-item .ai-loc { color: var(--text-faint); font-size: 12.5px; }
.agenda-empty { padding: 40px 16px; text-align: center; color: var(--text-faint); }

/* ---- Month ---------------------------------------------------------------- */
.month { padding: 8px; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-dow { text-align: center; font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; padding: 6px 0; }
.mcell { min-height: 84px; border: 1px solid var(--border); border-radius: 9px; padding: 6px; background: var(--bg-elev); display: flex; flex-direction: column; gap: 4px; }
.mcell.out { opacity: .4; }
.mcell.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.mcell .mnum { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.mcell.today .mnum { color: var(--accent); }
.mdot { font-size: 11px; padding: 2px 5px; border-radius: 5px; color: #fff; background: var(--busy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.mmore { font-size: 11px; color: var(--text-faint); }

/* ---- Sidebar -------------------------------------------------------------- */
.side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 84px; }
@media (max-width: 880px) { .side { position: static; } }
.avail-day { padding: 10px 0; border-bottom: 1px dashed var(--border); }
.avail-day:last-child { border-bottom: 0; }
.avail-day .ad-h { font-weight: 600; font-size: 13px; margin-bottom: 6px; display:flex; justify-content:space-between; }
.avail-day .ad-h .free-sum { color: var(--text-faint); font-weight: 500; }
.slot { display: inline-block; font-size: 12px; padding: 3px 8px; margin: 2px 4px 2px 0; border-radius: 6px; background: var(--accent-weak); color: var(--accent); font-variant-numeric: tabular-nums; }
.slot.none { background: var(--bg-sunken); color: var(--text-faint); }
.office-list { list-style: none; margin: 0; padding: 0; }
.office-list li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.office-list li:last-child { border-bottom: 0; }
.office-list .ol-when { color: var(--text-dim); font-variant-numeric: tabular-nums; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); }
.legend .lg .sw { width: 11px; height: 11px; border-radius: 3px; }

/* ---- Popover -------------------------------------------------------------- */
.scrim { position: fixed; inset: 0; background: rgba(8,11,16,.5); z-index: 50; display: none; }
.scrim.open { display: block; }
.popover {
  position: fixed; z-index: 60; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); width: min(360px, calc(100vw - 32px));
  padding: 0; display: none;
}
.popover.open { display: block; }
.pop-bar { height: 6px; border-radius: var(--radius) var(--radius) 0 0; background: var(--busy); }
.pop-body { padding: 16px 18px; }
.pop-title { font-weight: 700; font-size: 17px; margin: 0 0 4px; }
.pop-cat { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.pop-row { display: flex; gap: 9px; align-items: baseline; margin-top: 10px; color: var(--text-dim); font-size: 13.5px; }
.pop-row b { color: var(--text); font-weight: 600; min-width: 64px; }
.pop-note { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 13.5px; }
.pop-tentative { display:inline-block; margin-top:10px; font-size:12px; color:#b7791f; background:#fdf3df; padding:2px 8px; border-radius:6px; }
html[data-theme="dark"] .pop-tentative, @media (prefers-color-scheme: dark) { }

/* ---- Footer --------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); color: var(--text-faint); font-size: 12.5px; }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 20px; max-width: var(--maxw); margin: 0 auto; }

/* ---- No-JS ---------------------------------------------------------------- */
.nojs-header, main#main { max-width: 760px; margin: 0 auto; padding: 24px 20px; }
.nojs-list { list-style: none; padding: 0; }
.nojs-list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 12px; flex-wrap: wrap; }
.nojs-date { font-weight: 600; min-width: 110px; }
.nojs-time { color: var(--text-dim); min-width: 110px; }

.hidden { display: none !important; }
