:root {
  --bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e4ecfc;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.08);
  --on-primary: #ffffff;
  --accent: #059669;
  --accent-soft: rgba(5, 150, 105, 0.12);
  --on-accent: #ffffff;
  --danger: #dc2626;
  --shadow: rgba(37, 99, 235, 0.06);

  --font-sans: "Inter", "Segoe UI", Arial, sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
}

body.dark {
  --bg: #0f172a;
  --sidebar-bg: #1e293b;
  --card-bg: #334155;
  --text: #f8fafc;
  --text-muted: #cbd5e1;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --on-primary: #0f172a;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.18);
  --on-accent: #0f172a;
  --danger: #ef4444;
  --shadow: rgba(0, 0, 0, 0.35);
}

/* 건너뛰기 링크 스타일 */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: var(--on-primary);
  padding: 8px 16px;
  z-index: 100;
  transition: top 0.2s;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus-visible {
  top: 0;
  outline: none;
}

* {
  box-sizing: border-box;
}

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.icon-svg {
  display: inline-block;
  vertical-align: middle;
  stroke-width: 2;
  color: currentColor;
  pointer-events: none;
  transition: transform 0.2s ease;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* 사이드바: 브랜드 / 통계 / 필터 / 정리 */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}

.icon-btn {
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  transition:
    background-color 0.2s ease,
    transform 0.15s ease;
}

.icon-btn:hover {
  background-color: var(--border);
}

.icon-btn:active {
  transform: scale(0.92);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  text-align: center;
}

.stat dt {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.todo-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-btn {
  display: flex;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease;
}

.filter-btn:hover {
  background: var(--primary-soft);
  color: var(--text);
}

.filter-btn:active {
  transform: scale(0.98);
}

.filter-btn.active {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}

.clear-btn {
  margin-top: auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85rem;
  transition:
    background-color 0.2s ease,
    transform 0.15s ease;
}

.clear-btn:hover:not(:disabled) {
  background: var(--primary-soft);
}

.clear-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.clear-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

/* 메인: 입력 / 목록 / 요약 */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 40px 48px;
}

#todo-form {
  margin-bottom: 24px;
  width: 100%;
}
.main-body {
  display: grid;
  grid-template-columns: 6fr 4fr;
  gap: 24px;
  flex: 1;
  min-height: 0; /* 내부 스크롤 활성화를 위한 설정 */
}

/* 달력 섹션 스타일 */
.calendar-section {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.03),
    0 14px 28px -10px var(--shadow);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.calendar-header h2 {
  font-size: 1.4rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.calendar-weekdays span:first-child {
  color: var(--danger, #ef4444);
}
.calendar-weekdays span:last-child {
  color: #3b82f6;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  gap: 8px;
  flex: 1;
}

.calendar-days div,
.calendar-days button {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
}

.calendar-days button {
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease;
  position: relative;
}
.calendar-days button.sunday {
  color: var(--danger, #ef4444);
}
.calendar-days button.saturday {
  color: #3b82f6;
}

/* 선택된 상태일 때는 글자색을 흰색으로 강제 유지 */
.calendar-days button.selected.sunday,
.calendar-days button.selected.saturday {
  color: var(--on-primary);
}

.calendar-days button:hover {
  background-color: var(--primary-soft);
}

.calendar-days button:active {
  transform: scale(0.9);
}

/* 선택된 날짜 강조 */
.calendar-days button.selected {
  background-color: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

/* 할 일이 존재하는 날짜에 나타나는 점 표시 */
.calendar-days button.has-todo::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 5px;
  height: 5px;
  background-color: var(--accent);
  border-radius: 50%;
}

.calendar-days button.selected.has-todo::after {
  background-color: var(--on-primary);
}

/* 일정 목록 섹션 스타일 */
.todo-section {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.03),
    0 14px 28px -10px var(--shadow);
}

ul#todo-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
}

.empty-state {
  margin: auto 0;
  text-align: center;
}

#todo-input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1rem;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

#todo-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

#todo-form button {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    transform 0.15s ease;
}

#todo-form button:hover {
  background: var(--primary-hover);
}

#todo-form button:active {
  transform: scale(0.97);
}

ul#todo-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.todo-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  gap: 10px;
  animation: fadeSlideIn 0.2s ease;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease;
}

.todo-item:hover {
  transform: translateY(-2px);
  border-color: var(--primary-soft);
  box-shadow: 0 8px 20px -8px var(--shadow);
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.todo-check {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.todo-checkbox {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.todo-text {
  overflow-wrap: anywhere;
}

.todo-item.completed {
  opacity: 0.7;
}

.todo-item.completed .todo-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.todo-actions button {
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 8px;
  min-width: 40px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease;
}

.todo-actions button:hover {
  background-color: var(--border);
  color: var(--text);
}

.todo-actions button:active {
  transform: scale(0.92);
}

.todo-item.editing .todo-actions {
  display: none;
}

.edit-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.95rem;
}

.edit-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.empty-state {
  flex: 1;
  display: flex;
  justify-content: center;
  color: var(--text-muted);
  margin: 0;
}

.empty-state[hidden] {
  display: none;
}

.todo-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
/* 할 일 텍스트 및 날짜 묶음 컨테이너 */
.todo-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

/* 날짜 텍스트 스타일 */
.todo-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}
/* 좁은 화면: 사이드바를 상단 바로 전환 */
@media (max-width: 1200px) {
  .main-body {
    grid-template-columns: 5fr 5fr;
  }
}
@media (max-width: 900px) {
  .main-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .main {
    height: auto;
    overflow-y: auto;
  }
  ul#todo-list {
    max-height: 300px;
  }
}
@media (max-width: 780px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 16px 20px;
    gap: 16px;
  }

  .brand {
    width: 100%;
  }

  .stats {
    flex: 1;
    min-width: 220px;
  }

  .todo-filters {
    flex-direction: row;
    flex: 1;
    min-width: 220px;
  }

  .filter-btn {
    flex: 1;
    text-align: center;
  }

  .clear-btn {
    margin-top: 0;
  }

  .main {
    padding: 24px 20px;
    min-height: 0;
  }
}
.calendar-title-group {
  display: flex;
  align-items: center;
  /* justify-content: center; */
  gap: 12px;
}

/* 오늘 버튼 스타일 */
.today-btn {
  padding: 4px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  background-color: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    transform 0.15s ease;
}

.today-btn:hover {
  background-color: var(--accent);
  color: var(--on-accent);
}

.today-btn:active {
  transform: scale(0.96);
}
