/* Sized for a phone held one-handed: tap targets at least 44px, nothing that
   needs a pointer, and no horizontal scrolling at 320px. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e0dfda;
  --text: #1c1b19;
  --muted: #6d6b66;
  --accent: #2f6f4f;
  --accent-soft: #e3efe8;
  --danger: #a03028;
  --overdue: #a03028;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2126;
    --border: #32353c;
    --text: #e8e8e6;
    --muted: #9a9a96;
    --accent: #6fbf92;
    --accent-soft: #24352c;
    --danger: #e08a80;
    --overdue: #e08a80;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 0 5rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---------------- header ---------------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: env(safe-area-inset-top) 0.75rem 0.6rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0 0.5rem;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

nav {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
}

nav a {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

nav a.current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Open Inbox tasks in that list - its share of the home-screen badge. */
nav .inbox-count {
  margin-left: 0.35rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--surface);
  font-size: 0.7rem;
  font-weight: 600;
}

#add-form {
  display: flex;
  gap: 0.5rem;
}

#add-text {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

#add-form button {
  width: 46px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--surface);
  font-size: 1.4rem;
  line-height: 1;
}

/* ---------------- buckets ---------------- */

main {
  padding: 0.75rem;
}

section {
  margin-bottom: 1.25rem;
}

section h2 {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

section.empty {
  display: none;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

/* ---------------- task row ---------------- */

.task {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: start;
  gap: 0.15rem;
  padding: 0.15rem 0.35rem 0.15rem 0;
  border-top: 1px solid var(--border);
}

.task:first-child {
  border-top: none;
}

.task.busy {
  opacity: 0.5;
}

.check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  min-height: 46px;
  cursor: pointer;
}

.check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.box {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
}

.check input:checked + .box {
  border-color: var(--accent);
  background: var(--accent);
  background-image: linear-gradient(45deg, transparent 45%, var(--surface) 45%, var(--surface) 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--surface) 45%, var(--surface) 55%, transparent 55%);
  background-size: 60% 60%;
  background-position: center;
  background-repeat: no-repeat;
}

.check input:focus-visible + .box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.body {
  padding: 0.7rem 0.25rem 0.7rem 0;
  min-width: 0;
}

.text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

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

.text[contenteditable="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.meta:empty {
  display: none;
}

.due-badge.overdue {
  color: var(--overdue);
  font-weight: 600;
}

.pending {
  color: var(--accent);
  font-size: 0.6rem;
}

/* Marks a task that has notes; the notes themselves stay in the drawer. The
   padding widens the tap target without enlarging the icon. */
.has-notes {
  display: inline-flex;
  margin: -0.35rem;
  padding: 0.35rem;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.has-notes[hidden] {
  display: none;
}

.expand {
  width: 40px;
  min-height: 46px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.2rem;
}

/* ---------------- reordering ---------------- */

/* pan-y lets a swipe that starts on the handle scroll the page: on a phone the
   handle sits where the thumb scrolls from, and a touch drag only begins after
   a hold (see setUpReordering). The callout and selection rules stop iOS
   treating that hold as a long press on text. */
.handle {
  width: 40px;
  min-height: 46px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: grab;
  touch-action: pan-y;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* The list clips to its rounded corners, which would also clip a row being
   dragged past either end of it. */
ul.sorting {
  overflow: visible;
}

.task.dragging {
  position: relative;
  z-index: 5;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

body.dragging {
  cursor: grabbing;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------------- options drawer ---------------- */

.options {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem 0.85rem;
  border-top: 1px dashed var(--border);
}

.buckets-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.buckets-row button {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

.buckets-row button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.date-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

.date-row input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.date-row button,
.danger-row button {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
}

.notes-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* 1rem, not the 0.85rem of the controls around it: iOS zooms the page into any
   text field set smaller than 16px when it takes focus. */
.notes-row textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  resize: vertical;
}

.danger-row button {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------------- show/hide completed ---------------- */

#toggle-done {
  display: block;
  width: calc(100% - 1.5rem);
  margin: -0.5rem 0.75rem 1.5rem;
  padding: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
}

/* ---------------- footer ---------------- */

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

footer button {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

footer button[disabled] {
  opacity: 0.5;
}

#sync-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sync-status.error {
  color: var(--danger);
  white-space: normal;
}

/* ---------------- toast ---------------- */

#toast {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 4.25rem;
  z-index: 20;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  background: var(--danger);
  color: #fff;
  font-size: 0.85rem;
}

[hidden] {
  display: none !important;
}
