:root {
  --blue: #4b7bff;
  --blue-dark: #3a63d8;
  --blue-light: #eaf0ff;
  --amber: #ff9f43;
  --green: #33b679;
  --red: #ff5c5c;
  --purple: #a06be0;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e6e9f2;
  --text: #1c2333;
  --text-muted: #6b7284;
  --text-faint: #a4aabb;

  --memo-bg: #fffceb;
  --memo-border: #f3e8b8;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(28, 35, 51, 0.04), 0 8px 24px rgba(28, 35, 51, 0.06);
  --shadow-pop: 0 12px 40px rgba(28, 35, 51, 0.16);

  --todo-w: 260px;
  --memo-w: 280px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1a1d29;
    --surface-2: #20232f;
    --border: #2a2e3d;
    --text: #eef0f6;
    --text-muted: #9aa0b4;
    --text-faint: #666c80;
    --blue-light: #22284a;
    --memo-bg: #26240f;
    --memo-border: #423c1a;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, textarea { font-family: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }

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

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-icon { font-size: 19px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sync-status {
  font-size: 12px;
  color: var(--text-faint);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}
.sync-status.online { color: var(--green); background: #e5f7ee; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(75,123,255,0.28); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-outline { background: var(--surface); color: var(--blue); border: 1px solid var(--blue-light); }
.btn-outline:hover { background: var(--blue-light); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-outline { background: transparent; color: var(--red); border: 1px solid #ffd7d7; }
.btn-danger-outline:hover { background: #fff2f2; }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 26px; height: 26px; font-size: 15px; }
.btn-primary-ghost { background: var(--blue-light); color: var(--blue-dark); font-weight: 700; }
.btn-primary-ghost:hover { background: var(--blue); color: #fff; }

/* ---------- Layout grid ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--todo-w) 1fr var(--memo-w);
  min-height: 0;
}

/* ---------- Shared side panels ---------- */
.todo-panel, .memo-panel {
  background: var(--surface);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
.todo-panel { border-right: 1px solid var(--border); }
.memo-panel { border-left: 1px solid var(--border); background: var(--memo-bg); }

.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-sub { font-size: 12px; color: var(--text-muted); margin: -4px 0 2px; }
.panel-empty { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 8px; line-height: 1.6; }

/* ---------- Todo list ---------- */
.todo-add-form { display: flex; gap: 6px; }
.todo-add-form input {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13.5px; background: var(--surface-2); color: var(--text);
}
.todo-add-form input:focus { outline: 2px solid var(--blue); background: var(--surface); }

.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.todo-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 8px 8px 4px;
  border-radius: var(--radius-sm);
}
.todo-item:hover { background: var(--surface-2); }
.todo-item:hover .todo-delete { opacity: 1; }
.todo-check {
  width: 19px; height: 19px; border-radius: 6px; flex-shrink: 0;
  border: 1.5px solid var(--text-faint); background: var(--surface);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px;
}
.todo-item.done .todo-check { background: var(--blue); border-color: var(--blue); }
.todo-text { flex: 1; font-size: 13.5px; word-break: break-word; cursor: default; }
.todo-item.done .todo-text { text-decoration: line-through; color: var(--text-faint); }
.todo-delete {
  border: none; background: none; color: var(--text-faint); cursor: pointer;
  opacity: 0; transition: opacity .15s ease; font-size: 15px; padding: 2px 4px; flex-shrink: 0;
}
.todo-delete:hover { color: var(--red); }

/* ---------- Memo ---------- */
.memo-textarea {
  flex: 1;
  width: 100%;
  min-height: 200px;
  resize: none;
  border: 1px solid var(--memo-border);
  border-radius: var(--radius-md);
  background: repeating-linear-gradient(
    var(--memo-bg), var(--memo-bg) 27px, var(--memo-border) 28px
  );
  background-position: 0 8px;
  background-attachment: local;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 28px;
  color: var(--text);
}
.memo-textarea:focus { outline: 2px solid var(--blue); }

/* ---------- Calendar (center) ---------- */
.calendar-panel {
  padding: 18px 24px 60px;
  overflow-y: auto;
  min-width: 0;
}
.calendar-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.calendar-title-group { display: flex; align-items: center; gap: 6px; }
.calendar-title { font-size: 19px; font-weight: 800; margin: 0; min-width: 128px; text-align: center; }

.view-switch { display: flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.view-switch-btn {
  border: none; background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 700; padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.view-switch-btn.active { background: var(--surface); color: var(--blue); box-shadow: var(--shadow-card); }

.hint-card {
  background: var(--blue-light);
  color: var(--blue-dark);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}
.hint-card p { margin: 0; }

.month-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.month-weekdays[hidden] { display: none; }
.month-weekdays div {
  text-align: center; font-size: 12px; font-weight: 700; color: var(--text-faint); padding: 6px 0;
}
.month-weekdays div:first-child { color: var(--red); }
.month-weekdays div:last-child { color: var(--blue); }

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(84px, 1fr);
  gap: 6px;
}
.month-grid[hidden], .week-grid[hidden] { display: none; }
.day-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 6px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  text-align: left;
  transition: background .12s ease, border-color .12s ease;
}
.day-cell:hover { background: var(--surface-2); }
.day-cell.outside { opacity: 0.4; }
.day-cell.selected { border-color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--blue); }
.day-num {
  font-size: 12.5px; font-weight: 700; color: var(--text);
  width: 20px; height: 20px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}
.day-cell.today .day-num { background: var(--blue); color: #fff; }
.day-cell.weekend-sun .day-num { color: var(--red); }
.day-cell.weekend-sat .day-num { color: var(--blue); }
.day-cell.today.weekend-sun .day-num, .day-cell.today.weekend-sat .day-num { color: #fff; }

.day-chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.event-chip {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 6px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.day-more { font-size: 10px; color: var(--text-faint); padding: 0 4px; }

/* ---------- Week view ---------- */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: start;
}
.week-day-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.week-day-col.selected { border-color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--blue); }
.week-day-head {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border: none; background: transparent; cursor: pointer;
  border-bottom: 1px solid var(--border); color: inherit;
}
.week-day-name { font-size: 11px; font-weight: 700; color: var(--text-faint); }
.week-day-num {
  font-size: 15px; font-weight: 800; color: var(--text);
  width: 26px; height: 26px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}
.week-day-col.today .week-day-num { background: var(--blue); color: #fff; }
.week-day-col.weekend-sun .week-day-num { color: var(--red); }
.week-day-col.weekend-sat .week-day-num { color: var(--blue); }
.week-day-col.today.weekend-sun .week-day-num, .week-day-col.today.weekend-sat .week-day-num { color: #fff; }
.week-day-events { padding: 6px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; min-height: 0; }
.week-event-chip {
  font-size: 11px; padding: 3px 6px; border-radius: 6px; color: #fff;
  cursor: pointer; white-space: normal; word-break: break-word; line-height: 1.3;
}

/* ---------- Day view: today's to-dos ---------- */
.day-view-todos {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.day-view-todos .panel-head { margin-bottom: 4px; }
.day-view-todos .panel-head h2 { font-size: 15px; margin: 0; }
.day-view-todos .panel-empty { padding: 12px 8px; }

/* ---------- Day view: hourly schedule ---------- */
.day-schedule {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 18px;
  overflow: hidden;
}
.day-allday-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.day-allday-row:empty { display: none; }
.day-allday-chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; color: #fff; cursor: pointer; white-space: nowrap; }
.day-schedule-scroll { max-height: 560px; overflow-y: auto; }
.day-schedule-grid { display: flex; }
.day-hour-labels { width: 52px; flex-shrink: 0; }
.day-hour-label {
  height: 56px; font-size: 11px; color: var(--text-faint);
  text-align: right; padding-right: 8px; box-sizing: border-box; transform: translateY(-6px);
}
.day-hour-track { position: relative; flex: 1; min-width: 0; border-left: 1px solid var(--border); }
.day-hour-lines { position: absolute; inset: 0; }
.day-hour-line { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); }
.day-event-layer { position: relative; }
.day-event-block {
  position: absolute; border-radius: 8px; padding: 4px 8px; color: #fff; font-size: 12px;
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow-card);
}
.day-event-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-event-time { font-size: 10.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Day agenda (under month grid) ---------- */
.day-agenda { margin-top: 22px; }
.day-agenda-title { font-size: 15px; font-weight: 800; margin: 0 0 10px; }
.day-agenda-list { display: flex; flex-direction: column; gap: 8px; }

.event-card {
  display: flex;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  border-left: 4px solid var(--blue);
  transition: transform .08s ease, box-shadow .15s ease;
}
.event-card:hover { transform: translateY(-1px); box-shadow: 0 4px 18px rgba(28,35,51,0.10); }
.event-time { font-size: 12px; color: var(--text-muted); font-weight: 700; min-width: 78px; }
.event-body { min-width: 0; }
.event-title { font-size: 14px; font-weight: 700; margin: 0 0 3px; }
.event-meta { font-size: 12px; color: var(--text-muted); }

/* ---------- FAB (mobile) ---------- */
.fab {
  position: fixed; right: 20px; bottom: 24px;
  width: 56px; height: 56px; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 28px;
  border: none; box-shadow: 0 10px 28px rgba(75,123,255,0.4);
  display: none; align-items: center; justify-content: center;
  cursor: pointer; z-index: 25;
}
.only-mobile { display: none; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 24, 38, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-pop);
  padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 17px; margin: 0; }
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field input[type="text"], .field input[type="date"], .field input[type="time"], .field textarea {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; color: var(--text); background: var(--surface-2);
  font-weight: 400;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; background: var(--surface); }
.field textarea { resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field input { width: 16px; height: 16px; }

.color-picker { display: flex; gap: 10px; }
.color-swatch {
  width: 26px; height: 26px; border-radius: 999px; border: 2px solid transparent;
  background: var(--swatch); cursor: pointer;
}
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

.modal-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
.modal-actions-right { display: flex; gap: 10px; margin-left: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1c2333; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 200; box-shadow: var(--shadow-pop);
}
.toast[hidden] { display: none; }

.side-scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  :root { --todo-w: 230px; --memo-w: 250px; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none; }

  .todo-panel, .memo-panel {
    position: fixed; top: var(--topbar-h); bottom: 0;
    width: 300px; max-width: 84vw;
    transition: transform .22s ease;
    z-index: 40;
    box-shadow: var(--shadow-pop);
  }
  .todo-panel { left: 0; transform: translateX(-100%); border-right: none; }
  .todo-panel.open { transform: translateX(0); }
  .memo-panel { right: 0; transform: translateX(100%); border-left: none; }
  .memo-panel.open { transform: translateX(0); }

  .side-scrim {
    position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(20,24,38,0.35);
    z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .side-scrim.show { display: block; opacity: 1; pointer-events: auto; }

  .calendar-panel { padding: 14px 12px 90px; }
  .calendar-title { font-size: 17px; min-width: 108px; }
  .month-grid { grid-auto-rows: minmax(58px, 1fr); gap: 4px; }
  .day-cell { padding: 4px 3px 3px; border-radius: 8px; }
  .day-num { font-size: 11.5px; width: 18px; height: 18px; }
  .event-chip { font-size: 0; line-height: 0; width: 6px; height: 6px; padding: 0; border-radius: 999px; flex-shrink: 0; }
  .day-chips { flex-direction: row; flex-wrap: wrap; gap: 3px; }
  .day-more { display: none; }

  .week-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(112px, 1fr);
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .week-day-col { min-height: 200px; }

  .day-schedule-scroll { max-height: calc(100vh - 320px); }
  .day-hour-labels { width: 42px; }
  .day-hour-label { font-size: 10px; padding-right: 5px; }
  .day-event-title, .day-event-time { font-size: 10.5px; }

  .fab { display: flex; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .brand-name { display: none; }
  .field-row { flex-direction: column; }
  .sync-status { display: none; }
  .view-switch-btn { padding: 6px 10px; font-size: 12.5px; }
}
