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

body {
  font-family: 'Segoe UI', sans-serif;
  background: #f0f2f5;
  display: flex;
  justify-content: center;
  padding: 48px 16px;
  min-height: 100vh;
}

.container {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 520px;
  padding: 32px;
  height: fit-content;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1a1a2e;
}

.history-btn {
  padding: 6px 14px;
  background: #f0eeff;
  color: #6c63ff;
  border: 1.5px solid #d8d4ff;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.history-btn:hover { background: #e0deff; }

/* ── Top input row ── */
.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  align-items: center;
}

.select-wrapper {
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
}

.type-select {
  padding: 9px 28px 9px 10px;
  border: 2px solid #d0d0d0;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  background: #e8e8e8;
  color: #333;
  transition: border-color 0.2s, background 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.type-select:focus {
  border-color: #6c63ff;
  background: #e0dff8;
}

.select-arrow {
  position: absolute;
  right: 8px;
  pointer-events: none;
  color: #666;
  display: flex;
  align-items: center;
  transition: transform 0.2s;
}

.select-wrapper.open .select-arrow { transform: rotate(180deg); }

.input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-row input:focus { border-color: #6c63ff; }

.add-btn {
  padding: 10px 18px;
  background: #6c63ff;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.add-btn:hover { background: #574fd6; }

/* ── Drag handle ── */
.drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: #d0d0d0;
  display: flex;
  align-items: center;
  padding: 0 3px;
  transition: color 0.15s;
  user-select: none;
}

.drag-handle:hover { color: #999; }
.drag-handle:active { cursor: grabbing; }

/* ── Drag states ── */
.dragging { opacity: 0.3 !important; }

.drop-line {
  height: 2px;
  background: #6c63ff;
  border-radius: 2px;
  pointer-events: none;
  flex-shrink: 0;
}

/* ── Item list ── */
#itemList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Task item ── */
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid #ececec;
  border-radius: 8px;
  background: #fafafa;
  transition: opacity 0.2s;
}

.task-item.done { opacity: 0.4; }

.check-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #bbb;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s;
  padding: 0;
}

.check-btn svg { display: none; width: 14px; height: 14px; }

.task-item.done .check-btn { border-color: #6c63ff; background: #6c63ff; }
.task-item.done .check-btn svg { display: block; }

.task-text {
  flex: 1;
  font-size: 0.95rem;
  color: #333;
  word-break: break-word;
}

.task-item.done .task-text { text-decoration: line-through; }


/* ── Delete confirmation overlay ── */
.task-item  { position: relative; }
.list-header { position: relative; }

.confirm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 235, 235, 0.97);
  border-radius: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  z-index: 2;
}

.confirm-overlay .confirm-msg {
  flex: 1;
  font-size: 0.85rem;
  color: #c0392b;
  font-weight: 500;
}

.confirm-yes-btn {
  padding: 4px 12px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.confirm-yes-btn:hover { background: #c0392b; }

.confirm-no-btn {
  padding: 4px 12px;
  background: #ececec;
  color: #555;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.confirm-no-btn:hover { background: #ddd; }

/* ── Task date tooltip ── */
.task-date-tip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 40, 0.82);
  color: #fff;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}

.task-date-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: rgba(30, 30, 40, 0.82);
}

.task-item:hover .task-date-tip { opacity: 1; }

/* ── Due date ── */
.task-due {
  display: none;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}

.task-due[data-status="future"]  { background: #ede9ff; color: #6c63ff; }
.task-due[data-status="soon"]    { background: #fff3cd; color: #c47d00; }
.task-due[data-status="today"]   { background: #fef3c7; color: #d97706; font-weight: 600; }
.task-due[data-status="overdue"] { background: #fee2e2; color: #dc2626; font-weight: 600; }

.due-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  display: flex;
  align-items: center;
  padding: 0 3px;
  border-radius: 4px;
  transition: color 0.15s;
}

.due-btn:hover { color: #6c63ff; }

.task-date-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
  border: none;
  padding: 0;
}

/* ── Date picker popup ── */
.dp-popup {
  background: #fff;
  border: 1.5px solid #d8d4ff;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.14);
  padding: 14px;
  width: 232px;
  z-index: 9999;
  user-select: none;
}

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

.dp-nav {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: #6c63ff;
  padding: 2px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.15s;
}
.dp-nav:hover { background: #f0eeff; }

.dp-month-lbl {
  font-size: 0.88rem;
  font-weight: 700;
  color: #2d2b55;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 10px;
}

.dp-day-name {
  text-align: center;
  font-size: 0.68rem;
  color: #aaa;
  padding: 3px 0;
}

.dp-day {
  text-align: center;
  font-size: 0.8rem;
  padding: 5px 0;
  border-radius: 6px;
  cursor: pointer;
  color: #333;
  transition: background 0.1s;
}
.dp-day:hover { background: #f0eeff; }
.dp-day.dp-sun { color: #e74c3c; }
.dp-day.dp-sat { color: #2196f3; }
.dp-day.dp-today { font-weight: 700; }
.dp-day.dp-sel   { background: #6c63ff !important; color: #fff !important; border-radius: 6px; }

.dp-time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #f0f0f0;
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 10px;
}

.dp-time-lbl { font-size: 0.82rem; color: #666; }

.dp-time-input {
  flex: 1;
  padding: 5px 8px;
  border: 1.5px solid #e0e0e0;
  border-radius: 6px;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}
.dp-time-input:focus { border-color: #6c63ff; }

.dp-actions { display: flex; gap: 6px; }

.dp-clear {
  flex: 1;
  padding: 7px;
  background: none;
  border: 1.5px solid #eee;
  border-radius: 7px;
  font-size: 0.8rem;
  color: #aaa;
  cursor: pointer;
  transition: all 0.15s;
}
.dp-clear:hover { border-color: #e74c3c; color: #e74c3c; }

.dp-set {
  flex: 2;
  padding: 7px;
  background: #6c63ff;
  border: none;
  border-radius: 7px;
  font-size: 0.8rem;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
  font-weight: 600;
}
.dp-set:hover { background: #574fd6; }

/* ── Pin button ── */
.pin-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #d0d0d0;
  display: flex;
  align-items: center;
  padding: 0 3px;
  border-radius: 4px;
  transition: color 0.15s, transform 0.15s;
}

.pin-btn:hover { color: #6c63ff; }

.task-item.pinned .pin-btn,
.list-item.pinned .pin-btn {
  color: #fff;
  background: #6c63ff;
  border-radius: 50%;
  padding: 3px;
}

.task-item.pinned,
.list-item.pinned {
  border-color: #c4bff5;
  background: #f5f3ff;
}

/* ── Delete button ── */
.delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.2s;
}

.delete-btn:hover { color: #e74c3c; }

/* ── Task inline edit ── */
.task-edit-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: inherit;
  color: inherit;
  font-family: inherit;
  padding: 0;
  border-bottom: 1.5px solid #6c63ff;
}

/* ── Sub-task style overrides ── */
.sub-task-list .task-item {
  padding: 9px 12px;
  border-radius: 7px;
  background: #fff;
}

/* ── Inline add form ── */
.inline-add-form {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
}

.inline-add-form input {
  flex: 1;
  padding: 7px 11px;
  border: 1.5px solid #6c63ff;
  border-radius: 7px;
  font-size: 0.88rem;
  outline: none;
  background: #fff;
}

.inline-confirm-btn {
  padding: 7px 13px;
  background: #9b8ff7;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.inline-confirm-btn:hover { background: #7b6de6; }

.inline-cancel-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.inline-cancel-btn:hover { color: #e74c3c; }

/* ── List item ── */
.list-item {
  border: 1.5px solid #d8d4ff;
  border-radius: 10px;
  background: #faf9ff;
  overflow: hidden;
}

.list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}

.list-header:hover { background: #f3f0ff; }

.toggle-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.list-item.collapsed .toggle-icon { transform: rotate(-90deg); }

.list-title {
  flex: 1;
  font-size: 0.97rem;
  font-weight: 600;
  color: #3d3566;
}

.list-count {
  font-size: 0.78rem;
  color: #aaa;
  padding: 2px 7px;
  background: #ede9ff;
  border-radius: 12px;
}

.list-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 1.2rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.2s;
}

.list-delete-btn:hover { color: #e74c3c; }

.list-body {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item.collapsed .list-body { display: none; }

.sub-task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 36px;
}

.sub-task-list:empty {
  min-height: 36px;
  border: 1.5px dashed #d8d4ff;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sub-task-list:empty::after {
  content: 'タスクがありません';
  color: #d8d4ff;
  font-size: 0.82rem;
}

/* ── List footer add button ── */
.list-add-footer-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #9b8ff7;
  font-size: 0.85rem;
  padding: 4px 2px;
  text-align: left;
  width: 100%;
  transition: color 0.2s;
}

.list-add-footer-btn:hover { color: #6c63ff; }

/* ── History panel ── */
.container { position: relative; }

.history-panel {
  position: absolute;
  inset: 0;
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  padding: 32px;
}

.history-panel[hidden] { display: none; }

.history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.history-title {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1a1a2e;
}

.history-clear-btn {
  background: none;
  border: 1.5px solid #eee;
  border-radius: 6px;
  color: #aaa;
  font-size: 0.8rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.history-clear-btn:hover { color: #e74c3c; border-color: #e74c3c; }

.history-close-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: #ccc;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.history-close-btn:hover { color: #333; }

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-entry {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px 9px 14px;
  border-radius: 8px;
  background: #fafafa;
  border: 1.5px solid #f0f0f0;
  border-left-width: 3px;
}

.history-entry.add    { border-left-color: #6c63ff; }
.history-entry.delete { border-left-color: #e74c3c; }
.history-entry.done   { border-left-color: #4caf50; }
.history-entry.undone { border-left-color: #bbb; }
.history-entry.move   { border-left-color: #2196f3; }

.history-time {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: #bbb;
}

.history-text {
  flex: 1;
  font-size: 0.88rem;
  color: #444;
}

.history-empty-msg {
  text-align: center;
  color: #bbb;
  font-size: 0.9rem;
  padding: 24px 0;
}

/* ── Empty ── */
.empty {
  text-align: center;
  color: #bbb;
  font-size: 0.9rem;
  padding: 24px 0;
}

/* ── Title actions ── */
.title-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Select mode button ── */
.select-mode-btn {
  padding: 6px 14px;
  background: #f0eeff;
  color: #6c63ff;
  border: 1.5px solid #d8d4ff;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.select-mode-btn:hover { background: #e0deff; }
.container.select-mode .select-mode-btn {
  background: #6c63ff;
  color: #fff;
  border-color: #6c63ff;
}

/* ── Select bar ── */
.select-bar {
  margin-bottom: 16px;
  border: 1.5px solid #d8d4ff;
  border-radius: 10px;
  background: #f5f3ff;
  overflow: hidden;
}
.select-bar[hidden] { display: none; }

.sel-bar-main,
.sel-bar-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}
.sel-bar-confirm[hidden] { display: none; }

.sel-count {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6c63ff;
  text-align: center;
}
.sel-confirm-msg {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: #c0392b;
}

.sel-all-btn {
  padding: 5px 12px;
  background: none;
  border: 1.5px solid #d8d4ff;
  border-radius: 7px;
  font-size: 0.82rem;
  color: #6c63ff;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.sel-all-btn:hover { background: #e0deff; }

.sel-cancel-btn {
  padding: 5px 12px;
  background: none;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  font-size: 0.82rem;
  color: #888;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.sel-cancel-btn:hover { background: #eee; }

.sel-delete-btn {
  padding: 5px 14px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.sel-delete-btn:hover:not(:disabled) { background: #c0392b; }
.sel-delete-btn:disabled { background: #ddd; color: #aaa; cursor: default; }

/* ── Sel-check circle ── */
.sel-check {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #c0b8f0;
  background: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}
.select-mode .sel-check { display: flex; }

.task-item.selected .sel-check,
.list-item.selected .sel-check {
  background: #6c63ff;
  border-color: #6c63ff;
}
.task-item.selected .sel-check::after,
.list-item.selected .sel-check::after {
  content: '';
  display: block;
  width: 4px;
  height: 8px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg) translateY(-2px);
}

/* ── Select mode overrides ── */
.select-mode .drag-handle { display: none; }

.select-mode .check-btn,
.select-mode .task-due,
.select-mode .due-btn,
.select-mode .pin-btn,
.select-mode .delete-btn,
.select-mode .list-delete-btn { pointer-events: none; opacity: 0; }

.select-mode .task-item { cursor: pointer; }
.select-mode .list-header { cursor: pointer; }

.select-mode .task-item.selected { opacity: 1; background: #e8e4ff !important; }
.select-mode .list-item.selected > .list-header { background: #e8e4ff; }
.list-item.selected { border-color: #b8b0f5; }

/* ── スマホ対応 ── */
@media (max-width: 540px) {
  body { padding: 16px 10px; }

  .container { padding: 20px 16px; border-radius: 10px; }

  h1 { font-size: 1.3rem; }

  .history-btn,
  .select-mode-btn { padding: 5px 10px; font-size: 0.8rem; }

  /* 入力行 */
  .input-row { gap: 6px; }
  .input-row input { min-width: 0; }
  .add-btn { padding: 10px 12px; font-size: 0.9rem; white-space: nowrap; }
  .type-select { padding: 9px 24px 9px 8px; font-size: 0.82rem; }

  /* タスクアイテム */
  .task-item { padding: 10px 10px; gap: 8px; }
  .check-btn { width: 28px; height: 28px; }

  /* ドラッグハンドルをスマホ向けに大きく */
  .drag-handle { padding: 0 6px; }

  /* リスト */
  .list-header { padding: 10px 10px; gap: 8px; }
  .list-body { padding: 0 10px 10px; }

  /* 選択バー */
  .sel-bar-main,
  .sel-bar-confirm { gap: 6px; padding: 8px 10px; }
  .sel-all-btn,
  .sel-cancel-btn,
  .sel-delete-btn { padding: 6px 10px; font-size: 0.8rem; }
  .sel-count { font-size: 0.82rem; }

  /* 日付ピッカー */
  .dp-popup { width: 210px; }
}
