/* 색·간격은 여기 변수 한곳에서만 정한다. 다크 모드는 변수만 바꾼다.
   기기 설정을 따르되, 버튼으로 고른 값(data-theme)이 있으면 그것이 우선한다 */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #fff; --text: #1a1d26; --muted: #737a8c; --line: #eceef3;
  --primary: #3b5bdb; --primary-ink: #fff; --danger: #d6336c; --ok: #2b8a3e;
  --sun: #e03131; --sat: #3b5bdb;
  --radius: 12px; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --surface: #0e1015; --text: #e9ebf2; --muted: #8e95a8; --line: #23283a;
    --primary: #7b96ff; --primary-ink: #0e1220; --danger: #ff6b9a; --ok: #69db7c;
    --sun: #ff8787; --sat: #91a7ff; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #14161c; --surface: #0e1015; --text: #e9ebf2; --muted: #8e95a8; --line: #23283a;
    --primary: #7b96ff; --primary-ink: #0e1220; --danger: #ff6b9a; --ok: #69db7c;
    --sun: #ff8787; --sat: #91a7ff; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0 auto; padding: 0 20px 40px; max-width: 1040px; background: var(--surface); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}
body > .narrow, main.narrow { max-width: 760px; margin: 0 auto; }
h1 { font-size: 1rem; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
h3 { font-size: .85rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; font-size: .85em; }

/* 상단 */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 7px; flex: none; width: 26px; height: 26px; }
.actions, .tools { display: flex; align-items: center; gap: 8px; flex: none; }
.tools { flex-wrap: wrap; justify-content: flex-end; }
/* 넓은 화면: 로고 | 도구들 + 일정 버튼 한 줄. 좁은 화면(아래 미디어 쿼리)은 두 줄 */
.top { flex-wrap: wrap; }
.brand { margin-right: auto; }
.tools { order: 1; }
#add { order: 2; }
/* 앱 전환: 현재 앱(h1)은 굵게, 메모 앱은 링크. 좁으면 이름 사이에서만 줄바꿈 */
.apps { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; row-gap: 2px; min-width: 0; }
.brand h1, .apps-other { white-space: nowrap; }
.apps-other { display: inline-flex; gap: 8px; color: var(--muted); font-size: 1rem; }
.apps-other a { color: var(--muted); font-weight: 500; text-decoration: none; }
.apps-other a:hover { color: var(--text); text-decoration: underline; }
.who { color: var(--muted); font-size: .85rem; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: transparent; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 범주 범례 */
.legend { display: flex; gap: 4px; overflow-x: auto; padding: 2px 0 14px; scrollbar-width: none; }
.legend::-webkit-scrollbar { display: none; }
.legend button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid transparent; border-radius: 999px; background: none; color: var(--muted); font: inherit; font-size: .78rem; white-space: nowrap; flex: none; cursor: pointer; }
.legend button:hover { background: var(--bg); }
.legend button[aria-pressed="true"] { border-color: var(--line); background: var(--bg); color: var(--text); font-weight: 600; }
.legend.filtering button[aria-pressed="false"] { opacity: .5; }
.legend i { width: 8px; height: 8px; border-radius: 50%; }
@media (min-width: 700px) { .legend { flex-wrap: wrap; overflow: visible; } }

/* 카드·알림 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
body:has(#cal) .card { border: 0; padding: 0; margin: 0; border-radius: 0; }
.notice { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.notice.bad { border-color: var(--danger); color: var(--danger); }
.notice.ok { border-color: var(--ok); color: var(--ok); }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 12px; }

/* 입력 */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; min-height: 36px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); opacity: .8; }

/* 일정 창 */
dialog {
  width: min(440px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 16px; padding: 22px; background: var(--surface);
  color: var(--text); box-shadow: 0 16px 48px rgba(10, 12, 24, .18);
}
dialog::backdrop { background: rgba(12, 14, 24, .38); }
dialog h2 { font-size: 1.1rem; margin-bottom: 14px; }
form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); font-weight: 500; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
label input, label select, label textarea { font-weight: 400; font-size: .95rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two input { min-width: 0; }
.btns { display: flex; gap: 8px; margin-top: 4px; }
.btns span { flex: 1; }
.meta { margin: 0; font-size: .75rem; color: var(--muted); }
.err { color: var(--danger); margin: 0; min-height: 1.2em; font-size: .85rem; }
.field { display: flex; flex-direction: column; gap: 4px; }

/* 메모 칸 @ 힌트: 입력칸 위쪽에만 뜬다(높이는 app.js가 위 공간에 맞춘다) */
.memo-wrap { position: relative; display: flex; flex-direction: column; }
.memo-wrap textarea { font-size: .95rem; }
.hints {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 4px); z-index: 1; margin: 0; padding: 4px; list-style: none;
  overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(10, 12, 24, .18); font-size: .9rem;
}
.hints li { padding: 8px 10px; min-height: 36px; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hints li:hover, .hints li[aria-selected="true"] { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.hints li.note { color: var(--muted); cursor: default; background: none; }

/* 일정 메모 속 메모 링크(칩)와 딥링크 강조 */
.chip { padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; text-decoration: none; }
.chip:hover { text-decoration: underline; }
.chip.gone { color: var(--muted); background: var(--bg); text-decoration: line-through; }
.chip .del { display: inline-block; margin-left: 4px; font-size: .8em; text-decoration: none; } /* inline-block이라 취소선이 안 걸린다 */
.day-list li.hl { background: color-mix(in srgb, var(--primary) 10%, transparent); border-radius: 0 8px 8px 0; padding-right: 8px; }

.toast:empty { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--surface); font-size: .9rem;
}

/* 도움말 */
dialog.help { max-height: calc(100dvh - 32px); overflow-y: auto; word-break: keep-all; } /* 한글이 단어 중간에서 끊기지 않게 */
.help h3 { margin: 18px 0 6px; font-size: .95rem; color: var(--text); }
.help p { margin: 10px 0 4px; font-size: .9rem; }
.help ul, .help ol { margin: 0; padding-left: 20px; font-size: .9rem; }
.help li { margin: 4px 0; }
.help .meta { margin-top: 14px; }

/* 알림 */
.btn.icon { position: relative; width: 34px; padding: 0; }
#bell-dot { position: absolute; top: 5px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); box-sizing: content-box; }
dialog#notif { margin: 56px 16px auto auto; }
.n-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.n-head h2 { margin: 0; }
.n-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 55vh; overflow-y: auto; }
.n-list li { padding: 10px 0 10px 14px; border-bottom: 1px solid var(--line); position: relative; font-size: .9rem; }
.n-list li.unread { font-weight: 600; }
.n-list li.unread::before { content: ""; position: absolute; left: 0; top: 17px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.n-list li.empty { border: 0; padding-left: 0; color: var(--muted); }
.n-list .meta { font-weight: 400; }

/* 선택한 날짜의 일정 목록(달력 아래 섹션) */
.day-panel { margin-top: 8px; padding-top: 20px; border-top: 1px solid var(--line); }
.day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.day-head h2 { margin: 0; }
.day-head .hol-name { color: var(--sun); font-weight: 600; }
.fc .fc-daygrid-day.sel { box-shadow: inset 0 0 0 2px var(--primary); background: color-mix(in srgb, var(--primary) 6%, transparent); }
.day-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.day-list li { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.day-list li p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.day-list li.empty { border-left: 0; padding-left: 0; color: var(--muted); }

/* FullCalendar */
.fc {
  --fc-border-color: var(--line); --fc-page-bg-color: transparent; --fc-neutral-bg-color: transparent;
  --fc-today-bg-color: transparent;
  --fc-button-bg-color: var(--surface); --fc-button-border-color: var(--line); --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--bg); --fc-button-hover-border-color: var(--muted);
  --fc-button-active-bg-color: var(--bg); --fc-button-active-border-color: var(--muted);
  --fc-more-link-bg-color: transparent; --fc-more-link-text-color: var(--muted);
}
.fc .fc-toolbar { gap: 8px; margin-bottom: 14px !important; }
.fc .fc-toolbar-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
.fc .fc-button { border-radius: 8px; font-weight: 600; font-size: .82rem; box-shadow: none !important; padding: .4em .8em; }
.fc .fc-button-group > .fc-button { border-radius: 0; }
.fc .fc-button-group > .fc-button:first-child { border-radius: 8px 0 0 8px; }
.fc .fc-button-group > .fc-button:last-child { border-radius: 0 8px 8px 0; }
.fc .fc-scrollgrid { border: 0; }
.fc .fc-scrollgrid td:last-child, .fc .fc-scrollgrid th:last-child { border-right: 0; }
.fc .fc-scrollgrid-section > td, .fc .fc-daygrid-day { border-left: 0; border-right: 0; } /* 세로선은 빼고 가로선만 */
.fc .fc-col-header-cell { border-left: 0; border-right: 0; padding: 8px 0; }
.fc .fc-col-header-cell-cushion { font-size: .78rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.fc .fc-col-header-cell.fc-day-sun .fc-col-header-cell-cushion { color: var(--sun); }
.fc .fc-col-header-cell.fc-day-sat .fc-col-header-cell-cushion { color: var(--sat); }
.fc .fc-daygrid-day-number { font-size: .82rem; padding: 4px 6px; text-decoration: none; color: var(--text); }
.fc .fc-day-sun .fc-daygrid-day-number, .fc td.holiday:not(.fc-day-today) .fc-daygrid-day-number { color: var(--sun); }
.fc .fc-day-sat .fc-daygrid-day-number { color: var(--sat); }
.fc .fc-day-other .fc-daygrid-day-top { opacity: .38; }
.fc .fc-day-today .fc-daygrid-day-number {
  background: var(--primary); color: var(--primary-ink); border-radius: 999px; min-width: 26px; text-align: center;
  margin: 3px; padding: 1px 6px; font-weight: 700;
}
.fc .fc-daygrid-day:hover { background: color-mix(in srgb, var(--text) 3%, transparent); cursor: pointer; }
.fc .fc-event { border-radius: 4px; border-width: 0 0 0 3px; font-size: .75rem; font-weight: 500; cursor: pointer; }
.fc .fc-daygrid-event { padding: 1px 5px; margin: 1px 4px; }
.fc .fc-daygrid-dot-event { background: transparent; }
.fc .fc-daygrid-dot-event:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.fc .fc-event-title { font-weight: 500; }
.fc .fc-daygrid-more-link { font-size: .72rem; font-weight: 600; margin: 0 6px; }

/* 좁은 화면 */
@media (max-width: 560px) {
  body { padding: 0 10px 24px; }
  .top { padding: 14px 0 10px; row-gap: 8px; }
  .tools { order: 3; flex: 1 0 100%; gap: 6px; }
  .tools .btn:not(.icon) { padding: 0 10px; }
  .who { display: none; } /* 둘째 줄에 아이콘이 7개까지 늘어나 자리가 모자란다 */
  .card { padding: 6px; border-radius: 12px; }
  .fc .fc-toolbar-title { font-size: 1rem; }
  .fc .fc-button { padding: .35em .6em; }
  .fc .fc-daygrid-day-number { padding: 2px 4px; font-size: .75rem; }
  .fc .fc-event { font-size: .68rem; }
  .two { grid-template-columns: 1fr; }
  dialog { padding: 18px; }
}
