:root {
  --bg-1: #f1ecff;
  --bg-2: #fff0f5;
  --bg-3: #e8f9f3;
  --surface: #ffffff;
  --surface-soft: #faf8ff;
  --border: #e9e4f7;
  --border-strong: #d4cbee;
  --text-primary: #231f3a;
  --text-secondary: #6a6585;
  --text-muted: #a09bb8;
  --text-danger: #d6264f;

  --brand-1: #6c5ce7;
  --brand-2: #a259ff;
  --brand-3: #ff6fae;

  --high: #f0476a;
  --high-soft: #fff0f3;
  --medium: #f5a524;
  --medium-soft: #fff6e5;
  --low: #17b890;
  --low-soft: #e9faf5;

  --radius: 14px;
  --shadow: 0 6px 20px rgba(108, 92, 231, 0.10);
  --shadow-sm: 0 2px 8px rgba(108, 92, 231, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%) fixed;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(120deg, var(--brand-1) 0%, var(--brand-2) 55%, var(--brand-3) 100%);
  color: #fff;
  border-radius: 22px;
  padding: 1.6rem 1.5rem 1.5rem;
  box-shadow: 0 12px 30px rgba(108, 92, 231, 0.32);
  margin-bottom: 1rem;
}
.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.hero::before { width: 180px; height: 180px; right: -50px; top: -70px; }
.hero::after  { width: 110px; height: 110px; right: 70px; bottom: -60px; background: rgba(255,255,255,0.10); }
.hero-greeting { font-size: 13px; opacity: 0.9; margin: 0 0 2px; position: relative; }
.hero h1 {
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
  position: relative;
}
.hero-date { font-size: 13px; opacity: 0.85; margin: 0; position: relative; }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 1.1rem;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--brand-1);
}
.stat-num { font-size: 22px; font-weight: 600; line-height: 1.1; }
.stat-label { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.stat.s-open    { border-top-color: var(--brand-1); }
.stat.s-open .stat-num { color: var(--brand-1); }
.stat.s-today   { border-top-color: var(--medium); }
.stat.s-today .stat-num { color: #d98a00; }
.stat.s-overdue { border-top-color: var(--high); }
.stat.s-overdue .stat-num { color: var(--high); }
.stat.s-done    { border-top-color: var(--low); }
.stat.s-done .stat-num { color: var(--low); }

/* ---------- Add task card ---------- */
.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 1.1rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow);
}

.row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.row:last-of-type { margin-bottom: 0; }

input[type="text"],
input[type="datetime-local"],
select {
  height: 44px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  padding: 0 14px;
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
  min-width: 150px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 4px rgba(162, 89, 255, 0.15);
  background: #fff;
}

button { font-family: inherit; cursor: pointer; }

.btn-primary {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2) 60%, var(--brand-3));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0 22px;
  height: 44px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(108, 92, 231, 0.42); }
.btn-primary:active { transform: translateY(0); }

.quick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.quick-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 2px;
}
.quick-row .chip-btn { padding: 5px 11px; font-size: 12px; }
.quick-row .chip-btn:hover {
  background: var(--surface-soft);
  color: var(--brand-1);
  border-color: var(--brand-2);
}

/* Date & time picker theme */
.flatpickr-calendar {
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(108, 92, 231, 0.25);
  border: 1px solid var(--border);
  font-family: inherit;
}
.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
span.flatpickr-weekday { color: var(--text-primary); fill: var(--text-primary); }
span.flatpickr-weekday { color: var(--brand-2); font-weight: 700; }
.flatpickr-day { border-radius: 10px; }
.flatpickr-day:hover { background: var(--surface-soft); border-color: var(--surface-soft); }
.flatpickr-day.today { border-color: var(--brand-1); }
.flatpickr-day.today:hover { background: var(--surface-soft); color: var(--brand-1); }
.flatpickr-day.selected,
.flatpickr-day.selected:hover {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-3));
  border-color: transparent;
  color: #fff;
}
.flatpickr-time { border-top: 1px solid var(--border); }
.flatpickr-time input:hover,
.flatpickr-time .flatpickr-am-pm:hover,
.flatpickr-time input:focus,
.flatpickr-time .flatpickr-am-pm:focus { background: var(--surface-soft); }
.flatpickr-calendar.arrowTop:before,
.flatpickr-calendar.arrowTop:after { display: none; }

.error {
  font-size: 13px;
  color: var(--text-danger);
  margin: 8px 0 0;
  display: none;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(6px);
  border-radius: 16px;
  padding: 5px;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
}
.tab-btn {
  flex: 1;
  font-size: 13px;
  padding: 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--brand-1); }
.tab-active {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.35);
}

/* ---------- Daily header / progress ---------- */
.daily-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
}
.muted { color: var(--text-secondary); font-size: 12px; font-weight: 500; }

.progress-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1.1rem;
  box-shadow: inset 0 1px 3px rgba(108, 92, 231, 0.12);
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--low), #5ee0b8);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ---------- Filter chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}
.chip-btn {
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  transition: all 0.15s;
}
.chip-btn:hover { border-color: var(--brand-2); }
.chip-active {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* ---------- Task cards ---------- */
.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px 13px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  border-left: 5px solid var(--border-strong);
  transition: transform 0.12s, box-shadow 0.12s;
}
.task-row:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.task-row.p-high   { border-left-color: var(--high);   background: linear-gradient(90deg, var(--high-soft), #fff 45%); }
.task-row.p-medium { border-left-color: var(--medium); background: linear-gradient(90deg, var(--medium-soft), #fff 45%); }
.task-row.p-low    { border-left-color: var(--low);    background: linear-gradient(90deg, var(--low-soft), #fff 45%); }
.task-row.done { opacity: 0.55; background: var(--surface); border-left-color: var(--border-strong); }

.check-circle {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s;
}
.check-circle:hover { transform: scale(1.1); }
.check-circle input {
  position: absolute;
  opacity: 0;
  width: 24px;
  height: 24px;
  cursor: pointer;
}
.check-circle.checked {
  background: var(--low);
  border-color: var(--low) !important;
  color: #fff;
}

.task-text {
  flex: 1;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-primary);
}
.task-row.done .task-text {
  text-decoration: line-through;
  color: var(--text-muted);
  font-weight: 400;
}

.priority-badge {
  font-size: 11px;
  padding: 4px 11px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.deadline-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(108, 92, 231, 0.08);
  padding: 4px 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.deadline-label.done-label {
  color: #0f8a6c;
  background: var(--low-soft);
}
#completed-container .task-row.done { opacity: 0.9; }
.deadline-label.overdue {
  color: var(--text-danger);
  background: rgba(240, 71, 106, 0.12);
}

.delete-btn {
  border: none;
  background: transparent;
  padding: 4px;
  color: var(--text-muted);
  flex-shrink: 0;
  border-radius: 8px;
}
.delete-btn:hover { color: var(--text-danger); background: rgba(240, 71, 106, 0.1); }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 2.2rem 1rem;
  color: var(--text-secondary);
  text-align: center;
  background: rgba(255, 255, 255, 0.7);
  border: 2px dashed var(--border-strong);
  border-radius: 18px;
}
.empty-state i { font-size: 32px; color: var(--brand-2); }
.empty-state p { font-size: 13px; margin: 0; }

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 1.4rem 0 8px;
}

/* ---------- Calendar ---------- */
#calendar-view {
  background: var(--surface);
  border-radius: 18px;
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.cal-header button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--surface-soft);
  color: var(--brand-1);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-header button:hover { background: var(--brand-1); color: #fff; }
#cal-month-label { font-size: 16px; font-weight: 600; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.cal-weekday {
  font-size: 11px;
  color: var(--brand-2);
  text-align: center;
  padding: 4px 0;
  font-weight: 700;
}
.cal-day-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px;
  min-height: 48px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--surface-soft);
  transition: all 0.12s;
}
.cal-day-btn:hover { border-color: var(--brand-2); }
.cal-day-btn.selected {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-3));
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.35);
}
.cal-day-btn.selected .cal-day-num { color: #fff; font-weight: 700; }
.cal-day-btn.today { border-color: var(--brand-1); background: #fff; }
.cal-day-btn.today .cal-day-num { color: var(--brand-1); font-weight: 700; }
.cal-day-num { font-size: 13px; font-weight: 500; }
.cal-dots { display: flex; gap: 3px; min-height: 6px; }
.cal-dots span { width: 6px; height: 6px; border-radius: 50%; }
.cal-day-btn.selected .cal-dots span { box-shadow: 0 0 0 1.5px #fff; }

.day-detail-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-1);
  margin: 1.1rem 0 10px;
}

@media (max-width: 520px) {
  .tab-btn { padding: 10px 4px; font-size: 12px; gap: 3px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .task-row { flex-wrap: wrap; }
  .task-text { min-width: 55%; }
}
