/* ===== Reset & Variables ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f5f5f7;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-hover: #313244;
  --sidebar-active: #45475a;
  --primary: #89b4fa;
  --primary-dark: #74c7ec;
  --accent: #a6e3a1;
  --danger: #f38ba8;
  --danger-hover: #eba0ac;
  --warning: #fab387;
  --text: #1e1e2e;
  --text-secondary: #585b70;
  --card-bg: #ffffff;
  --border: #e0e0e6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== Layout ===== */
#app {
  display: flex;
  height: 100vh;
}

/* ===== Sidebar ===== */
#sidebar {
  width: 270px;
  min-width: 270px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 24px 20px 16px;
}

.sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

#sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 20px;
}

#sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
#sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sidebar-active);
  border-radius: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: none;
  color: var(--sidebar-text);
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--sidebar-hover);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-divider {
  height: 1px;
  background: var(--sidebar-active);
  margin: 12px 6px;
}

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #7f849c;
}

/* List tree items */
.list-tree-item {
  display: flex;
  align-items: center;
  width: 100%;
  position: relative;
}

.list-tree-item .nav-item {
  flex: 1;
  min-width: 0;
}

.list-tree-item .nav-item span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-tree-children {
  padding-left: 18px;
}

.list-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #7f849c;
  cursor: pointer;
  font-size: 10px;
  flex-shrink: 0;
  border-radius: 3px;
  transition: background var(--transition), transform var(--transition);
}

.list-toggle:hover {
  background: var(--sidebar-hover);
}

.list-toggle.expanded {
  transform: rotate(90deg);
}

.task-count-badge {
  font-size: 11px;
  background: var(--sidebar-active);
  color: #7f849c;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

/* ===== Buttons ===== */
.icon-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 18px;
  transition: background var(--transition);
}

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

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: var(--sidebar-bg);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #d0d0d6;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* ===== Main Content ===== */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
}

#main-content::-webkit-scrollbar {
  width: 6px;
}
#main-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

.view-header {
  margin-bottom: 24px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.view-header h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
  outline: none;
  border-bottom: 2px solid transparent;
  transition: border-color var(--transition);
  min-width: 60px;
}

.view-header h2[contenteditable="true"]:focus {
  border-color: var(--primary);
}

.view-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

.list-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* Sub-lists bar */
.sublists-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.sublists-bar:empty {
  display: none;
}

.sublist-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.sublist-chip:hover {
  border-color: var(--primary);
  background: #f0f4ff;
}

.sublist-chip .chip-count {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ===== Add Task Bar ===== */
.add-task-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.add-task-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color var(--transition);
  outline: none;
}

.add-task-bar input:focus {
  border-color: var(--primary);
}

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

/* ===== Task Item ===== */
.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.task-item:hover {
  box-shadow: var(--shadow);
  border-color: #c8c8d0;
}

/* Checkbox */
.task-checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid #c0c0cc;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.task-checkbox:hover {
  border-color: var(--accent);
  background: rgba(166, 227, 161, 0.1);
}

.task-checkbox.checked {
  border-color: var(--accent);
  background: var(--accent);
  animation: checkPop 0.4s ease;
}

.task-checkbox.checked::after {
  content: '\2713';
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

@keyframes checkPop {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.3); }
  60%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

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

.task-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.3s ease;
}

.task-item.completing .task-title {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 3px;
}

.task-deadline {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.task-deadline.overdue {
  color: var(--danger);
  font-weight: 600;
}

.task-deadline.today {
  color: var(--warning);
  font-weight: 600;
}

.task-deadline.soon {
  color: var(--primary);
}

.task-notes-indicator {
  font-size: 12px;
  color: var(--text-secondary);
}

.task-list-tag {
  font-size: 11px;
  background: #eef2ff;
  color: #6366f1;
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Completion animation */
.task-item.completing {
  animation: slideComplete 0.5s ease forwards;
}

@keyframes slideComplete {
  0%   { opacity: 1; transform: translateX(0); }
  70%  { opacity: 0.6; transform: translateX(30px); }
  100% { opacity: 0; transform: translateX(60px); max-height: 0; padding: 0; margin: 0; border: none; overflow: hidden; }
}

.task-item.uncompleting {
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  display: none;
}

.empty-state.visible {
  display: block;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-hint {
  font-size: 13px;
  margin-top: 6px;
  opacity: 0.7;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--card-bg);
  border-radius: 14px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.25s ease;
}

.modal-small {
  width: 380px;
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.modal-close-btn {
  font-size: 22px;
  color: var(--text-secondary);
}

.modal-close-btn:hover {
  color: var(--text);
  background: var(--bg);
}

.modal-body {
  padding: 22px;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  margin-top: 16px;
}

.form-label:first-child {
  margin-top: 0;
}

.form-input, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus, .form-textarea:focus {
  border-color: var(--primary);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* ===== New List Input ===== */
.new-list-input-wrap {
  padding: 2px 6px;
}

.new-list-input {
  width: 100%;
  padding: 7px 10px;
  background: var(--sidebar-hover);
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  outline: none;
}

.new-list-input::placeholder {
  color: #7f849c;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar {
    width: 240px;
    min-width: 240px;
  }
  #main-content {
    padding: 20px;
  }
}

@media (max-width: 600px) {
  html, body {
    overflow: auto;
  }
  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }
  #sidebar {
    width: 100%;
    min-width: 100%;
    max-height: none;
    overflow-y: visible;
  }
  #sidebar-nav {
    max-height: 35vh;
    overflow-y: auto;
  }
  #main-content {
    padding: 16px;
    overflow-y: visible;
    flex: 1;
  }
}

/* ===== Date group headers (Upcoming view) ===== */
.date-group-header {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 16px 0 6px;
}

.date-group-header:first-child {
  padding-top: 0;
}

.date-group-header.overdue-header {
  color: var(--danger);
}

.date-group-header.today-header {
  color: var(--warning);
}

/* ===== Group-by select ===== */
.form-select-small {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.form-select-small:focus {
  border-color: var(--primary);
}

/* ===== Frequency group headers ===== */
.freq-group-header {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 18px 0 6px;
}

.freq-group-header:first-child {
  padding-top: 0;
}

/* ===== Recurrence badge ===== */
.task-recurrence-badge {
  font-size: 11px;
  background: #f0fdf4;
  color: #16a34a;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}
