/* ==============================================
   DESIGN TOKENS
   ============================================== */
:root {
  --bg: #F0F6FF;
  --bg2: #E4EFFB;
  --surface: #FFFFFF;
  --surface2: #F7FAFF;
  --border: #D6E4F7;
  --border-focus: #2563EB;
  --text1: #0D1B2A;
  --text2: #4A6080;
  --text3: #8FA8C4;
  --accent: #2563EB;
  --accent-h: #1D4ED8;
  --accent-light: #EFF6FF;
  --accent-text: #FFFFFF;
  --success: #10B981;
  --error: #EF4444;
  --warn: #F59E0B;
  --info-color: #06B6D4;
  --shadow-sm: 0 1px 3px rgba(37,99,235,.08);
  --shadow-md: 0 4px 16px rgba(37,99,235,.12);
  --shadow-lg: 0 12px 40px rgba(37,99,235,.16);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --trans: all 0.22s cubic-bezier(.4,0,.2,1);
  --header-h: 68px;
  --fab-size: 58px;
  --font: 'Inter', sans-serif;
}

[data-theme="dark"] {
  --bg: #0A0F1E;
  --bg2: #0F172A;
  --surface: #1A2236;
  --surface2: #1E293B;
  --border: #2A3A55;
  --border-focus: #3B82F6;
  --text1: #F0F6FF;
  --text2: #94A3B8;
  --text3: #4A6080;
  --accent: #3B82F6;
  --accent-h: #2563EB;
  --accent-light: #162035;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text1);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, button { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea { outline: none; border: none; background: none; width: 100%; }
textarea { resize: vertical; }
svg { flex-shrink: 0; display: block; }

/* ==============================================
   OVERLAY / MODALS
   ============================================== */
.overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10,15,30,.55);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }

/* USERNAME CARD */
.username-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 20px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.35s cubic-bezier(.4,0,.2,1);
}
.welcome-icon {
  width: 72px; height: 72px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.username-card h2 { font-size: 1.6rem; font-weight: 800; color: var(--text1); }
.username-card p { color: var(--text2); font-size: .95rem; line-height: 1.5; }

/* CREATE CARD */
.create-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 20px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s cubic-bezier(.4,0,.2,1);
  max-height: 90dvh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 1.25rem; font-weight: 700; }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px;
}

/* ==============================================
   FORM ELEMENTS
   ============================================== */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: .82rem; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: .06em;
  display: flex; align-items: center; gap: 5px;
}
.req { color: var(--error); }

.form-group input,
.form-group textarea {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: .95rem;
  color: var(--text1);
  transition: var(--trans);
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: var(--surface);
}
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text3); }

.char-count { font-size: .75rem; color: var(--text3); text-align: right; }

.form-fields { display: flex; flex-direction: column; gap: 16px; }

/* TYPE TOGGLE */
.type-toggle {
  display: flex; gap: 8px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.type-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px;
  font-size: .9rem; font-weight: 600;
  color: var(--text2);
  border-radius: 6px;
  transition: var(--trans);
}
.type-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ==============================================
   BUTTONS
   ============================================== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: .92rem; font-weight: 600;
  transition: var(--trans);
}
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px rgba(37,99,235,.35);
}
.btn-primary:hover { background: var(--accent-h); transform: translateY(-1px); box-shadow: 0 4px 18px rgba(37,99,235,.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: var(--bg2); color: var(--text2); }
.btn-ghost:hover { background: var(--border); }
.btn-full { width: 100%; justify-content: center; }
.btn-text { background: none; color: var(--accent); font-size: .82rem; font-weight: 600; padding: 4px 8px; border-radius: 6px; }
.btn-text:hover { background: var(--accent-light); }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  background: transparent;
  transition: var(--trans);
}
.icon-btn:hover { background: var(--bg2); color: var(--text1); }

/* ==============================================
   HEADER
   ============================================== */
#main-header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}

.header-brand {
  display: flex; align-items: center; gap: 9px; flex-shrink: 0;
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
}
.logo-text { font-size: 1.15rem; font-weight: 800; color: var(--text1); }

.header-search { flex: 1; max-width: 480px; }
.search-wrapper {
  position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 11px; color: var(--text3); pointer-events: none;
}
#search-input {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 36px 8px 36px;
  font-size: .9rem; color: var(--text1);
  transition: var(--trans); width: 100%;
}
#search-input:focus {
  border-color: var(--border-focus);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
#search-input::placeholder { color: var(--text3); }
.clear-btn {
  position: absolute; right: 10px;
  width: 22px; height: 22px;
  border-radius: 50%; background: var(--text3);
  color: #fff; display: flex; align-items: center; justify-content: center;
  transition: var(--trans);
}
.clear-btn:hover { background: var(--text2); }

.header-actions {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto;
}

/* User avatar */
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7C3AED);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .9rem; font-weight: 700;
  cursor: default; flex-shrink: 0;
}

/* ==============================================
   NOTIFICATION BELL & PANEL
   ============================================== */
.notif-wrapper { position: relative; }

.notif-badge {
  position: absolute; top: 4px; right: 4px;
  width: 17px; height: 17px;
  background: var(--error); color: #fff;
  font-size: .62rem; font-weight: 700;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.notif-badge.hidden { display: none; }

.notif-panel {
  position: absolute; top: calc(100% + 10px); right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideDown .2s ease;
  z-index: 300;
}
.notif-panel.hidden { display: none; }
.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.notif-panel-header h3 { font-size: .95rem; font-weight: 700; }
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 16px; color: var(--text3); font-size: .85rem;
}
.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-start;
  transition: var(--trans);
}
.notif-item:hover { background: var(--bg2); }
.notif-item:last-child { border-bottom: none; }
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0; margin-top: 5px;
}
.notif-item p { font-size: .85rem; color: var(--text1); line-height: 1.4; }
.notif-item span { font-size: .75rem; color: var(--text3); }

/* ==============================================
   MAIN FEED
   ============================================== */
#main-feed {
  max-width: 720px; margin: 0 auto;
  padding: 24px 16px calc(var(--fab-size) + 48px);
  min-height: calc(100dvh - var(--header-h));
  overflow-x: hidden;
}

/* Pull to refresh */
.ptr-indicator {
  display: flex; align-items: center; justify-content: center;
  height: 0; overflow: hidden; opacity: 0;
  transition: height .2s ease, opacity .2s ease;
}
.ptr-spinner {
  color: var(--accent); animation: spin 1s linear infinite;
  width: 28px; height: 28px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Filter tabs */
.filter-bar {
  display: flex; gap: 6px; margin-bottom: 20px;
  overflow-x: auto; padding-bottom: 2px;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-tab {
  flex-shrink: 0; padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: .85rem; font-weight: 600;
  color: var(--text2);
  background: var(--surface);
  border: 1.5px solid var(--border);
  transition: var(--trans);
}
.filter-tab:hover { border-color: var(--accent); color: var(--accent); }
.filter-tab.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(37,99,235,.3);
}

/* Skeletons */
.skeleton-list { display: flex; flex-direction: column; gap: 12px; }
.skeleton-card {
  height: 88px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-card:nth-child(2) { animation-delay: .15s; }
.skeleton-card:nth-child(3) { animation-delay: .3s; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Items list */
.items-list { display: flex; flex-direction: column; gap: 10px; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 60px 20px; color: var(--text3); text-align: center;
}
.empty-state.hidden { display: none; }
.empty-state h3 { font-size: 1.1rem; font-weight: 700; color: var(--text2); }
.empty-state p { font-size: .9rem; }

/* ==============================================
   ITEM CARDS
   ============================================== */
.item-card {
  position: relative; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .22s ease, border-color .22s ease;
  animation: slideUp .25s ease both;
}
.item-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-focus); }

/* Swipe backgrounds */
.swipe-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center;
  padding: 0 24px;
  opacity: 0;
  transition: opacity .15s ease;
}
.swipe-bg.left {
  background: linear-gradient(90deg, var(--error), transparent);
  justify-content: flex-start; color: #fff;
}
.swipe-bg.right {
  background: linear-gradient(270deg, var(--error), transparent);
  justify-content: flex-end; color: #fff;
}
.swipe-bg span { font-size: .88rem; font-weight: 700; display: flex; align-items: center; gap: 6px; }

/* Card inner (draggable) */
.item-inner {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 14px 14px 14px;
  background: var(--surface);
  position: relative; z-index: 1;
  will-change: transform;
}

/* Left icon area */
.item-left { flex-shrink: 0; padding-top: 2px; }

/* Checkbox */
.checkbox-btn {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  transition: var(--trans);
  color: #fff;
}
.checkbox-btn:hover { border-color: var(--accent); background: var(--accent-light); }
.checkbox-btn.checked { background: var(--success); border-color: var(--success); }

/* Info icon */
.info-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--info-color);
  color: var(--info-color);
  font-size: .75rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-style: italic;
}

/* Card body */
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }

.item-title {
  font-size: .97rem; font-weight: 600; color: var(--text1);
  line-height: 1.35; word-break: break-word;
}
.item-card.done .item-title {
  text-decoration: line-through; color: var(--text3);
}
.item-desc {
  font-size: .87rem; color: var(--text2); line-height: 1.5; word-break: break-word;
}
.item-meta {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 4px;
}
.item-meta span {
  font-size: .76rem; color: var(--text3);
  display: flex; align-items: center; gap: 4px;
}
.item-meta .badge-to {
  color: var(--accent); font-weight: 600;
  background: var(--accent-light);
  padding: 2px 8px; border-radius: var(--radius-full);
}
.item-meta .badge-mine {
  color: #7C3AED; font-weight: 600;
  background: #F3E8FF;
  padding: 2px 8px; border-radius: var(--radius-full);
}
[data-theme="dark"] .item-meta .badge-mine { background: #2D1B4E; }

/* Right delete button */
.item-right { flex-shrink: 0; padding-top: 1px; }
.delete-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  transition: var(--trans);
}
.delete-btn:hover { background: #FEE2E2; color: var(--error); }
[data-theme="dark"] .delete-btn:hover { background: #3F1313; }

/* Info type card accent */
.item-card.info { border-left: 3px solid var(--info-color); }
.item-card.task.done { opacity: .7; }

/* Assigned-to-me highlight */
.item-card.for-me {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--surface), var(--accent-light));
}

/* ==============================================
   FAB
   ============================================== */
.fab {
  position: fixed; bottom: 28px; right: 24px; z-index: 500;
  width: var(--fab-size); height: var(--fab-size);
  border-radius: 50%;
  background: var(--accent);
  color: #fff; 
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 24px rgba(37,99,235,.45);
  transition: var(--trans);
}
.fab:hover {
  background: var(--accent-h); transform: scale(1.08) rotate(90deg);
  box-shadow: 0 10px 32px rgba(37,99,235,.55);
}
.fab:active { transform: scale(.96); }

/* ==============================================
   TOAST NOTIFICATIONS
   ============================================== */
#toast-stack {
  position: fixed; bottom: 100px; right: 20px;
  z-index: 600; display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); color: var(--text1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: .9rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: slideRight .25s ease both;
  border-left: 3px solid var(--accent);
  max-width: 320px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.info { border-left-color: var(--info-color); }
.toast.fade-out { animation: fadeOut .3s ease forwards; }

@keyframes slideRight {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ==============================================
   SETUP WARNING BANNER
   ============================================== */
.setup-banner {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  border: 1px solid #F59E0B; border-radius: var(--radius-sm);
  padding: 14px 18px; margin-bottom: 20px;
  font-size: .88rem; color: #78350F; line-height: 1.5;
}
.setup-banner strong { display: block; margin-bottom: 4px; font-size: .95rem; }
[data-theme="dark"] .setup-banner {
  background: #2D1F00; border-color: #78350F; color: #FDE68A;
}

/* ==============================================
   SCROLLBAR
   ============================================== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ==============================================
   RESPONSIVE
   ============================================== */
@media (max-width: 600px) {
  .logo-text { display: none; }
  .header-search { max-width: none; }
  #main-header { gap: 8px; padding: 0 12px; }
  #main-feed { padding: 16px 12px calc(var(--fab-size) + 40px); }
  .username-card { padding: 28px 22px; }
  .create-card { padding: 22px 18px; }
  .fab { bottom: 20px; right: 16px; }
  #toast-stack { right: 12px; left: 12px; }
  .toast { max-width: none; }
  .notif-panel { right: -40px; width: 290px; }
}
