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

:root {
  /* Colors - Light Theme */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-subtle: #eef2ff;
  --accent: #06b6d4;
  --accent-subtle: #ecfeff;
  --success: #10b981;
  --success-subtle: #ecfdf5;
  --warning: #f59e0b;
  --warning-subtle: #fffbeb;
  --danger: #ef4444;
  --danger-subtle: #fef2f2;

  --bg: #f1f5f9;
  --bg-secondary: #e2e8f0;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07),
    0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08),
    0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.08),
    0 8px 10px -6px rgba(0, 0, 0, 0.05);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --header-height: 72px;
  --sidebar-width: 340px;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --surface: #1e293b;
  --surface-hover: #283548;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --primary-subtle: rgba(99, 102, 241, 0.15);
  --accent-subtle: rgba(6, 182, 212, 0.15);
  --success-subtle: rgba(16, 185, 129, 0.15);
  --warning-subtle: rgba(245, 158, 11, 0.15);
  --danger-subtle: rgba(239, 68, 68, 0.15);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4),
    0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4),
    0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5),
    0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

/* ===== Base ===== */
html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition-slow), color var(--transition-slow);
  /* Clear iPhone home indicator / bottom safe area */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Hide scrollbar everywhere (Chrome/Safari/WebKit, Firefox, IE); no vertical scrollbar */
html,
body {
  overflow-y: hidden;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none !important;
  width: 0;
  height: 0;
}
*::-webkit-scrollbar {
  display: none !important;
  width: 0;
  height: 0;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== App Header ===== */
.app-header {
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-dark) 50%,
    #7c3aed 100%
  );
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
  /* Safe area so navbar content isn’t under notch/Dynamic Island (iPhone) or status bar */
  padding-top: env(safe-area-inset-top, 0);
}

.header-inner {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  color: #fff;
  backdrop-filter: blur(10px);
}

.brand-text h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}

.header-date {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 400;
  margin-top: 1px;
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  backdrop-filter: blur(10px);
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

.theme-btn:active {
  transform: scale(0.95);
}

/* Sun/Moon icon toggling */
[data-theme="light"] .icon-sun {
  display: none;
}
[data-theme="light"] .icon-moon {
  display: block;
}
[data-theme="dark"] .icon-sun {
  display: block;
}
[data-theme="dark"] .icon-moon {
  display: none;
}

/* ===== App Layout (Desktop: Sidebar + Main) ===== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 28px;
  padding-top: 40px;
  padding-bottom: 60px;
  align-items: start;
}

/* ===== Sidebar ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  /* Account for header height + safe area (iPhone notch/Dynamic Island) so sidebar sticks below */
  top: calc(var(--header-height) + env(safe-area-inset-top, 0) + 28px);
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-slow),
    border-color var(--transition-slow), box-shadow var(--transition);
}

.card-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

/* ===== Circular Progress Bar ===== */
.circle-card {
  text-align: center;
}

.circle-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.circle-svg {
  width: 180px;
  height: 180px;
  transform: rotate(-90deg);
}

.circle-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.circle-fg {
  fill: none;
  stroke: url(#progress-gradient);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 471.24;
  stroke-dashoffset: 471.24;
  transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.circle-inner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.circle-percent {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.03em;
  transition: color var(--transition-slow);
}

.circle-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== Stats Row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-card {
  text-align: center;
  padding: 16px 8px;
  position: relative;
  overflow: hidden;
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.stat-total .stat-icon {
  background: var(--primary-subtle);
  color: var(--primary);
}

.stat-done .stat-icon {
  background: var(--success-subtle);
  color: var(--success);
}

.stat-pending .stat-icon {
  background: var(--warning-subtle);
  color: var(--warning);
}

.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  transition: color var(--transition-slow);
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== Chart Cards ===== */
.chart-card {
  padding: 20px 16px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 180px;
}

.chart-wrap-doughnut {
  height: 220px;
}

/* ===== Main Content ===== */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ===== Add Task Form ===== */
.add-form {
  padding: 18px 20px;
}

.form-top {
  display: flex;
  gap: 10px;
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 0 14px;
  transition: border-color var(--transition), background var(--transition),
    box-shadow var(--transition);
}

.input-wrap:focus-within {
  border-color: var(--primary-light);
  background: var(--primary-subtle);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.input-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.task-input {
  flex: 1;
  height: 46px;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--text);
  background: transparent;
}

.task-input::placeholder {
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 22px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  height: 38px;
  padding: 0 14px;
  font-size: 0.8rem;
}

.btn-ghost:hover {
  background: var(--danger-subtle);
  color: var(--danger);
  border-color: var(--danger);
}

/* Form Options / Priority Selector */
.form-options {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.options-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.priority-group {
  display: flex;
  gap: 8px;
}

.priority-option {
  cursor: pointer;
}

.priority-option input {
  display: none;
}

.priority-tag {
  display: inline-block;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 2px solid transparent;
  transition: all var(--transition);
}

.priority-low {
  background: var(--success-subtle);
  color: var(--success);
}

.priority-medium {
  background: var(--warning-subtle);
  color: var(--warning);
}

.priority-high {
  background: var(--danger-subtle);
  color: var(--danger);
}

.priority-option input:checked + .priority-low {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.priority-option input:checked + .priority-medium {
  border-color: var(--warning);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.priority-option input:checked + .priority-high {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 14px;
  height: 42px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrap:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: transparent;
}

.search-input::placeholder {
  color: var(--text-muted);
}

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

.select {
  height: 38px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* ===== Tasks Section ===== */
.tasks-section {
  min-height: 200px;
}

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}

/* ===== Task Item ===== */
.task-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 12px 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  animation: slideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.task-item:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

/* Task Checkbox */
.task-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border: 2.5px solid var(--border);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  transition: all var(--transition);
  padding: 0;
}

.task-check:hover {
  border-color: var(--primary-light);
  background: var(--primary-subtle);
}

.task-check svg {
  width: 14px;
  height: 14px;
  color: #fff;
  opacity: 0;
  transform: scale(0.3);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.task-item.completed .task-check {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.task-item.completed .task-check svg {
  opacity: 1;
  transform: scale(1);
}

/* Task Content */
.task-content {
  flex: 1;
  min-width: 0;
}

.task-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
  transition: all var(--transition);
}

.task-item.completed .task-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

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

.priority-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Task Delete Button */
.task-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0;
}

.task-item:hover .task-delete {
  opacity: 1;
}

.task-delete:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

.task-delete:active {
  transform: scale(0.9);
}

/* ===== Empty State ===== */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}

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

.empty-illustration {
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 50%;
  margin-bottom: 20px;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Animations ===== */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
    max-height: 120px;
  }
  to {
    opacity: 0;
    transform: translateX(50px);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-width: 0;
    overflow: hidden;
  }
}

.slide-out {
  animation: slideOut 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

.shake {
  animation: shake 0.4s ease-in-out;
}

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

/* ===== Responsive: Tablet (max-width: 1024px) ===== */
@media screen and (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .circle-card {
    grid-column: 1 / -1;
  }

  .stats-row {
    grid-column: 1 / -1;
  }
}

/* ===== Responsive: Mobile (max-width: 768px) ===== */
@media screen and (max-width: 768px) {
  :root {
    --header-height: 64px;
  }

  /* On phones: ensure at least 12px from top when safe-area is 0 (e.g. some Android PWAs) */
  .app-header {
    padding-top: max(env(safe-area-inset-top, 0), 12px);
  }

  .container {
    padding: 0 16px;
  }

  /* Extra horizontal padding for content only (navbar stays edge-to-edge) */
  .container.app-layout {
    padding-left: 24px;
    padding-right: 24px;
  }

  .brand-logo {
    width: 38px;
    height: 38px;
  }

  .brand-logo svg {
    width: 22px;
    height: 22px;
  }

  .brand-text h1 {
    font-size: 1.2rem;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .circle-svg {
    width: 150px;
    height: 150px;
  }

  .circle-percent {
    font-size: 2rem;
  }

  .app-layout {
    margin-top: 20px;
    padding-top: 28px;
    padding-bottom: 40px;
    gap: 16px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar-right {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-right .select {
    flex: 1;
    min-width: 0;
  }

  .toolbar-right .btn-ghost {
    flex: 1;
    justify-content: center;
  }

  /* Mobile add button: icon only */
  .btn-primary span {
    display: none;
  }

  .btn-primary {
    width: 46px;
    padding: 0;
  }

  /* Always show delete on mobile */
  .task-delete {
    opacity: 1;
  }

  .form-options {
    flex-wrap: wrap;
  }
}

/* ===== Responsive: Small Mobile (max-width: 480px) ===== */
@media screen and (max-width: 480px) {
  .container {
    padding: 0 12px;
  }

  /* Content-only horizontal padding (navbar unchanged) */
  .container.app-layout {
    padding-left: 20px;
    padding-right: 20px;
  }

  .app-layout {
    margin-top: 16px;
    padding-top: 24px;
  }

  .brand {
    gap: 10px;
  }

  .brand-text h1 {
    font-size: 1.1rem;
  }

  .header-date {
    font-size: 0.7rem;
  }

  .circle-svg {
    width: 130px;
    height: 130px;
  }

  .circle-percent {
    font-size: 1.6rem;
  }

  .circle-label {
    font-size: 0.65rem;
  }

  .stat-card {
    padding: 12px 6px;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .stat-icon {
    width: 30px;
    height: 30px;
  }

  .stat-icon svg {
    width: 14px;
    height: 14px;
  }

  .add-form {
    padding: 14px 14px;
  }

  .task-item {
    padding: 12px 10px 12px 14px;
    gap: 10px;
  }

  .task-text {
    font-size: 0.88rem;
  }

  .priority-tag {
    padding: 4px 10px;
    font-size: 0.68rem;
  }

  .chart-wrap {
    height: 160px;
  }

  .chart-wrap-doughnut {
    height: 200px;
  }
}

/* ===== Print ===== */
@media print {
  .app-header,
  .sidebar,
  .toolbar,
  .add-form,
  .task-check,
  .task-delete {
    display: none !important;
  }

  .app-layout {
    display: block;
  }

  .task-item {
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
