/* -------------------------------------------------------------------------
   ToDoei theme – design tokens (theming only)
   ------------------------------------------------------------------------- */
:root {
  --bg-primary: #1E1B2E;
  --bg-secondary: #2C2943;
  --bg-elevated: #35314F;

  --border-subtle: #4C4966;

  --text-primary: #F4F3FA;
  --text-muted: #A7A3C0;

  --accent-primary: #6D63FF;
  --accent-success: #4ADE80;
  --accent-warm: #F6C9B8;
  --accent-gold: #F2C86B;
  --accent-lavender: #8B80F9;

  /* Focus ring */
  --focus-ring: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.2);
  --shadow-modal: 0 8px 32px rgba(0, 0, 0, 0.35);
  --title-bar-height: 3.25rem;
  /* Reserve space so content slot sits strictly between title bar and footer (all buttons always visible, may wrap) */
  --footer-height: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  min-height: -webkit-fill-available;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 42rem;
  margin: 0 auto;
  height: 100vh;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  padding-top: calc(var(--title-bar-height) + env(safe-area-inset-top, 0px));
  padding-bottom: var(--footer-height);
}

.server-error {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent-warm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

/* Title bar – full width, fixed at top; task list scrolls underneath */
.title-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: var(--title-bar-height);
  min-height: 44px;
  padding: calc(env(safe-area-inset-top, 0) + 0.25rem) max(0.75rem, env(safe-area-inset-left, 0)) 0.25rem max(0.75rem, env(safe-area-inset-right, 0));
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.title-bar-logo {
  width: 2.75rem;
  height: 2.75rem;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 6px;
}

.title-bar-brand {
  font-family: "Sora", system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent-lavender);
  background: linear-gradient(135deg, #E879B4 0%, #A78BFA 50%, #6D63FF 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  min-width: 2rem;
  min-height: 2rem;
  font-size: 1.1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.title-bar-btn .nav-icon {
  width: 1.25rem;
  height: 1.25rem;
}

.title-bar-btn:hover,
.title-bar-btn:focus-visible {
  color: var(--text-primary);
  background: var(--bg-elevated);
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent-primary);
}

.title-bar-btn-right {
  margin-left: auto;
}

.title-bar-logout {
  margin-left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  min-width: 2rem;
  min-height: 2rem;
  font-size: 1.1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.title-bar-logout .nav-icon {
  width: 1.25rem;
  height: 1.25rem;
}

.title-bar-logout:hover,
.title-bar-logout:focus-visible {
  color: var(--text-primary);
  background: var(--bg-elevated);
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent-primary);
}

.header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

/* Nav footer – single bar: task actions (when selected) + nav buttons, same row */
.nav-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem max(0.5rem, env(safe-area-inset-left, 0)) calc(0.4rem + env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-right, 0));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  z-index: 20;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* Footer: two rows of buttons */
.footer-actions-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

.footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.nav-footer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  min-width: 2.25rem;
  min-height: 2.25rem;
  font-size: 1.1rem;
  line-height: 1;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-footer button[data-action] {
  background: var(--bg-elevated);
}

.nav-footer button[data-action="bump"] {
  color: var(--accent-success);
}

.nav-footer button:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.nav-footer button:active,
.nav-footer button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent-primary);
}

.nav-footer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
  pointer-events: none;
}

body.rename-mode #new-task-btn {
  display: none;
}

/* Header inputs */
.header-input {
  display: none;
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#rename-input.visible {
  display: block;
}

#rename-input::placeholder {
  color: var(--text-muted);
}

#rename-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: var(--focus-ring);
}

#rename-input {
  border-color: var(--border-subtle);
}

/* Task list scrolls only in the slot between title bar and footer; no overflow under footer */
.list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

#task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#task-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  transition: background 0.12s ease;
  scroll-margin-bottom: 1rem; /* buffer so wrapped task (title + delay/date line) stays fully visible on mobile */
}

#task-list li.selected {
  background: var(--bg-elevated);
  outline: 1px solid var(--accent-primary);
  outline-offset: -1px;
  box-shadow: 0 0 0 1px rgba(109, 99, 255, 0.15);
  touch-action: none;
}

#task-list li.due {
  font-weight: 600;
  color: var(--text-primary);
}

#task-list li.future {
  color: var(--text-muted);
}

#task-list li .meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  margin-left: auto;
}

#task-list li .delay {
  font-variant-numeric: tabular-nums;
  min-width: 2rem;
  text-align: right;
  color: var(--text-muted);
}

#task-list.view-active li .delay {
  flex-shrink: 0;
  margin-right: 0.25rem;
}

#task-list li .date {
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
  color: var(--text-muted);
}

#task-list li.selected .date {
  color: var(--text-primary);
}

#task-list li .title {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-wrap: break-word;
}

.empty-state {
  color: var(--text-muted);
  padding: 1.5rem;
  text-align: center;
}

@media (max-width: 480px) {
  :root {
    --footer-height: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  }

  .nav-footer {
    padding: 0.4rem 0.35rem calc(0.4rem + env(safe-area-inset-bottom));
  }

  /* Larger touch targets on mobile (min 44px) */
  .nav-footer button {
    padding: 0.5rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    font-size: 1rem;
  }

  .nav-footer button .nav-icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .title-bar-btn,
  .title-bar-logout {
    padding: 0.5rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
  }

  .title-bar-btn .nav-icon,
  .title-bar-logout .nav-icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  #task-list li {
    padding: 0.75rem;
  }

  #task-list li .title {
    flex-basis: 100%;
  }

  #task-list li .meta {
    margin-left: 0;
  }
}

/* Search and New task overlays – same style and feel */
.search-overlay,
.new-task-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 0.5rem;
  z-index: 100;
}

.search-overlay[hidden],
.new-task-overlay[hidden] {
  display: none !important;
}

.search-modal,
.new-task-modal {
  width: 100%;
  max-width: 32rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  box-shadow: var(--shadow-modal);
}

.search-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus,
.new-task-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: var(--focus-ring);
}

.new-task-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.new-task-input::placeholder {
  color: var(--text-muted);
}

.new-task-footer {
  margin: 0.5rem 0 0;
  padding: 0.25rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 18rem;
  overflow-y: auto;
  border-radius: var(--radius-md);
}

.search-results li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.12s ease;
}

.search-results li.selected {
  background: var(--bg-elevated);
  outline: 1px solid var(--accent-primary);
  outline-offset: -1px;
}

.search-results li .meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  margin-left: auto;
}

.search-results li .delay {
  font-variant-numeric: tabular-nums;
  min-width: 2rem;
  text-align: right;
  color: var(--text-muted);
}

.search-results li .date {
  font-variant-numeric: tabular-nums;
  min-width: 4.5rem;
  color: var(--text-muted);
}

.search-results li .title {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-wrap: break-word;
}

.search-results li.search-empty {
  cursor: default;
  color: var(--text-muted);
  padding: 1rem;
  text-align: center;
  flex-basis: 100%;
}

.search-footer {
  margin: 0.5rem 0 0;
  padding: 0.25rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.login-overlay[aria-hidden="true"] {
  display: none !important;
}

.login-modal {
  width: 100%;
  max-width: 20rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-modal);
}

.login-logo {
  display: block;
  width: 4rem;
  height: 4rem;
  object-fit: contain;
  margin: 0 auto 0.75rem;
}

.login-title {
  margin: 0 0 0.25rem;
  font-family: "Sora", system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.login-hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-input::placeholder {
  color: var(--text-muted);
}

.login-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: var(--focus-ring);
}

.login-error {
  margin: 0;
  font-size: 0.875rem;
  color: var(--accent-warm);
}

.login-submit {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease, filter 0.15s ease;
}

.login-submit:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
