@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  -webkit-font-smoothing: antialiased;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #F5F3FF 0%, #EEF2FF 100%);
  min-height: 100vh;
}

/* ── CSS custom properties ── */
:root {
  --purple-900: #1E1B4B;
  --purple-700: #7C3AED;
  --purple-600: #6D28D9;
  --purple-400: #A78BFA;
  --purple-300: #C4B5FD;
  --purple-200: #DDD6FE;
  --purple-100: #EDE9FE;
  --purple-50:  #F5F3FF;
  --indigo-50:  #EEF2FF;
  --green-500:  #10B981;
  --amber-400:  #F59E0B;
  --orange-500: #F97316;
  --red-500:    #EF4444;
  --violet-500: #8B5CF6;
  --gray-900:   #1F2937;
  --gray-500:   #6B7280;
  --gray-400:   #9CA3AF;
  --shadow-sm:  0 2px 10px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 20px rgba(124,58,237,0.1);
  --shadow-lg:  0 6px 20px rgba(124,58,237,0.13);
}

/* ── Keyframe animations ── */
@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.92); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes popIn {
  0%   { transform: scale(0.85); opacity: 0; }
  70%  { transform: scale(1.04); }
  100% { transform: scale(1);    opacity: 1; }
}
@keyframes pulseRing {
  0%   { box-shadow: 0 0 0 0px var(--ring, rgba(124,58,237,0.3)); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0px transparent; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Layout shell ── */
#app-wrapper {
  min-height: 100vh;
  padding: 20px 16px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
}
.toast {
  color: white;
  padding: 10px 24px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.2px;
  white-space: nowrap;
  animation: slideDown 0.22s cubic-bezier(0.34,1.56,0.64,1) forwards;
}
.toast-xp    { background: #10B981; box-shadow: 0 6px 24px rgba(16,185,129,0.45); }
.toast-fire  { background: #F97316; box-shadow: 0 6px 24px rgba(249,115,22,0.45); }
.toast-level { background: #7C3AED; box-shadow: 0 6px 24px rgba(124,58,237,0.45); }

/* ── Mobile content column ── */
#mobile-col {
  width: 100%;
  max-width: 460px;
}

/* ── Header ── */
.app-header {
  text-align: center;
  margin-bottom: 22px;
}
.app-header h1 {
  font-size: 27px;
  font-weight: 900;
  color: var(--purple-900);
  letter-spacing: -0.8px;
}
.app-header p {
  color: var(--purple-400);
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 3px;
  letter-spacing: 0.5px;
}

/* ── Stats card ── */
.stats-card {
  background: white;
  border-radius: 20px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: 16px;
  align-items: center;
}
.xp-bar-section { flex: 1; }
.xp-bar-labels {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.xp-bar-level {
  font-weight: 900;
  font-size: 15px;
  color: var(--purple-700);
}
.xp-bar-fraction {
  font-size: 11px;
  color: var(--purple-400);
  font-weight: 600;
}
.xp-bar-track {
  background: var(--purple-100);
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}
.xp-bar-fill {
  background: linear-gradient(90deg, #7C3AED, #A78BFA);
  height: 100%;
  border-radius: 999px;
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}
.stat-pill {
  text-align: center;
  min-width: 52px;
}
.stat-number-today {
  font-size: 30px;
  font-weight: 900;
  color: var(--amber-400);
  line-height: 1;
}
.stat-number-xp {
  font-size: 30px;
  font-weight: 900;
  color: var(--violet-500);
  line-height: 1;
}
.stat-label {
  font-size: 9.5px;
  color: var(--gray-400);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 3px;
}

/* ── Input bar ── */
.input-bar {
  background: white;
  border-radius: 16px;
  padding: 11px 14px;
  margin-bottom: 14px;
  box-shadow: 0 4px 20px rgba(124,58,237,0.08);
  display: flex;
  gap: 10px;
  align-items: center;
}
.task-input {
  flex: 1;
  border: none;
  font-size: 15px;
  color: var(--purple-900);
  background: transparent;
  font-family: inherit;
  font-weight: 500;
}
.task-input::placeholder { color: var(--purple-300); }
.task-input:focus { outline: none; }

/* ── AI input bar (NLP) ── */
.ai-input-bar {
  background: white;
  border-radius: 16px;
  padding: 11px 14px;
  margin-bottom: 14px;
  box-shadow: 0 4px 20px rgba(124,58,237,0.08);
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1.5px solid var(--purple-200);
}
.ai-input {
  flex: 1;
  border: none;
  font-size: 15px;
  color: var(--purple-900);
  background: transparent;
  font-family: inherit;
  font-weight: 500;
}
.ai-input::placeholder { color: #C4B5FD; }
.ai-input:focus { outline: none; }

/* ── Buttons ── */
.add-btn {
  background: var(--purple-700);
  color: white;
  border: none;
  border-radius: 10px;
  width: 35px; height: 35px;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 300;
  transition: background 0.18s, transform 0.18s;
}
.add-btn:hover { background: #6D28D9; transform: scale(1.06); }

.ai-btn {
  background: linear-gradient(135deg, #7C3AED, #A78BFA);
  color: white;
  border: none;
  border-radius: 10px;
  width: 35px; height: 35px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.18s, transform 0.18s;
}
.ai-btn:hover { opacity: 0.85; transform: scale(1.06); }
.ai-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.action-btn {
  background: var(--purple-700);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.18s, transform 0.18s;
}
.action-btn:hover { background: var(--purple-600); transform: scale(1.02); }
.action-btn.secondary {
  background: white;
  color: var(--purple-700);
  border: 1.5px solid var(--purple-200);
}
.action-btn.secondary:hover { background: var(--purple-50); }

/* ── Task card ── */
.task-card {
  background: white;
  border-radius: 14px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s, opacity 0.32s, translate 0.32s;
}
.task-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.task-card.completing { opacity: 0; translate: 50px 0; }

.complete-btn {
  width: 27px; height: 27px;
  border-radius: 50%;
  border: 2.5px solid var(--pc, #CBD5E1);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s, box-shadow 0.18s, transform 0.18s;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.complete-btn:hover {
  background: var(--pc, #CBD5E1) !important;
  transform: scale(1.22) !important;
  animation: pulseRing 0.5s ease;
}

.task-text {
  flex: 1;
  font-size: 15px;
  color: var(--gray-900);
  line-height: 1.45;
  font-weight: 500;
}

.pri-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 900;
  font-size: 14px;
  padding: 3px 6px;
  border-radius: 6px;
  transition: opacity 0.15s;
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
  font-family: inherit;
}
.pri-btn:hover { opacity: 1 !important; }

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--purple-200);
  font-size: 19px;
  padding: 2px 4px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
  font-weight: 400;
  font-family: inherit;
}
.del-btn:hover { color: var(--red-500) !important; }

/* ── Expand/details area on task card (desktop) ── */
.task-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--purple-300);
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
  transition: color 0.15s;
  flex-shrink: 0;
  font-family: inherit;
  display: none; /* shown on desktop */
}
.task-expand-btn:hover { color: var(--purple-700) !important; }

.task-details {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 6px;
  border-top: 1px solid var(--purple-100);
  margin-top: 4px;
  animation: fadeIn 0.18s ease;
}
.task-details.open { display: flex; }

.task-notes {
  width: 100%;
  border: 1px solid var(--purple-200);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--gray-900);
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}
.task-notes:focus { outline: none; border-color: var(--purple-400); }
.task-notes::placeholder { color: var(--purple-300); }

.task-meta-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.task-date-input {
  border: 1px solid var(--purple-200);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--gray-900);
  font-family: inherit;
  background: white;
}
.task-date-input:focus { outline: none; border-color: var(--purple-400); }

.tag-chip {
  background: var(--purple-100);
  color: var(--purple-700);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background 0.15s;
}
.tag-chip:hover { background: var(--purple-200); }
.tag-chip.active { background: var(--purple-700); color: white; }

.task-tags-input {
  border: 1px solid var(--purple-200);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--gray-900);
  font-family: inherit;
  flex: 1;
}
.task-tags-input:focus { outline: none; border-color: var(--purple-400); }
.task-tags-input::placeholder { color: var(--purple-300); }

/* ── Breakdown suggestion cards ── */
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
  animation: fadeIn 0.2s ease;
}
.breakdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--purple-50);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
.breakdown-add-btn {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--purple-400);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 14px;
  color: var(--purple-700);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.breakdown-add-btn:hover { background: var(--purple-400); color: white; }

/* ── NLP preview card ── */
.nlp-preview {
  background: white;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--purple-400);
  animation: fadeIn 0.2s ease;
}
.nlp-preview-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--purple-900);
  margin-bottom: 6px;
}
.nlp-preview-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--purple-400);
  margin-bottom: 10px;
}
.nlp-preview-actions {
  display: flex;
  gap: 8px;
}

/* ── Empty states ── */
.empty-initial {
  text-align: center;
  padding: 52px 20px;
  color: var(--purple-300);
  animation: popIn 0.35s ease;
}
.empty-initial .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-initial .empty-title { font-weight: 700; font-size: 17px; color: var(--purple-700); }
.empty-initial .empty-sub { font-size: 13px; margin-top: 5px; color: var(--purple-400); }

.empty-all-done {
  text-align: center;
  padding: 32px 0;
  animation: popIn 0.3s ease;
}
.empty-all-done .done-icon { font-size: 44px; margin-bottom: 10px; }
.empty-all-done .done-title { font-weight: 900; font-size: 20px; color: var(--green-500); }
.empty-all-done .done-sub { color: var(--gray-500); font-size: 14px; margin-top: 5px; }

/* ── Task list ── */
#task-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Completed section ── */
#completed-section { margin-top: 22px; }
.show-done-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 2px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
  font-family: inherit;
}
.show-done-btn:hover { color: var(--purple-700) !important; }

#completed-list { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }

.completed-card {
  background: white;
  border-radius: 10px;
  padding: 9px 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0.6;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.completed-check { color: var(--green-500); font-size: 14px; font-weight: 800; flex-shrink: 0; }
.completed-text { flex: 1; font-size: 14px; color: var(--gray-500); text-decoration: line-through; }
.completed-xp { color: var(--purple-400); font-size: 11px; font-weight: 700; flex-shrink: 0; }

/* ── Hint line ── */
.hint-line {
  margin-top: 28px;
  text-align: center;
  color: var(--purple-200);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ── Spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

/* ── Offline banner ── */
#offline-banner {
  display: none;
  background: #F97316;
  color: white;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  z-index: 8888;
}
#offline-banner.visible { display: block; }

/* ── Auth banner ── */
#auth-banner {
  display: none;
  background: var(--purple-700);
  color: white;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  position: fixed;
  top: 0;
  left: 0; right: 0;
  z-index: 8888;
}
#auth-banner a { color: white; text-decoration: underline; }
#auth-banner.visible { display: block; }

/* ── Sync indicator ── */
.sync-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 4px;
  background: var(--green-500);
  transition: background 0.3s;
}
.sync-dot.pending { background: var(--amber-400); }
.sync-dot.error   { background: var(--red-500); }

/* ── AI loading overlay in panel ── */
.ai-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--purple-400);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 0;
}

/* ═══════════════════════════════════════════════
   DESKTOP LAYOUT  (≥769px)
   ═══════════════════════════════════════════════ */
@media (min-width: 769px) {
  #app-wrapper {
    padding: 24px 24px 40px;
    align-items: stretch;
    max-width: 1200px;
    margin: 0 auto;
  }

  /* Three-column grid: sidebar | main | AI panel */
  #desktop-grid {
    display: grid;
    grid-template-columns: 220px 1fr 280px;
    gap: 20px;
    align-items: start;
  }

  #mobile-col {
    max-width: none;
  }

  /* Show expand button on task cards */
  .task-expand-btn { display: flex; }

  /* ── Sidebar ── */
  #sidebar {
    background: white;
    border-radius: 20px;
    padding: 20px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 24px;
  }
  .sidebar-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
  }
  .sidebar-tag-btn {
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-500);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s, color 0.15s;
  }
  .sidebar-tag-btn:hover { background: var(--purple-50); color: var(--purple-700); }
  .sidebar-tag-btn.active { background: var(--purple-100); color: var(--purple-700); font-weight: 700; }
  .sidebar-tag-count {
    background: var(--purple-100);
    color: var(--purple-700);
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
  }
  .sidebar-section { margin-bottom: 20px; }

  /* ── Desktop stats tab ── */
  .tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--purple-50);
    border-radius: 12px;
    padding: 4px;
  }
  .tab-btn {
    flex: 1;
    background: none;
    border: none;
    cursor: pointer;
    padding: 7px 12px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 600;
    color: var(--purple-400);
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
  }
  .tab-btn.active { background: white; color: var(--purple-700); box-shadow: var(--shadow-sm); }

  /* ── AI Panel ── */
  #ai-panel {
    background: white;
    border-radius: 20px;
    padding: 20px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  .ai-panel-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--purple-900);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .ai-feature-section { border-top: 1px solid var(--purple-100); padding-top: 14px; }
  .ai-feature-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
  }

  /* Prioritization diff view */
  .priority-diff {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
  }
  .priority-diff-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 8px;
    background: var(--purple-50);
  }
  .priority-diff-text { flex: 1; color: var(--gray-900); }
  .priority-badge {
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
  }
  .priority-badge.normal { background: #F1F5F9; color: #64748B; }
  .priority-badge.high   { background: #FEF3C7; color: #92400E; }
  .priority-badge.urgent { background: #FEE2E2; color: #991B1B; }
  .priority-arrow { color: var(--purple-400); font-size: 10px; }

  /* Daily summary card */
  .summary-card {
    background: linear-gradient(135deg, var(--purple-50), var(--indigo-50));
    border-radius: 14px;
    padding: 14px;
    border-left: 3px solid var(--purple-400);
    animation: fadeIn 0.25s ease;
  }
  .summary-headline {
    font-weight: 800;
    font-size: 14px;
    color: var(--purple-900);
    margin-bottom: 6px;
  }
  .summary-line {
    font-size: 12px;
    color: var(--gray-500);
    margin-bottom: 4px;
    line-height: 1.5;
  }
  .summary-streak {
    font-size: 12px;
    color: var(--purple-700);
    font-weight: 600;
    margin-top: 6px;
  }

  /* Chart */
  #stats-chart {
    width: 100%;
    border-radius: 12px;
    background: var(--purple-50);
    margin-top: 8px;
  }

  /* Desktop stats numbers row */
  .desktop-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  .desktop-stat-card {
    background: var(--purple-50);
    border-radius: 14px;
    padding: 14px;
    text-align: center;
  }
  .desktop-stat-number {
    font-size: 26px;
    font-weight: 900;
    color: var(--purple-700);
    line-height: 1;
  }
  .desktop-stat-label {
    font-size: 10px;
    color: var(--gray-400);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-top: 4px;
  }
}

/* Mobile: hide desktop-only elements */
@media (max-width: 768px) {
  #desktop-grid { display: contents; }
  #sidebar, #ai-panel { display: none !important; }
  .tab-bar, .desktop-stats-row, #stats-chart { display: none !important; }
}
