/* 2du — Minimalist, Swift Todo Item Manager */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  
  /* Light Theme (Default) */
  --bg-page: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f1f3f5;
  --bg-hover: #e9ecef;
  
  --border-subtle: #e9ecef;
  --border-strong: #dee2e6;
  
  --text-main: #212529;
  --text-muted: #6c757d;
  --text-dim: #adb5bd;
  
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-fg: #ffffff;
  
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;
  
  /* Subtle Priority Accents (Tasteful, never harsh or loud) */
  --p1-bg: #fff5f2;
  --p1-text: #c2410c;
  --p1-border: #ea580c;
  --p1-dot: #ea580c;

  --p2-bg: #f0f7ff;
  --p2-text: #1d4ed8;
  --p2-border: #3b82f6;
  --p2-dot: #3b82f6;

  --p3-bg: #f5f3ff;
  --p3-text: #6d28d9;
  --p3-border: #8b5cf6;
  --p3-dot: #7c3aed;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

[data-theme="dark"] {
  --bg-page: #0f1115;
  --bg-surface: #181b20;
  --bg-card: #181b20;
  --bg-subtle: #22262e;
  --bg-hover: #2d323c;
  
  --border-subtle: #262a33;
  --border-strong: #363c48;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-fg: #0f172a;
  
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-border: rgba(239, 68, 68, 0.3);

  --p1-bg: rgba(234, 88, 12, 0.16);
  --p1-text: #fb923c;
  --p1-border: #f97316;
  --p1-dot: #f97316;

  --p2-bg: rgba(59, 130, 246, 0.16);
  --p2-text: #60a5fa;
  --p2-border: #60a5fa;
  --p2-dot: #60a5fa;

  --p3-bg: rgba(139, 92, 246, 0.16);
  --p3-text: #c4b5fd;
  --p3-border: #a78bfa;
  --p3-dot: #a78bfa;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page: #0f1115;
    --bg-surface: #181b20;
    --bg-card: #181b20;
    --bg-subtle: #22262e;
    --bg-hover: #2d323c;
    
    --border-subtle: #262a33;
    --border-strong: #363c48;
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;
    
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --accent-fg: #0f172a;
    
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --danger-border: rgba(239, 68, 68, 0.3);

    --p1-bg: rgba(234, 88, 12, 0.16);
    --p1-text: #fb923c;
    --p1-border: #f97316;
    --p1-dot: #f97316;

    --p2-bg: rgba(59, 130, 246, 0.16);
    --p2-text: #60a5fa;
    --p2-border: #60a5fa;
    --p2-dot: #60a5fa;

    --p3-bg: rgba(139, 92, 246, 0.16);
    --p3-text: #c4b5fd;
    --p3-border: #a78bfa;
    --p3-dot: #a78bfa;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Auth Screen
   ========================================================================== */
.auth-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-main);
}

.logo-bg {
  color: var(--accent);
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.input-group {
  margin-bottom: 16px;
  text-align: left;
}

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.auth-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.auth-card input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

/* ==========================================================================
   App Layout
   ========================================================================== */
.app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

/* Nav View Switcher */
.view-tabs {
  display: flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-full);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.tab-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  color: var(--text-muted);
}

.tab-btn.active .tab-badge {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

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

.icon-btn.small {
  width: 28px;
  height: 28px;
}

.icon {
  width: 18px;
  height: 18px;
}

/* Main Content */
.app-main {
  flex: 1;
  padding: 16px 16px calc(80px + var(--safe-bottom)) 16px;
}

.content-container {
  max-width: 680px;
  margin: 0 auto;
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
}

.btn.secondary:hover {
  background: var(--bg-hover);
}

.btn.danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.btn.danger-outline:hover {
  background: var(--danger-bg);
}

.btn.text-btn {
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn.text-btn:hover {
  color: var(--text-main);
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn.full-width {
  width: 100%;
}

.btn-icon {
  width: 16px;
  height: 16px;
}

.ml-auto {
  margin-left: auto;
}

/* ==========================================================================
   Inline Creator (Instant new task)
   ========================================================================== */
.inline-creator {
  margin-bottom: 16px;
  animation: slideDown 180ms ease-out;
}

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

/* ==========================================================================
   Section Divider (Empty space separating active and completed items)
   ========================================================================== */
.section-divider {
  height: 32px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.section-divider::after {
  content: "";
  width: 100%;
  height: 1px;
  background: var(--border-subtle);
  opacity: 0.6;
}

/* ==========================================================================
   Done View Actions (Centered at bottom)
   ========================================================================== */
.done-footer-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 36px;
  margin-bottom: 24px;
}

.clear-done-btn {
  font-size: 13px;
  font-weight: 500;
  padding: 8px 20px;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.clear-done-btn:hover {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-bg);
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Todo List & Item Cards
   ========================================================================== */
.todo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  min-height: 44px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.todo-item:hover {
  border-color: var(--border-strong);
}

/* Subtle left border priority indicator */
.todo-item.p-1 {
  border-left: 3.5px solid var(--p1-dot);
}

.todo-item.p-2 {
  border-left: 3.5px solid var(--p2-dot);
}

.todo-item.p-3 {
  border-left: 3.5px solid var(--p3-dot);
}

/* Active touch feedback for long-press */
.todo-item.pressing {
  transform: scale(0.985);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

/* Checkbox (Clean, Swift, Touch-Friendly) */
.checkbox-wrap {
  position: relative;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.todo-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  transition: all var(--transition-fast);
  color: transparent;
}

.todo-checkbox:hover {
  border-color: var(--accent);
}

.todo-item.completed .todo-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.check-svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Task Content (Strictly Single Line) */
.todo-text {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

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

/* Inline action button (Recycle on completed items) */
.recycle-inline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 3px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  opacity: 0.65;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.recycle-inline-btn:hover {
  opacity: 1;
  color: var(--accent);
  background: var(--bg-hover);
}

/* Age Timestamp (Right side of single line) */
.todo-age {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.8;
}

.empty-state h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 14px;
  max-width: 320px;
  margin: 0 auto;
}

/* ==========================================================================
   Floating Action Button (New Task)
   ========================================================================== */
.fab {
  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition-fast), background-color var(--transition-fast);
  z-index: 30;
}

.fab:hover {
  transform: scale(1.05);
  background: var(--accent-hover);
}

.fab:active {
  transform: scale(0.95);
}

.icon-fab {
  width: 24px;
  height: 24px;
}

/* ==========================================================================
   Modal / Sheet (Edit Mode & 1-Touch Priority Bumper)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px 16px;
  z-index: 100;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fadeIn 150ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  margin-top: 0;
  animation: popUp 180ms ease-out;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 15px;
  color: var(--text-main);
  resize: vertical;
  min-height: 72px;
  line-height: 1.4;
}

.modal-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-textarea:read-only {
  background: transparent;
  border-color: transparent;
  padding: 4px 0;
  font-size: 16px;
  resize: none;
  color: var(--text-main);
  box-shadow: none;
}

/* 1-Touch Priority Bumper in Modal */
.priority-section {
  margin: 16px 0;
}

.modal-priority-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.priority-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  background: var(--bg-subtle);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0.65;
  transition: all var(--transition-fast);
}

.priority-btn .p-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.priority-btn.p1 .p-dot { background-color: var(--p1-dot); }
.priority-btn.p2 .p-dot { background-color: var(--p2-dot); }
.priority-btn.p3 .p-dot { background-color: var(--p3-dot); }

.priority-btn:hover {
  opacity: 0.95;
  border-color: var(--border-strong);
  color: var(--text-main);
}

.priority-btn.selected {
  opacity: 1;
  font-weight: 700;
  transform: translateY(-1px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.priority-btn.p1.selected {
  background: var(--p1-bg);
  color: var(--p1-text);
  border: 2px solid var(--p1-border);
}

.priority-btn.p2.selected {
  background: var(--p2-bg);
  color: var(--p2-text);
  border: 2px solid var(--p2-border);
}

.priority-btn.p3.selected {
  background: var(--p3-bg);
  color: var(--p3-text);
  border: 2px solid var(--p3-border);
}

.item-meta-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Mobile Screen Placement: Always at top above software keyboard */
@media (max-width: 480px) {
  .modal-backdrop {
    align-items: flex-start;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 12px 12px;
  }

  .modal-card {
    border-radius: var(--radius-lg);
    max-width: 100%;
    padding: 18px 16px;
    margin-top: 0;
  }
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
  animation: toastIn 180ms ease-out;
}

.toast-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-btn {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  padding: 2px 4px;
  cursor: pointer;
}

.toast-btn:hover {
  text-decoration: underline;
}

.toast-close {
  color: var(--text-dim);
  font-size: 15px;
  margin-left: 2px;
  padding: 2px;
  cursor: pointer;
  line-height: 1;
}

.toast-close:hover {
  color: #f8fafc;
}

[data-theme="dark"] .toast {
  background: #334155;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}
