/* Mobile-first additions (UX audit 2026-11-18): thumb navigation (#bottom-nav), the "+ Neu"
   capture sheet (#quick-add) and touch-target fixes. Loaded after style.css and reusing its
   colour tokens; style.css itself stays byte-stable for its pinned layout tests. */

:root {
  /* #c8102e on white is 5.9:1 (WCAG AA for normal text); the brand red #ED2939 is 4.2:1. */
  --qa-accent: #c8102e;
  --qa-on-accent: #ffffff;
  --qa-focus: #1d4ed8;
  --qa-nav-height: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --qa-focus: #93c5fd;
  }
}

/* ---- touch targets in the existing chrome ---- */
#menu-btn {
  min-width: 44px;
}

#sidebar a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1rem;
  box-sizing: border-box;
  color: var(--fg);
}

/* The closed phone sidebar sat at translateX(-100%) yet stayed visible to touch, focus and
   VoiceOver, and buttons wider than it peeked in at the left edge. */
@media (max-width: 720px) {
  #sidebar {
    overflow-x: hidden;
    box-sizing: border-box;
  }

  #sidebar:not(.open) {
    visibility: hidden;
    transition: transform 0.2s, visibility 0s linear 0.2s;
  }

  #sidebar > button,
  #sidebar > a {
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ---- bottom navigation ---- */
#bottom-nav {
  flex: none;
  display: flex;
  align-items: stretch;
  position: relative;
  z-index: 30;
  /* reach into the body's home-indicator padding so the bar colour runs to the screen edge */
  margin-bottom: calc(-1 * env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid var(--border);
  background-color: var(--card);
}

#bottom-nav .bn-item {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--qa-nav-height);
  margin: 0;
  padding: 6px 2px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#bottom-nav .bn-label {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#bottom-nav .bn-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#bottom-nav .bn-item[aria-current="page"] {
  color: var(--fg);
  font-weight: 600;
}

#bottom-nav .bn-item[aria-current="page"] .bn-icon svg {
  stroke-width: 2.5;
}

#bottom-nav .bn-add .bn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 32px;
  border-radius: 16px;
  background-color: var(--qa-accent);
  color: var(--qa-on-accent);
}

#bottom-nav .bn-add {
  color: var(--fg);
  font-weight: 600;
}

#bottom-nav .bn-item:focus-visible {
  outline: 3px solid var(--qa-focus);
  outline-offset: -3px;
}

/* the iOS keyboard needs the room; the composer then sits directly on it */
body.keyboard-open #bottom-nav {
  display: none;
}

@media (min-width: 721px) {
  #bottom-nav {
    justify-content: center;
  }

  #bottom-nav .bn-item {
    flex: 0 1 8rem;
  }
}

/* ---- capture sheet ---- */
#quick-add {
  box-sizing: border-box;
  width: min(100% - 2rem, 32rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background-color: var(--bg);
  color: var(--fg);
  box-shadow: 0 12px 40px var(--shadow);
  overflow-y: auto;
  overscroll-behavior: contain;
}

#quick-add::backdrop {
  background-color: rgba(0, 0, 0, 0.45);
}

/* phones: a full-screen sheet, so the iOS keyboard never hides the fields it edits */
@media (max-width: 720px) {
  #quick-add {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border: none;
    border-radius: 0;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
      env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  }
}

#quick-add .qa-form,
#quick-add .qa-done {
  padding: 0 1rem 1rem;
}

#quick-add .qa-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.5rem;
}

#quick-add h2 {
  margin: 0.5rem 0;
  font-size: 1.375rem;
}

#quick-add .qa-close {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--fg);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

#quick-add .qa-label {
  display: block;
  margin: 1rem 0 0.375rem;
  padding: 0;
  font-weight: 600;
}

#quick-add input,
#quick-add select {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--card);
  color: var(--fg);
  font-size: 17px;
}

#quick-add input {
  -webkit-appearance: none;
  appearance: none;
}

#quick-add .qa-when {
  margin: 1rem 0 0;
  padding: 0;
  border: none;
  min-width: 0;
}

#quick-add .qa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#quick-add .qa-chip {
  min-height: 44px;
  padding: 0 0.875rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background-color: var(--bg);
  color: var(--fg);
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

#quick-add .qa-chip[aria-pressed="true"] {
  border-color: var(--fg);
  background-color: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

#quick-add .qa-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 0.75rem;
}

#quick-add .qa-hint {
  margin: 0.375rem 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

#quick-add .qa-hint a {
  color: var(--fg);
}

#quick-add .qa-message:empty {
  display: none;
}

#quick-add .qa-message {
  margin: 1rem 0 0;
  padding: 0.625rem 0.75rem;
  border-left: 4px solid var(--danger);
  border-radius: 6px;
  background-color: var(--card);
}

#quick-add .qa-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

#quick-add .qa-actions button {
  flex: 1 1 0;
  padding: 0 0.75rem;
  min-height: 50px;
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
  touch-action: manipulation;
}

#quick-add .qa-actions .qa-primary {
  flex-grow: 2;
}

#quick-add .qa-primary {
  border: 1px solid var(--qa-accent);
  background-color: var(--qa-accent);
  color: var(--qa-on-accent);
  font-weight: 600;
}

#quick-add .qa-primary:disabled {
  opacity: 0.7;
  cursor: progress;
}

#quick-add .qa-secondary {
  border: 1px solid var(--border);
  background-color: var(--card);
  color: var(--fg);
}

#quick-add .qa-done-title {
  margin-top: 1.25rem;
}

#quick-add .qa-done-text {
  font-size: 17px;
  line-height: 1.45;
}

#quick-add button:focus-visible,
#quick-add input:focus-visible,
#quick-add select:focus-visible,
#quick-add a:focus-visible,
#quick-add .qa-done-title:focus-visible {
  outline: 3px solid var(--qa-focus);
  outline-offset: 2px;
}

/* ---- task dashboard and reminders panel on phones ---- */
#task-dashboard .task-meta p {
  margin: 0;
}

#task-dashboard .task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

#task-dashboard .task-card {
  border-radius: 12px;
}

@media (max-width: 720px) {
  /* the bottom navigation's Chat tab replaces these; the timezone/reference line is diagnostics */
  #task-dashboard-back,
  #reminders-back,
  #task-dashboard-context {
    display: none;
  }
}
