:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273549;
  --nav-bg: rgba(15, 23, 42, 0.92);
  --border: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --warn: #f59e0b;
  --success: #10b981;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #e2e8f0;
    --nav-bg: rgba(255, 255, 255, 0.92);
    --border: rgba(15, 23, 42, 0.1);
    --text: #0f172a;
    --muted: #64748b;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  }
}

:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --nav-bg: rgba(255, 255, 255, 0.92);
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.tiny {
  font-size: 0.78rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-date-time {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 560px) {
  .row-date-time {
    grid-template-columns: 1.35fr 0.85fr;
  }
}

.row-2 > *,
.row-date-time > * {
  min-width: 0;
}

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.auth-card p {
  margin: 0 0 20px;
  font-size: 0.94rem;
}

.auth-footer {
  margin-top: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Form Elements */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  outline: none;
}

input[type="date"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-right: 44px;
}

.eye-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 6px;
}

.error-text {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin: 0;
}

.info-text {
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin: 0;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #ef4444;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-full {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.05rem;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sidebar {
  display: none;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(82px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}

.ptr-indicator {
  height: 0;
  overflow: hidden;
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  transition: height 0.2s ease, opacity 0.2s ease;
}

.ptr-indicator.dragging {
  transition: none;
}

.ptr-indicator.ready {
  color: var(--primary);
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

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

.sync-badge {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
}

.sync-badge.synced {
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.35);
}

.sync-badge.syncing {
  color: var(--primary);
  border-color: rgba(59, 130, 246, 0.35);
}

.sync-badge.offline {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.35);
}

/* Area Chips */
.chip-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 18px 10px;
  scrollbar-width: none;
}

.chip-strip::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

/* List Toolbar & Sort */
.list-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.sort-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* Time Presets */
.time-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 11px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 4px 18px 24px;
}

.due-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #d97706;
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.tasks-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.group-header.overdue {
  color: #ef4444;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.task-card.completing {
  opacity: 0.35;
  transform: scale(0.98);
}

.tick-btn {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  color: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.85rem;
}

.tick-btn.checked {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.18);
  color: var(--success);
}

@media (hover: hover) and (pointer: fine) {
  .tick-btn:hover {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.18);
    color: var(--success);
  }
}

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

.more-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.more-btn:hover,
.more-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

.task-title {
  font-size: 0.97rem;
  font-weight: 600;
  margin: 0 0 4px;
  word-break: break-word;
}

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

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.74rem;
}

.pill.overdue {
  background: rgba(239, 68, 68, 0.16);
  color: #ef4444;
}

.pill.due-soon {
  background: rgba(245, 158, 11, 0.18);
  color: #f59e0b;
}

.pill.priority-high {
  background: rgba(239, 68, 68, 0.16);
  color: #ef4444;
}

.pill.priority-medium {
  background: rgba(245, 158, 11, 0.16);
  color: #d97706;
}

.pill.priority-low {
  background: rgba(59, 130, 246, 0.16);
  color: #3b82f6;
}

/* Areas Dashboard */
.areas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.area-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-area-card {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  min-height: 112px;
}

.area-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.area-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.area-card p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

/* History */
.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.restore-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.del-small-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 6px;
  cursor: pointer;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 18px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(86px + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 10px 26px rgba(59, 130, 246, 0.45);
  cursor: pointer;
  z-index: 20;
}

/* Undo & Calendar Toast */
.undo-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(88px + var(--safe-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 10px 14px 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  z-index: 30;
  white-space: nowrap;
}

.undo-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  z-index: 15;
}

.nav-item {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

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

.nav-icon-wrap {
  position: relative;
  display: inline-flex;
}

.nav-icon {
  font-size: 1.2rem;
}

.nav-badge-dot {
  position: absolute;
  top: -4px;
  right: -10px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

/* Settings & Segmented Control */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.setting-box {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.setting-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.version-footer {
  text-align: center;
  margin: 4px 0 0;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}

.prio-pills {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn,
.prio-btn {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.seg-btn.active,
.prio-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--border);
  padding: 12px 20px calc(22px + var(--safe-bottom));
  max-height: 90dvh;
  overflow-y: auto;
  transition: transform 0.2s ease;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 12px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

/* Manage Areas */
.area-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.area-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emoji-input {
  width: 46px !important;
  min-width: 46px !important;
  text-align: center;
  padding: 8px 4px !important;
}

.area-row-top input[type="text"]:not(.emoji-input) {
  border: none;
  padding: 6px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch-btn.active {
  border-color: var(--text);
  transform: scale(1.12);
}

.area-add-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.area-add-row {
  display: flex;
  gap: 8px;
}

/* Responsive Desktop Sidebar */
@media (min-width: 820px) {
  .app-shell {
    flex-direction: row;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    min-width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 22px 14px;
    gap: 18px;
  }

  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 0 8px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 1rem;
  }

  .sidebar-nav,
  .sidebar-areas {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .side-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    font: inherit;
    font-size: 0.94rem;
    font-weight: 500;
    padding: 9px 12px;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
  }

  .side-item:hover {
    background: var(--surface-2);
  }

  .side-item.active {
    background: var(--primary);
    color: #fff;
  }

  .sidebar-section-label {
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 6px 10px 0;
  }

  .app-main {
    padding-bottom: 32px;
    max-width: 780px;
  }

  .chip-strip,
  .bottom-nav,
  .sheet-handle {
    display: none;
  }

  .fab {
    right: 32px;
    bottom: 32px;
  }

  .undo-toast {
    bottom: 32px;
  }

  .modal {
    align-items: center;
  }

  .modal-sheet {
    border-radius: 24px;
    padding-top: 20px;
  }
}
