/* ============================================
   Onward — Warm Tactile Paper Design System
   Mobile First, Accessible & Non-Overwhelming
   ============================================ */

/* Screen-reader only: visually hidden but accessible to crawlers & assistive tech */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  /* Typography */
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Tactile Warm Paper Palette */
  --bg-page: #f5f4f0;
  --bg-card: #ffffff;
  --bg-card-hover: #faf8f5;
  --bg-input: #f8f7f4;
  
  --text-main: #1c1e21;
  --text-muted: #546070;
  --text-subtle: #6b7a8d;
  
  /* Primary Accent: Serene Indigo */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.16);
  
  /* Friendly Focus Badges (No aggressive reds) */
  --focus-high-bg: #f3e8ff;
  --focus-high-text: #6d28d9;
  
  --focus-med-bg: #e0f2fe;
  --focus-med-text: #0369a1;
  
  --focus-low-bg: #dcfce7;
  --focus-low-text: #166534;
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  
  --border: rgba(0, 0, 0, 0.07);
  --border-focus: #6366f1;
  
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 12px 32px -4px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 16px 40px -6px rgba(79, 70, 229, 0.1);
  
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Explicit Dark Theme Override */
[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #151d2a;
  --bg-card-hover: #1e283a;
  --bg-input: #1a2436;
  
  --text-main: #f8fafc;
  --text-muted: #a1b0c4;
  --text-subtle: #8494a7;
  
  --primary-light: rgba(79, 70, 229, 0.22);
  
  --focus-high-bg: rgba(139, 92, 246, 0.22);
  --focus-high-text: #ddd6fe;
  
  --focus-med-bg: rgba(59, 130, 246, 0.22);
  --focus-med-text: #bfdbfe;
  
  --focus-low-bg: rgba(16, 185, 129, 0.22);
  --focus-low-text: #a7f3d0;
  
  --border: rgba(255, 255, 255, 0.12);
  --border-focus: #818cf8;
  
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 36px -4px rgba(0, 0, 0, 0.5);
  --shadow-hover: 0 16px 40px -4px rgba(99, 102, 241, 0.25);
}

/* System Dark Mode fallback if no explicit theme set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page: #0b0f17;
    --bg-card: #151d2a;
    --bg-card-hover: #1e283a;
    --bg-input: #1a2436;
    
    --text-main: #f8fafc;
    --text-muted: #a1b0c4;
    --text-subtle: #8494a7;
    
    --primary-light: rgba(79, 70, 229, 0.22);
    
    --focus-high-bg: rgba(139, 92, 246, 0.22);
    --focus-high-text: #ddd6fe;
    
    --focus-med-bg: rgba(59, 130, 246, 0.22);
    --focus-med-text: #bfdbfe;
    
    --focus-low-bg: rgba(16, 185, 129, 0.22);
    --focus-low-text: #a7f3d0;
    
    --border: rgba(255, 255, 255, 0.12);
    --border-focus: #818cf8;
    
    --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 36px -4px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 16px 40px -4px rgba(99, 102, 241, 0.25);
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.has-sync-banner {
  padding-top: calc(52px + env(safe-area-inset-top));
}

/* ---- PASSWORD SCREEN ---- */
.password-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 85vh;
}

.password-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 44px 32px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  text-align: center;
  animation: fadeIn 0.35s ease-out;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  margin-bottom: 24px;
}

.password-card h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

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

.password-form .input-wrapper {
  margin-bottom: 20px;
}

.password-form input[type="password"] {
  width: 100%;
  height: 52px;
  padding: 0 20px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}

.password-form input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.remember-row {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
}

.custom-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 500;
  user-select: none;
}

.custom-checkbox input {
  display: none;
}

.custom-checkbox .checkmark {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  background: var(--bg-input);
}

.custom-checkbox input:checked ~ .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.custom-checkbox input:checked ~ .checkmark::after {
  content: '✓';
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 16px;
  font-weight: 600;
  display: none;
}

.btn-primary {
  width: 100%;
  height: 52px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* ---- SETUP SCREEN (BYOD) ---- */
.setup-card {
  max-width: 600px;
  text-align: left;
  padding: 36px 32px;
}

.setup-header {
  text-align: center;
  margin-bottom: 28px;
}

.setup-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-top: 4px;
}

.setup-header .subtitle {
  margin-bottom: 14px;
}

.setup-github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  transition: var(--transition);
}

.setup-github-link:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.setup-steps {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-step {
  display: flex;
  gap: 16px;
}

.step-number {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 800;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-body {
  flex-grow: 1;
}

.step-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
  margin-bottom: 4px;
}

.step-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.step-desc a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.step-desc a:hover {
  text-decoration: underline;
}

/* SCHEMA CODE BLOCK */
.schema-block {
  position: relative;
  background: #1e1e2e;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.schema-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #cdd6f4;
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.schema-copy-btn:hover {
  background: var(--primary);
  color: #ffffff;
}

.schema-copy-btn.copied {
  background: var(--success) !important;
  color: #ffffff !important;
}

#schemaCode {
  color: #a6adc8;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  margin: 0;
}

.setup-fields {
  margin-top: 16px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.setup-label {
  display: block;
  width: 100%;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.setup-input {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
  font-family: var(--font-family);
  box-sizing: border-box;
}

.setup-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

/* ---- TOP FULL-BLEED SYNC BANNER ---- */
.sync-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 99;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #ffffff;
  padding: 8px 24px;
  font-size: 0.85rem;
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.22);
}

.sync-banner-content {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sync-banner-text {
  font-weight: 500;
  letter-spacing: -0.01em;
}

.btn-sync-banner {
  background: #ffffff;
  color: var(--primary);
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-sync-banner:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ---- ELEGANT MODAL OVERLAY ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 36px;
  box-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.28) !important;
  animation: modalPop 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.btn-close-modal {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 10;
}

.btn-close-modal:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  transform: scale(1.06);
}

/* ---- ABOUT & GUIDE MODAL ---- */
.about-card {
  max-width: 640px;
}

.about-header {
  text-align: center;
  margin-bottom: 28px;
}

.about-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-top: 4px;
}

.about-sections {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 28px;
}

.about-item {
  display: flex;
  gap: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  transition: var(--transition);
}

.about-item:hover {
  border-color: var(--primary-glow);
  box-shadow: var(--shadow-sm);
}

.about-icon {
  flex-shrink: 0;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.about-content {
  flex-grow: 1;
}

.about-content h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.about-content p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 6px;
}

.about-content p:last-child {
  margin-bottom: 0;
}

.about-content ul {
  margin: 6px 0 8px 18px;
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.about-content code {
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 700;
}

.about-footer {
  margin-top: 8px;
}

.btn-coffee {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 48px;
  background: #ffdd00;
  color: #000000;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  margin-bottom: 12px;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(255, 221, 0, 0.25);
}

.btn-coffee:hover {
  background: #facc15;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(255, 221, 0, 0.35);
}

.footer-link-btn.coffee-link {
  color: #f59e0b;
}

.footer-link-btn.coffee-link:hover {
  color: #d97706;
}

/* ---- INLINE HOME PAGE GUIDE & FOOTER ---- */
.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: 28px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.guide-card:hover {
  border-color: var(--primary-glow);
}

.guide-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-card);
}

.guide-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.guide-icon {
  font-size: 1.1rem;
}

.btn-toggle-guide {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.guide-card-header:hover .btn-toggle-guide {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.guide-card-body {
  padding: 0 20px 20px 20px;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.2s ease-out;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.guide-grid-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.guide-grid-item h4 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.guide-grid-item p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.guide-grid-item code {
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* APP FOOTER */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-subtle);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footer-link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}

.footer-link-btn:hover {
  color: var(--primary);
}

/* ---- HEADER STATUS PILL ---- */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.status-pill.local {
  color: var(--warning);
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.2);
}

.status-pill.synced {
  color: var(--success);
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.2);
}

.status-pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.local .status-dot {
  animation: pulse 2s infinite;
}

/* Sidebar Connect Cloud button */
.nav-item.connect-cloud-btn {
  color: var(--primary);
  font-weight: 700;
  background: var(--primary-light);
  margin-top: 4px;
}

.nav-item.connect-cloud-btn:hover {
  background: var(--primary);
  color: #ffffff;
}

/* ---- OVERLAY & SIDEBAR ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 19, 24, 0.4);
  backdrop-filter: blur(4px);
  z-index: 240;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  z-index: 250;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 24px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.3rem;
  font-weight: 800;
}

.btn-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.sidebar-nav {
  flex: 1;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 18px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

/* SIDEBAR THEME ROW */
.sidebar-theme-row {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.theme-btn {
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.theme-btn:hover {
  border-color: var(--primary);
}

.sidebar-footer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}

.nav-item.logout {
  color: var(--danger);
}

/* ---- MAIN APP CONTAINER ---- */
.app-container {
  display: none;
  max-width: 680px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease-out;
}

/* ---- APP HEADER ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

.btn-hamburger {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.btn-hamburger:hover {
  border-color: var(--primary);
  transform: scale(1.03);
}

.btn-hamburger span {
  display: block;
  width: 20px;
  height: 2.5px;
  background: var(--text-main);
  border-radius: 2px;
}

.header-title-group h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
}

.header-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---- PROGRESS CARD ---- */
.stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.stats-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.stats-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.stats-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: var(--radius-full);
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- STREAMLINED QUICK TASK CREATOR ---- */
.add-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.add-form:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-hover);
}

.add-form.editing {
  border-color: var(--primary);
  background: var(--primary-light);
}

.form-main {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.form-main input {
  flex: 1 1 0%;
  min-width: 0;
  height: 52px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: clamp(0.9rem, 3.6vw, 1.05rem);
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
  text-overflow: ellipsis;
}

.form-main input::placeholder {
  color: var(--text-subtle);
  font-size: clamp(0.85rem, 3.4vw, 1rem);
}

.form-main input:focus {
  border-color: var(--primary);
}

.form-note-row {
  margin-bottom: 14px;
}

.form-note-row input {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}

.form-note-row input:focus {
  border-color: var(--primary);
}

.btn-add-submit {
  flex-shrink: 0;
  height: 52px;
  padding: 0 24px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-add-submit:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* CHIPS ROW INSIDE ADD FORM */
.form-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip-select-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.88rem;
}

.chip-label-icon {
  font-size: 14px;
}

.chip-select,
.chip-date {
  border: none;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.btn-cancel-edit {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---- SEARCH & CONTROLS ROW ---- */
.controls-row {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 18px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--primary);
}

.search-icon {
  font-size: 14px;
  color: var(--text-muted);
}

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

/* ---- FILTER BAR ---- */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 10px 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.chip:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 14px var(--primary-glow);
}

/* ---- TASK CARDS ---- */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 60px;
}

.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: background 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.task-card:hover {
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.task-card.done {
  opacity: 0.55;
}

.task-card.done .task-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* BIG EASY-TO-TAP CHECKBOX */
.task-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  background: var(--bg-input);
  margin-top: 2px;
}

.task-check:hover {
  border-color: var(--primary);
  transform: scale(1.1);
}

.task-card.done .task-check {
  background: var(--success);
  border-color: var(--success);
}

.task-card.done .task-check::after {
  content: '✓';
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

.task-content {
  flex: 1;
  min-width: 0;
}

.task-name {
  font-weight: 600;
  font-size: 1.08rem;
  color: var(--text-main);
  line-height: 1.45;
  margin-bottom: 4px;
  word-break: break-word;
}

.task-note {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
  word-break: break-word;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

/* SOOTHING BADGES (NO ALARMING REDS) */
.tag {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.tag-priority.high {
  background: var(--focus-high-bg);
  color: var(--focus-high-text);
  border: none;
}

.tag-priority.medium {
  background: var(--focus-med-bg);
  color: var(--focus-med-text);
  border: none;
}

.tag-priority.low {
  background: var(--focus-low-bg);
  color: var(--focus-low-text);
  border: none;
}

.tag-syncing {
  background: #fef3c7;
  color: #d97706;
}

/* ACTION BUTTONS */
.task-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  opacity: 0.85;
  transition: var(--transition);
}

.task-card:hover .task-actions {
  opacity: 1;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-input);
  color: var(--text-main);
}

.btn-icon.delete:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* DRAG AND DROP — SORTABLEJS & FLIP PHYSICS */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  color: var(--text-subtle);
  font-size: 18px;
  letter-spacing: -2px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  opacity: 0.4;
  transition: var(--transition);
  margin-top: 2px;
}

.task-card:hover .drag-handle {
  opacity: 1;
  color: var(--text-muted);
}

.drag-handle:active,
.sortable-drag .drag-handle,
.sortable-chosen .drag-handle {
  cursor: grabbing !important;
}

/* GHOST / PLACEHOLDER SLOT LEFT BEHIND */
.task-card.sortable-ghost {
  opacity: 0.25 !important;
  background: var(--bg-card-hover) !important;
  border: 2px dashed var(--primary) !important;
  box-shadow: none !important;
  transform: none !important;
}

/* FLOATING DRAGGED CARD (TACTILE LIFT) */
.task-card.sortable-drag,
.task-card.sortable-fallback {
  opacity: 1 !important;
  transform: scale(1.02) rotate(1deg) !important;
  box-shadow: 0 20px 40px -6px rgba(79, 70, 229, 0.4), 0 10px 20px rgba(0, 0, 0, 0.15) !important;
  border: 2px solid var(--primary) !important;
  border-radius: var(--radius-lg) !important;
  background: var(--bg-card) !important;
  z-index: 999999 !important;
  cursor: grabbing !important;
  transition: none !important;
}

.sortable-fallback {
  pointer-events: none !important;
}

/* Disable hover transform while dragging to prevent jitter */
.task-card.sortable-chosen {
  transition: none !important;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
}

.empty-state .emoji {
  font-size: 3.5rem;
  margin-bottom: 14px;
}

.empty-state p {
  font-size: 1.05rem;
  font-weight: 500;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--text-main);
  color: var(--bg-card);
  padding: 14px 28px;
  border-radius: var(--radius-full);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

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

/* MOBILE OPTIMIZATIONS */
@media (max-width: 640px) {
  body {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom));
  }

  body.has-sync-banner {
    padding-top: calc(96px + env(safe-area-inset-top)) !important;
  }

  .sync-banner {
    padding: 8px 14px;
  }

  .sync-banner-content {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }

  .sync-banner-text {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .btn-sync-banner {
    padding: 4px 14px;
    font-size: 0.76rem;
    align-self: center;
  }

  .app-header {
    margin-bottom: 20px;
  }

  .header-title-group h1 {
    font-size: 1.6rem;
  }

  .header-subtitle {
    font-size: 0.82rem;
  }

  .stats-card {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
  }

  .stats-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 10px;
  }

  .stats-title {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
  }

  .stats-value {
    font-size: 0.95rem;
  }

  .add-form {
    padding: 16px;
    gap: 12px;
  }

  .form-main {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .form-main input {
    flex: 1 1 0%;
    min-width: 0;
    height: 46px;
    font-size: 0.92rem;
    padding: 0 14px;
  }

  .btn-add-submit {
    flex-shrink: 0;
    height: 46px;
    padding: 0 16px;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .form-chips-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .chip-select-wrapper {
    flex: 1 1 auto;
    min-width: 105px;
    padding: 6px 12px;
  }

  .chip-select, .chip-date {
    width: 100%;
    font-size: 0.8rem;
  }

  .controls-row {
    margin-bottom: 20px;
    gap: 12px;
  }

  .filter-bar {
    padding-right: 16px;
    gap: 6px;
  }

  .chip {
    padding: 6px 14px;
    font-size: 0.8rem;
  }

  .task-card {
    padding: 14px;
    gap: 10px;
    align-items: flex-start;
  }

  .drag-handle {
    padding: 2px 6px;
    font-size: 1.1rem;
    align-self: center;
    touch-action: none;
    -webkit-user-drag: none;
    opacity: 0.7;
  }

  .task-checkbox {
    width: 22px;
    height: 22px;
    margin-top: 2px;
  }

  .task-name {
    font-size: 0.92rem;
    line-height: 1.45;
  }

  .task-meta {
    gap: 6px;
    margin-top: 4px;
  }

  .task-actions {
    gap: 2px;
    align-self: flex-start;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 0.88rem;
  }

  .modal-card {
    padding: 24px 20px;
    max-height: 90vh;
  }

  .about-item {
    padding: 14px 16px;
    gap: 12px;
  }

  .about-icon {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
  }

  .about-content h3 {
    font-size: 0.9rem;
  }

  .about-content p {
    font-size: 0.82rem;
  }

  .guide-card-header {
    padding: 14px 16px;
  }

  .guide-card-title {
    font-size: 0.88rem;
  }

  .guide-card-body {
    padding: 0 16px 16px 16px;
  }

  .guide-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}