/* ===== CSS Variables & Themes ===== */
:root {
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-light: #60a5fa;
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-hover: #f0f1f3;
  --bg-active: #e8eef5;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --sidebar-bg: #fafbfc;
  --danger: #ef4444;
  --green: #10b981;
  --orange: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 260px;
  --detail-w: 400px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-hover: #1e2a4a;
  --bg-active: #233456;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2d3f5f;
  --sidebar-bg: #16213e;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
input, textarea, select, button { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  outline: none;
  transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
.hidden { display: none !important; }

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

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: margin-left var(--transition);
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
}
.logo i { margin-right: 6px; }
#theme-toggle { color: var(--text-secondary); font-size: 16px; padding: 4px; }

.quick-add-bar {
  margin: 4px 12px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.quick-add-bar > i { color: var(--blue); font-size: 14px; }
.quick-add-bar input {
  border: none;
  background: none;
  padding: 0;
  flex: 1;
}

/* Nav */
.nav-section { padding: 0 8px; }
.nav-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.nav-section-header button {
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}
.nav-section-header button:hover { background: var(--bg-hover); color: var(--blue); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  margin: 1px 0;
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--bg-active); color: var(--blue); font-weight: 600; }
.nav-item i { width: 16px; text-align: center; font-size: 13px; }
.nav-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-hover);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active .count { background: var(--blue); color: white; }
.nav-item .list-color-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.nav-item .delete-list-btn {
  opacity: 0;
  color: var(--danger);
  font-size: 11px;
  padding: 2px;
  transition: opacity var(--transition);
}
.nav-item:hover .delete-list-btn { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== Main ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 20px; font-weight: 700; }
.current-date { font-size: 12px; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}
.search-box i { color: var(--text-muted); font-size: 13px; }
.search-box input {
  border: none;
  background: none;
  width: 200px;
  padding: 0;
}

/* Add Task Bar */
.add-task-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
}
.checkbox-placeholder { width: 20px; height: 20px; }
.add-task-bar input {
  flex: 1;
  border: 1px dashed var(--border);
  background: var(--bg-secondary);
  padding: 8px 12px;
}
.btn-primary {
  background: var(--blue);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13px;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger {
  background: var(--danger);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
}
.add-task-options { color: var(--text-muted); font-size: 16px; padding: 4px 8px; border-radius: var(--radius-sm); }
.add-task-options:hover { background: var(--bg-hover); }

/* Expandable add task panel */
.add-task-panel {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.atp-row { display: grid; grid-template-columns: auto 1fr auto 1fr auto 1fr; gap: 8px; align-items: center; }
.atp-row label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.atp-row select, .atp-row input, .atp-row textarea { padding: 4px 8px; font-size: 12px; }
.atp-row textarea { grid-column: 1 / -1; resize: vertical; }

/* Dropdown */
.dropdown {
  position: absolute;
  top: 60px; right: 24px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  min-width: 180px;
  overflow: hidden;
}
.dropdown-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.active { color: var(--blue); font-weight: 600; }

/* Priority dots */
.pri-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pri-high { background: var(--danger); }
.pri-med { background: var(--orange); }
.pri-low { background: var(--blue); }

/* ===== Task List ===== */
.task-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 24px;
}
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.task-item:hover { background: var(--bg-hover); }
.task-item.completed { opacity: 0.5; }
.task-item.completed .task-title { text-decoration: line-through; }

.task-checkbox {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.task-checkbox:hover { border-color: var(--blue); }
.task-item.completed .task-checkbox {
  background: var(--green);
  border-color: var(--green);
}
.task-item.completed .task-checkbox::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  color: white;
  font-size: 10px;
}

.task-content { flex: 1; min-width: 0; }
.task-title {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-muted);
}
.task-meta .tag-badge {
  background: var(--bg-secondary);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
}
.task-meta .date-badge { color: var(--text-secondary); }
.task-meta .date-badge.overdue { color: var(--danger); font-weight: 600; }
.task-meta .date-badge.today { color: var(--green); font-weight: 600; }
.task-meta .date-badge.tomorrow { color: var(--orange); }
.task-priority-flag {
  width: 16px;
  font-size: 12px;
  flex-shrink: 0;
  text-align: center;
}
.flag-high { color: var(--danger); }
.flag-med { color: var(--orange); }
.flag-low { color: var(--blue); }
.task-list-name {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.no-tasks {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.no-tasks i { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
.no-tasks p { font-size: 14px; }

/* ===== Detail Panel ===== */
.detail-panel {
  width: var(--detail-w);
  min-width: var(--detail-w);
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.detail-header {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.detail-body { padding: 16px; }
.detail-title-row { margin-bottom: 16px; }
.detail-title {
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 4px 0;
}
.detail-title:focus { border-bottom-color: var(--blue); }
.detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row i { width: 20px; color: var(--text-muted); text-align: center; }
.detail-row label { font-size: 12px; color: var(--text-muted); min-width: 50px; }
.detail-row input, .detail-row select { flex: 1; padding: 4px 8px; font-size: 13px; }
.text-btn { color: var(--blue); font-size: 12px; padding: 2px 6px; }
.detail-section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.detail-section label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.detail-section textarea, .detail-section select { width: 100%; }
.detail-footer { padding-top: 16px; }

/* Subtasks */
#detail-subtasks { margin-bottom: 8px; }
.subtask-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.subtask-checkbox {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.subtask-checkbox:hover { border-color: var(--blue); }
.subtask-item.done .subtask-checkbox {
  background: var(--green);
  border-color: var(--green);
}
.subtask-item.done .subtask-checkbox::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  color: white;
  font-size: 8px;
}
.subtask-item.done .subtask-title { text-decoration: line-through; opacity: 0.5; }
.subtask-title {
  flex: 1;
  border: none;
  background: none;
  padding: 2px 0;
}
.subtask-title:focus { border-bottom: 1px solid var(--blue); }
.subtask-delete { color: var(--text-muted); font-size: 12px; opacity: 0; transition: opacity var(--transition); }
.subtask-item:hover .subtask-delete { opacity: 1; }
.subtask-delete:hover { color: var(--danger); }
.add-subtask-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-subtask-bar input {
  flex: 1;
  border: 1px dashed var(--border);
  background: var(--bg-secondary);
  padding: 4px 8px;
}
.add-subtask-bar button {
  color: var(--blue);
  padding: 4px 8px;
}

/* ===== Pomodoro Modal ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  padding: 28px;
  max-width: 420px;
  width: 90%;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.pomo-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.pomo-header h2 { font-size: 22px; color: var(--blue); }
.pomo-tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--bg-secondary); border-radius: var(--radius); padding: 4px; }
.pomo-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.pomo-tab.active { background: var(--blue); color: white; }
.pomo-timer-display { text-align: center; margin-bottom: 24px; }
.pomo-time {
  font-size: 72px;
  font-weight: 300;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
}
.pomo-status { font-size: 14px; color: var(--text-muted); margin-top: 8px; }
.pomo-sessions { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.pomo-controls { display: flex; gap: 8px; justify-content: center; margin-bottom: 20px; }
.pomo-btn { padding: 10px 20px; font-size: 13px; }
.pomo-settings { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--border); }
.pomo-settings label { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.pomo-settings input { width: 40px; padding: 2px 6px; font-size: 12px; text-align: center; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Auth Screen ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  animation: fadeIn 0.4s ease;
}
[data-theme="dark"] .auth-screen {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.auth-card {
  background: var(--bg);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 40px 36px;
  width: 380px;
  max-width: 90vw;
  animation: cardSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardSlideIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.auth-logo i { font-size: 28px; color: var(--blue); }
.auth-logo h1 { font-size: 24px; font-weight: 800; color: var(--text); }

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}
.auth-tab.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-field {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  transition: border-color 0.2s ease;
}
.auth-field:focus-within { border-color: var(--blue); }
.auth-field i { color: var(--text-muted); font-size: 14px; width: 16px; text-align: center; }
.auth-field input {
  border: none;
  background: none;
  flex: 1;
  padding: 0;
  font-size: 14px;
}
.auth-field input:focus { outline: none; }

.auth-submit {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  margin-top: 4px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}
.auth-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4); }
.auth-submit:active { transform: translateY(0); }

.auth-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}
[data-theme="dark"] .auth-error { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.3); }

.auth-loading {
  text-align: center;
  padding: 10px;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
}
.auth-footer p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

.auth-skip {
  margin-top: 16px;
  text-align: center;
}
.auth-skip button {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  transition: color 0.2s ease;
}
.auth-skip button:hover { color: var(--blue); }

/* Logout button */
.logout-btn {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s ease;
}
.logout-btn:hover { color: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar { position: absolute; z-index: 100; height: 100%; }
  #sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
  .search-box input { width: 120px; }
  .detail-panel { position: absolute; right: 0; z-index: 50; height: 100%; width: 100%; }
  .atp-row { grid-template-columns: 1fr 1fr; }
}