*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: #f5f5f7;
  color: #1a1a1a;
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Header ---- */
.header {
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ---- Main ---- */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ---- Filters ---- */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  margin-bottom: 16px;
}

.filter-search {
  flex: 1;
  min-width: 180px;
}

.filter-select {
  min-width: 140px;
}

.filter-search,
.filter-select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #111;
  outline: none;
  transition: border-color 0.15s;
}

.filter-search:focus,
.filter-select:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79,70,229,0.08);
}

/* ---- Toolbar (stats + view toggle) ---- */
.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ---- Stats ---- */
.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: #111;
}

.stat-label {
  font-size: 11px;
  color: #888;
}

/* ---- View Toggle ---- */
.view-toggle {
  display: flex;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-start;
}

.view-btn {
  padding: 7px 18px;
  border: none;
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: #6b7280;
  transition: background 0.12s, color 0.12s;
}

.view-btn:not(:last-child) {
  border-right: 1px solid #e5e7eb;
}

.view-btn.active {
  background: #4f46e5;
  color: #fff;
  font-weight: 600;
}

/* ---- Task List ---- */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: #bbb;
  font-size: 14px;
}

/* ---- Task Item ---- */
.task-item {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-left: 3px solid transparent;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: box-shadow 0.15s;
}

.task-item:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}

.task-item.priority-high   { border-left-color: #ef4444; }
.task-item.priority-medium { border-left-color: #f59e0b; }
.task-item.priority-low    { border-left-color: #22c55e; }

.task-item.status-done {
  opacity: 0.55;
}

.task-item.status-done .task-title {
  text-decoration: line-through;
  color: #999;
}

.task-check {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #4f46e5;
}

.task-content {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  word-break: break-word;
}

.task-description {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
  word-break: break-word;
  white-space: pre-wrap;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  line-height: 1.6;
  letter-spacing: 0.2px;
}

.badge-priority-high   { background: #fee2e2; color: #dc2626; }
.badge-priority-medium { background: #fef3c7; color: #b45309; }
.badge-priority-low    { background: #dcfce7; color: #16a34a; }

.badge-status-todo        { background: #f3f4f6; color: #6b7280; }
.badge-status-in-progress { background: #dbeafe; color: #1d4ed8; }
.badge-status-done        { background: #d1fae5; color: #059669; }

.badge-category  { background: #ede9fe; color: #6d28d9; }
.badge-tag       { background: #f3f4f6; color: #4b5563; font-weight: 400; }
.badge-recurring { background: #e0e7ff; color: #4338ca; }

/* ---- Due Date ---- */
.due-date {
  font-size: 12px;
  color: #999;
}

.due-date.overdue  { color: #dc2626; font-weight: 600; }
.due-date.due-soon { color: #d97706; font-weight: 600; }

/* ---- Task Actions ---- */
.task-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #bbb;
  transition: background 0.12s, color 0.12s;
}

.icon-btn:hover          { background: #f3f4f6; color: #444; }
.icon-btn.delete:hover   { background: #fee2e2; color: #dc2626; }

/* ---- Buttons ---- */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary   { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; }

.btn-secondary { background: #f3f4f6; color: #374151; }
.btn-secondary:hover { background: #e5e7eb; }

.btn-ghost {
  background: transparent;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}
.btn-ghost:hover { background: #f3f4f6; }

/* ---- Calendar ---- */
.calendar-section {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e5e5;
}

.calendar-month-label {
  font-size: 15px;
  font-weight: 700;
}

.cal-nav-btn {
  font-size: 22px;
  width: 32px;
  height: 32px;
  color: #555;
}

.calendar-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f9fafb;
  border-bottom: 1px solid #e5e5e5;
}

.calendar-dow span {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  padding: 8px 0;
}

.calendar-dow span:first-child { color: #ef4444; }
.calendar-dow span:last-child  { color: #3b82f6; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-left: 1px solid #e5e5e5;
  width: 100%;
  table-layout: fixed;
}

.cal-cell {
  min-height: 130px;
  padding: 6px 5px;
  border-right: 1px solid #e5e5e5;
  border-bottom: 1px solid #e5e5e5;
  min-width: 0;
  overflow: hidden;
}

.cal-cell-empty { background: #fafafa; }
.cal-cell-today { background: #faf5ff; }

.cal-day-number {
  font-size: 13px;
  font-weight: 500;
  color: #9ca3af;
  margin-bottom: 4px;
  line-height: 1;
}

.cal-day-today {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #4f46e5;
  color: #fff;
  border-radius: 50%;
  font-weight: 700;
  font-size: 12px;
}

.cal-task {
  font-size: 11px;
  padding: 3px 5px;
  border-radius: 3px;
  margin-bottom: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.1s;
  display: block;
  max-width: 100%;
}

.cal-task:hover      { opacity: 0.7; }
.cal-task-done       { opacity: 0.4; text-decoration: line-through; }

.priority-dot-high   { background: #fee2e2; color: #dc2626; }
.priority-dot-medium { background: #fef3c7; color: #b45309; }
.priority-dot-low    { background: #dcfce7; color: #16a34a; }

.cal-more {
  font-size: 10px;
  color: #9ca3af;
  padding: 1px 4px;
}

.data-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.btn-sm {
  padding: 7px 18px;
  font-size: 13px;
}

@media (max-width: 600px) {
  .btn.btn-sm {
    padding: 7px 18px;
    font-size: 13px;
  }
}

/* ---- Recurring form section ---- */
.recurring-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}

.recurring-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: #4f46e5;
}

.recurrence-options {
  display: none;
  padding: 12px;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 6px;
  margin-top: -8px;
  margin-bottom: 14px;
}

.recurrence-options.open { display: block; }

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-sm { max-width: 380px; }

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: #f3f4f6;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  line-height: 1;
}

.modal-close:hover { background: #e5e7eb; }

/* ---- Form ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group { flex: 1; }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

.required { color: #ef4444; }

.form-hint {
  font-weight: 400;
  color: #9ca3af;
  font-size: 11px;
}

.form-input,
.form-textarea {
  padding: 8px 11px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  color: #111;
}

.form-input:focus,
.form-textarea:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79,70,229,0.08);
}

.form-textarea { resize: vertical; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

/* ---- Category List ---- */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 6px;
  font-size: 13px;
}

/* ---- Footer ---- */
.footer {
  color: rgba(0, 0, 0, 0.6);
  text-align: center;
  padding: 20px 24px;
  font-size: 13px;
  letter-spacing: 0.2px;
  margin-top: 40px;
}

.footer p {
  opacity: 0.8;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .header {
    padding: 12px 14px;
  }
  .header-title { font-size: 16px; }

  .main { padding: 14px 10px; }

  /* フィルター：横スクロールで1行に */
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    margin-bottom: 12px;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter-search { min-width: 150px; flex-shrink: 0; }
  .filter-select { min-width: 115px; flex-shrink: 0; width: auto; }

  /* ツールバー */
  .toolbar { margin-bottom: 12px; }
  .stat-card { padding: 8px 12px; min-width: 60px; }
  .stat-value { font-size: 18px; }

  /* カレンダー */
  .cal-cell {
    min-height: 110px;
    padding: 4px 3px;
  }
  .cal-day-number { font-size: 12px; }
  .cal-day-today { width: 22px; height: 22px; font-size: 11px; }
  .cal-task { font-size: 10px; padding: 2px 4px; margin-bottom: 2px; }
  .cal-nav-btn { font-size: 26px; width: 40px; height: 40px; }
  .calendar-month-label { font-size: 16px; }
  .calendar-header { padding: 14px 16px; }
  .calendar-dow span { font-size: 11px; padding: 10px 0; }

  /* フォーム */
  .form-row { flex-direction: column; }

  /* モーダル */
  .modal { padding: 20px 16px; }
  .btn { padding: 10px 14px; font-size: 14px; }
}
