/* ===== CSS Custom Properties ===== */
:root {
  --orange: #e8750a;
  --orange-light: #f59e3f;
  --orange-dim: rgba(232, 117, 10, 0.15);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --bg-surface: #1a1a1a;
  --bg-surface-hover: #222222;
  --bg-elevated: #252525;
  --text: #f0f0f0;
  --text-secondary: #999999;
  --text-muted: #666666;
  --border: #2a2a2a;
  --border-hover: #3a3a3a;
  --modal-bg: #1e1e1e;
  --overlay: rgba(0,0,0,0.6);
  --input-bg: #1a1a1a;
  --tag-bg: #2a2a2a;
  --completed-text: #555555;
  --scrollbar-thumb: #333;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f5;
  --bg-surface: #ffffff;
  --bg-surface-hover: #fafafa;
  --bg-elevated: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e0e0e0;
  --border-hover: #cccccc;
  --modal-bg: #ffffff;
  --overlay: rgba(0,0,0,0.3);
  --input-bg: #f9f9f9;
  --tag-bg: #eee;
  --completed-text: #bbbbbb;
  --scrollbar-thumb: #ccc;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

/* ===== Layout ===== */
#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--orange);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.logout-btn {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.logout-btn:hover {
  color: var(--text);
  background: var(--bg-surface-hover);
}

/* ===== Buttons ===== */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  font-size: 1.3rem;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--bg-surface-hover); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--orange);
  color: #fff;
}
.btn-primary:hover { background: var(--orange-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-surface-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--orange); color: var(--orange); }
.btn-outline.active { border-color: var(--orange); color: var(--orange); background: var(--orange-dim); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-danger {
  background: transparent;
  color: #d44;
  border: none;
}
.btn-danger:hover { background: rgba(221,68,68,0.1); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color var(--transition);
  min-width: 140px;
}
.filter-select:hover { border-color: var(--border-hover); }
.filter-select:focus { outline: none; border-color: var(--orange); }

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

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: grab;
  user-select: none;
}
.task-item:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}
.task-item.dragging {
  opacity: 0.4;
  transform: scale(0.98);
}
.task-item.drag-over {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-dim);
}
.task-item.completed .task-title {
  text-decoration: line-through;
  color: var(--completed-text);
}
.task-item.completed .task-meta {
  color: var(--completed-text);
}
.task-item.overdue {
  border-left: 3px solid var(--orange);
  background: var(--orange-dim);
}

.task-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-hover);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 2px;
  position: relative;
  flex-shrink: 0;
}
.task-checkbox:hover { border-color: var(--orange); }
.task-checkbox:checked {
  background: var(--orange);
  border-color: var(--orange);
}
.task-checkbox:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 6px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-body {
  min-width: 0;
}

.task-title {
  font-size: 0.95rem;
  font-weight: 500;
  word-break: break-word;
  transition: color var(--transition);
}

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

.task-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--tag-bg);
  color: var(--text-secondary);
  font-weight: 500;
}

.task-reminder {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.task-reminder.overdue-text {
  color: var(--orange);
  font-weight: 600;
}

.task-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.task-item:hover .task-actions { opacity: 1; }

.task-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}
.task-action-btn:hover { color: var(--text); background: var(--bg-surface-hover); }
.task-action-btn.delete-btn:hover { color: #d44; background: rgba(221,68,68,0.1); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon {
  margin-bottom: 16px;
  opacity: 0.4;
}
.empty-state p {
  font-size: 0.95rem;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--modal-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body {
  padding: 20px 24px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color var(--transition);
}
.form-input:focus { outline: none; border-color: var(--orange); }
.form-input-sm { padding: 6px 10px; font-size: 0.8rem; }

/* Date/time input styling */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.5);
  cursor: pointer;
}
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
}
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.5);
  cursor: pointer;
}
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
}

.quick-dates {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.suggestions-row {
  margin-bottom: 10px;
}

/* ===== Settings Panel ===== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.settings-overlay[hidden] { display: none; }

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  background: var(--modal-bg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.25s ease;
  z-index: 201;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.settings-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.settings-section {
  margin-bottom: 28px;
}
.settings-section h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.9rem;
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-hover);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--orange); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Suggestions list in settings */
.suggestions-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.add-suggestion {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 6px;
  align-items: end;
}
.add-suggestion select,
.add-suggestion input[type="time"] {
  width: auto;
}

/* ===== Login Screen ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-screen[hidden] { display: none; }

.login-card {
  text-align: center;
  padding: 48px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 100%;
}

.login-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--orange);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 32px;
}

.login-google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: #fff;
  color: #333;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: box-shadow var(--transition), transform var(--transition);
}
.login-google-btn:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

/* ===== Urgent ===== */
.task-item.urgent {
  border-left: 3px solid #e53e3e;
  background: rgba(229, 62, 62, 0.08);
}
.task-item.urgent.overdue {
  border-left: 3px solid #e53e3e;
}

.urgent-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #e53e3e;
  background: rgba(229, 62, 62, 0.12);
  padding: 2px 6px;
  border-radius: 99px;
}

.urgent-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.urgent-check svg {
  color: var(--text-muted);
  transition: color var(--transition);
}
.urgent-checkbox {
  display: none;
}
.urgent-checkbox:checked ~ svg {
  color: #e53e3e;
  fill: #e53e3e;
}
.urgent-checkbox:checked ~ span {
  color: #e53e3e;
  font-weight: 600;
}

.task-action-btn.urgent-action.active {
  color: #e53e3e;
}
.task-action-btn.urgent-action.active svg {
  fill: #e53e3e;
}

/* ===== Completed Section ===== */
.completed-section {
  margin-top: 16px;
}
.completed-section[hidden] { display: none; }

.completed-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 8px 4px;
  transition: color var(--transition);
}
.completed-toggle-btn:hover { color: var(--text-secondary); }

.completed-list {
  margin-top: 8px;
}
.completed-list .task-item {
  opacity: 0.6;
}
.completed-list .task-item:hover {
  opacity: 0.8;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes completeBlink {
  0% { opacity: 1; }
  15% { background: var(--orange-dim); }
  30% { background: var(--bg-surface); }
  45% { background: var(--orange-dim); }
  60% { background: var(--bg-surface); }
  75% { background: var(--orange-dim); }
  85% { background: var(--bg-surface); opacity: 1; }
  100% { opacity: 0; }
}

.task-item.completing {
  animation: completeBlink 1.6s ease forwards;
  pointer-events: none;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #app { padding: 0 12px; }
  .app-header { padding: 16px 0 12px; }
  .app-title { font-size: 1.25rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filter-group { width: 100%; }
  .filter-select { flex: 1; }
  #add-task-btn { width: 100%; }
  .task-item { padding: 12px; gap: 10px; }
  .task-actions { opacity: 1; }
  .settings-panel { width: 100%; }
  .add-suggestion {
    grid-template-columns: 1fr 1fr;
  }
  .modal { margin: 12px; }
  .user-name { display: none; }
}
