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

:root {
  --today: #ef4444;
  --tomorrow: #f97316;
  --week: #3b82f6;
  --next-week: #10b981;
  --backlog: #8b5cf6;
  --shows-recipes: #ec4899;
  --ai-tasks: #06b6d4;
  --toys-to-buy: #eab308;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --selected-bg: #eff6ff;
  --chat-width: 360px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #1a1d24;
  --card-bg: #1f232b;
  --border: #2d323c;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --selected-bg: #1e2a44;
  color-scheme: dark;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}
.logo { font-size: 1.2rem; font-weight: 700; white-space: nowrap; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; gap: 8px; align-items: center; }

/* Search */
.search-input {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.875rem;
  width: 200px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: #2563eb; }
.search-input::placeholder { color: var(--muted); }

mark {
  background: #fde68a;
  color: #1f2937;
  border-radius: 2px;
  padding: 0 1px;
}
[data-theme="dark"] mark { background: #b45309; color: #fff; }

/* Hide drag handles while searching so a filtered reorder can't corrupt order */
.board.searching .drag-handle { display: none; }
.board.searching .task-card { padding-left: 12px; }

/* List toggle pill */
.list-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
.list-btn {
  border: none;
  background: transparent;
  border-radius: 16px;
  padding: 5px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.list-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg); }

/* Layout */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Board */
.board {
  display: flex;
  gap: 16px;
  padding: 20px;
  overflow-x: auto;
  flex: 1;
  align-items: flex-start;
}

.column {
  background: var(--surface);
  border-radius: 12px;
  min-width: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  border: 1px solid var(--border);
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 3px solid var(--border);
}
.column[data-category="today"] .column-header { border-bottom-color: var(--today); }
.column[data-category="tomorrow"] .column-header { border-bottom-color: var(--tomorrow); }
.column[data-category="week"] .column-header { border-bottom-color: var(--week); }
.column[data-category="next_week"] .column-header { border-bottom-color: var(--next-week); }
.column[data-category="backlog"] .column-header { border-bottom-color: var(--backlog); }
.column[data-category="shows_recipes"] .column-header { border-bottom-color: var(--shows-recipes); }
.column[data-category="ai_tasks"] .column-header { border-bottom-color: var(--ai-tasks); }
.column[data-category="toys_to_buy"] .column-header { border-bottom-color: var(--toys-to-buy); }

.column-header h2 { font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

.add-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  transition: all 0.15s;
  line-height: 1;
}
.add-btn:hover { background: var(--bg); border-color: #999; color: var(--text); }

.column-body {
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 60px;
}

/* Task cards */
.task-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 40px 10px 36px;
  margin-bottom: 8px;
  user-select: none;
  touch-action: pan-y;
  transition: box-shadow 0.15s, transform 0.1s;
  position: relative;
}

.drag-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  color: var(--border);
  font-size: 0.85rem;
  border-right: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
}
.drag-handle:hover { color: var(--muted); background: var(--bg); }
.task-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.task-card.drag-ghost { opacity: 0.4; }
.task-card.sortable-chosen { box-shadow: 0 4px 16px rgba(0,0,0,0.2); transform: rotate(1deg); }

.task-title { font-size: 0.9rem; font-weight: 500; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.task-card.tapped .task-title { -webkit-line-clamp: unset; overflow: visible; }
.task-desc { font-size: 0.78rem; color: var(--muted); }
.task-link { color: var(--week); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.task-link:hover { text-decoration-thickness: 2px; }

.task-actions {
  display: flex;
  position: absolute;
  top: 6px; right: 6px;
  gap: 4px;
}
.task-action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 26px; height: 26px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.task-action-btn:hover { background: var(--bg); }

/* Delete: always visible green SVG checkbox */
.task-action-btn[data-action="delete"] {
  width: 24px; height: 24px;
  border: none;
  background: none;
  color: #16a34a;
}
.task-action-btn[data-action="delete"]:hover { color: #15803d; background: #f0fdf4; border-radius: 4px; }
[data-theme="dark"] .task-action-btn[data-action="delete"]:hover { color: #4ade80; background: #14271c; }

/* Edit: hidden until card is tapped */
.task-action-btn[data-action="edit"] {
  display: none;
  color: var(--muted);
}
.task-card.tapped .task-action-btn[data-action="edit"] { display: flex; }

/* Bulk select mode */
.select-check {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 28px;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: transparent;
  border-right: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
}
.board.select-mode .select-check { display: flex; }
.board.select-mode .drag-handle { display: none; }
.board.select-mode .task-actions { display: none; }
.board.select-mode .task-card { cursor: pointer; }
.board.select-mode .add-btn { display: none; }

.task-card.selected { border-color: #2563eb; background: var(--selected-bg); }
.task-card.selected .select-check { background: #2563eb; color: white; border-right-color: #2563eb; }

.select-all-btn {
  display: none;
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  line-height: 1;
}
.select-all-btn:hover { background: var(--bg); border-color: #2563eb; color: #2563eb; }
.board.select-mode .select-all-btn { display: flex; }
#select-toggle-btn.active { background: #2563eb; color: white; border-color: #2563eb; }

/* Bulk action bar */
.bulk-bar {
  position: fixed;
  bottom: -90px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: bottom 0.25s ease;
  z-index: 1000;
}
.bulk-bar.show { bottom: 24px; }
#bulk-count { font-weight: 600; white-space: nowrap; }
.bulk-move-to { color: rgba(255,255,255,0.7); }
#bulk-category, #bulk-list {
  border: 1px solid rgba(255,255,255,0.3);
  background: #374151;
  color: white;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.88rem;
  cursor: pointer;
  outline: none;
}
#bulk-move-btn:disabled { background: #93c5fd; cursor: not-allowed; }

/* Delete toast */
.delete-toast {
  position: fixed;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  border-radius: 10px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  transition: bottom 0.25s ease;
  z-index: 1000;
  min-width: 280px;
  overflow: hidden;
}
.delete-toast.show { bottom: 24px; }
#toast-undo-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
#toast-undo-btn:hover { background: rgba(255,255,255,0.1); }
.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: #10b981;
  width: 100%;
  transform-origin: left;
  transition: transform linear;
}

/* Chat panel */
.chat-panel {
  position: fixed;
  top: 57px;
  right: 0;
  bottom: 0;
  width: var(--chat-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 20;
}
.chat-panel.open { transform: translateX(0); }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble.user {
  background: #2563eb;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  background: var(--bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-bubble.typing { color: var(--muted); font-style: italic; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  outline: none;
}
.chat-input-row input:focus { border-color: #2563eb; }
#chat-send-btn {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 1rem;
}
#chat-send-btn:hover { background: #1d4ed8; }
#chat-send-btn:disabled { background: #93c5fd; cursor: not-allowed; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  margin: auto;
  flex-shrink: 0;
}
.modal h3 { margin-bottom: 16px; font-size: 1.1rem; }
.modal input, .modal textarea, .modal select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 12px;
  font-family: inherit;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: #2563eb; }
.modal-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-primary { background: #2563eb; color: white; border: none; border-radius: 8px; padding: 8px 20px; cursor: pointer; font-size: 0.9rem; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 20px; cursor: pointer; font-size: 0.9rem; }
.btn-secondary:hover { background: var(--bg); }

/* Responsive */
@media (max-width: 768px) {
  html { overflow-x: hidden; }
  body { overflow-y: auto; overflow-x: hidden; }
  header { flex-wrap: wrap; gap: 8px; }
  .header-left { flex: 1 1 100%; order: 3; }
  .search-input { width: 100%; }
  .app-layout { overflow: visible; }
  .board {
    flex-direction: column;
    overflow: hidden;
    align-items: stretch;
  }
  .board { padding: 16px 26px; }
  .column { min-width: unset; max-height: none; width: 100%; }
  .chat-panel {
    top: 0;
    width: 100%;
    z-index: 50;
  }
}

/* Planning chips: due date, priority, estimate, repeat, stale */
.task-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  font-size: 0.7rem;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.chip-overdue { background: var(--today); border-color: var(--today); color: #fff; font-weight: 600; }
.chip-due-today { border-color: var(--tomorrow); color: var(--tomorrow); font-weight: 600; }
.chip-due { color: var(--text); }
.chip-high { border-color: var(--today); color: var(--today); font-weight: 600; }
.chip-stale { border-style: dashed; }
.task-card.high { box-shadow: inset 3px 0 0 var(--today); }

/* Edit dialog: two-up planning fields, delete on the left */
.modal-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 12px; }
.btn-danger {
  margin-right: auto;
  background: none;
  color: var(--today);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-danger:hover { border-color: var(--today); }

/* Done panel */
.done-modal { max-width: 480px; }
.done-list { max-height: 60vh; overflow-y: auto; margin-bottom: 16px; }
.done-day {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 12px 0 6px;
}
.done-day:first-child { margin-top: 0; }
.done-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.done-text { flex: 1; min-width: 0; }
.done-title { font-size: 0.9rem; text-decoration: line-through; color: var(--muted); overflow-wrap: anywhere; }
.done-where { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.done-restore { padding: 6px 12px; flex-shrink: 0; }
.done-empty { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }
