:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --text: #1c2033;
  --muted: #6b7186;
  --line: #e3e6ee;
  --accent: #4f6bff;
  --sun: #e5484d;
  --sat: #3e7bfa;
  --today: #4f6bff;
  --chip-l: 52%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2c;
    --surface-2: #1f2338;
    --text: #e9ebf5;
    --muted: #9aa0b8;
    --line: #2a2f48;
    --accent: #7d91ff;
    --sun: #ff6b70;
    --sat: #6f9bff;
    --today: #7d91ff;
    --chip-l: 62%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 340px; padding: 32px 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 20px 50px -25px rgba(20, 25, 60, .35);
  display: grid; gap: 12px; text-align: center;
}
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; color: var(--muted); }
.login .err { color: var(--sun); }
.login input {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.login button {
  padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700;
}

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: 6px; }
.nav > button:not(.pill) {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 20px; line-height: 1;
}
.month-label { position: relative; min-width: 128px; text-align: center; font-size: 19px; font-weight: 800; cursor: pointer; }
.month-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pill {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.pill.ghost { background: transparent; color: var(--muted); }
.search { flex: 1; min-width: 160px; display: flex; justify-content: flex-end; }
.search input {
  width: 100%; max-width: 280px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
}

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 200px minmax(0, 1fr) 300px; gap: 16px;
  padding: 16px; max-width: 1500px; margin: 0 auto;
}
.side details { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.side summary { font-weight: 700; cursor: pointer; padding: 2px 0; }
#calList { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
#calList label { display: flex; align-items: center; gap: 8px; padding: 5px 2px; cursor: pointer; word-break: break-all; }
#calList input { accent-color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- month grid ---------- */
.month-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays span { padding: 8px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
.weekdays span:first-child { color: var(--sun); }
.weekdays span:last-child { color: var(--sat); }
.day {
  min-height: 108px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: none; border-top: 0; border-left: 0; text-align: left; display: flex; flex-direction: column; gap: 2px;
  overflow: hidden;
}
.day:nth-child(7n) { border-right: 0; }
.day:hover { background: var(--surface-2); }
.day.other { opacity: .42; }
.day.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.day.sun .num, .day.holiday .num { color: var(--sun); }
.day.sat .num { color: var(--sat); }
.day.today .num { background: var(--today); color: #fff; }
.hol { font-size: 10.5px; color: var(--sun); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.chip {
  display: block; font-size: 11.5px; line-height: 1.35; padding: 1px 5px; border-radius: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: color-mix(in srgb, var(--c) 18%, transparent); border-left: 3px solid var(--c);
}
.more { font-size: 11px; color: var(--muted); padding: 0 4px; }

/* ---------- side panel ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  align-self: start; position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto;
}
.panel h2 { margin: 0 0 10px; font-size: 16px; }
#panelList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#panelList .empty { color: var(--muted); padding: 8px 0; }
.item {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 12px; padding: 9px 11px; display: grid; gap: 2px; border-left: 4px solid var(--c);
}
.item:hover { border-color: var(--c); }
.item .t { font-weight: 600; word-break: break-all; }
.item .s { font-size: 12px; color: var(--muted); }

/* ---------- detail dialog ---------- */
dialog {
  width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .5);
}
dialog::backdrop { background: rgba(10, 12, 25, .45); }
dialog .close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 24px; color: var(--muted); }
#detailBody h3 { margin: 0 32px 6px 0; font-size: 19px; word-break: break-all; }
#detailBody .bar { height: 4px; width: 48px; border-radius: 4px; background: var(--c); margin-bottom: 14px; }
#detailBody dl { display: grid; grid-template-columns: 64px 1fr; gap: 8px 12px; margin: 14px 0 0; }
#detailBody dt { color: var(--muted); font-size: 13px; }
#detailBody dd { margin: 0; word-break: break-all; }
#detailBody .memo { white-space: pre-wrap; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) 280px; }
  .side { grid-column: 1 / -1; }
  .side details { padding: 8px 12px; }
  #calList { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 760px) {
  .top { padding: 10px 16px; gap: 8px; }
  .search { order: 3; flex-basis: 100%; }
  .search input { max-width: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; gap: 12px; }
  .panel { position: static; max-height: none; }
  .day { min-height: 64px; padding: 3px 2px; }
  .chip { font-size: 10px; padding: 0 3px; border-left-width: 2px; }
  .hol { font-size: 9.5px; }
  .num { font-size: 12px; min-width: 22px; height: 22px; }
}
