:root {
  --wc-danger: #d93526;
  --wc-pending: #c59600;
}

body > main { padding-top: 0; }
nav form.inline { margin: 0; }
/* Sync and Log out: compact buttons that sit on the nav links' line. */
nav button.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: auto;
  margin: 0;
  padding: 0.3rem 0.7rem;
  font-size: 0.875rem;
  white-space: nowrap;
}
/* The Sync icon spins while a sync is running. */
@keyframes wc-spin { to { transform: rotate(360deg); } }
button.sync.htmx-request .icon { animation: wc-spin 1s linear infinite; }

button.link {
  background: none;
  border: none;
  color: var(--pico-primary);
  padding: 0.25rem 0.4rem;
  margin: 0;
  width: auto;
  font-size: 0.875rem;
  text-decoration: underline;
}
button.link.danger { color: var(--wc-danger); }

/* Row actions: square icon buttons, so every row's actions line up. */
.icon { width: 1rem; height: 1rem; fill: currentColor; vertical-align: middle; }
button.icon-button, .icon-button-gap {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  flex: none;
}
button.icon-button {
  background: none;
  border: none;
  border-radius: var(--pico-border-radius);
  color: var(--pico-muted-color);
}
.icon-button.primary { color: var(--pico-primary); }
.icon-button:hover, .icon-button:focus-visible { background: var(--pico-secondary-background); color: var(--pico-secondary-inverse); }
.icon-button.danger:hover, .icon-button.danger:focus-visible { background: var(--wc-danger); color: #fff; }

/* The header's Sync button reads "Syncing…" while its request is out. */
button.sync .busy, button.sync.htmx-request .idle { display: none; }
button.sync.htmx-request .busy { display: inline; }

.muted { color: var(--pico-muted-color); }
.error { color: var(--wc-danger); }

/* Timer */
.timer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  align-items: center;
}
.timer > * { margin: 0; }

/* Pico gives text inputs (but not selects or buttons) a bottom margin through a
   higher-specificity selector, which knocks controls in a row out of line. Zero it
   for every control in our compact forms; the grids' gap does the spacing. */
:is(.timer, .editing, .add-entry, .project-new, .preset-form)
  :is(input, select, textarea, button):not([type="checkbox"], [type="radio"]) {
  margin-bottom: 0;
}
.timer.running { grid-template-columns: 1fr auto; }
.timer.running button { grid-column: 1 / -1; }
.elapsed { font-size: 1.75rem; font-variant-numeric: tabular-nums; }

/* Quick starts: one-tap timers above the timer, a stripe in their project's colour */
.quick-starts {
  display: grid;
  /* Six columns on wide screens, so a full row ends flush with the timer form below and
     a short list keeps the same button size; at least 7.5rem each (two per row on phones). */
  grid-template-columns: repeat(auto-fill, minmax(max(7.5rem, (100% - 2.5rem) / 6), 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.quick-start {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0.5rem 0.75rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: inset 4px 0 0 var(--wc-project, transparent);
}
.emoji { margin-right: 0.35rem; }
/* A fixed slot, so labels start at the same place whatever the emoji's width. */
.quick-start .emoji { flex: none; width: 1.5em; text-align: center; }
.preset-form { grid-template-columns: 4rem 1fr; }
.preset-form .emoji-input { text-align: center; }
.preset-form.editing { padding: 0.6rem 0; border-bottom: 1px solid var(--pico-muted-border-color); }
/* Phones: emoji and description share a row; the rest take a row each.
   Row actions get a line of their own, right-aligned. */
@media (max-width: 767px) {
  :is(.entry, .project-row) .entry-actions { grid-column: 1 / -1; }
  .preset-form > :not(.emoji-input, [name="description"]) { grid-column: 1 / -1; }
}

/* Entries and project rows */
.day-header, .week-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-top: 1.5rem;
}
.day-header h2, .day-header h3, .week-header h2 { margin: 0; }
.total { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.week-header a[role="button"] { padding: 0.25rem 0.75rem; }

.entry, .project-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
  align-items: center;
}
.entry-duration { text-align: right; font-variant-numeric: tabular-nums; }
.entry-time { color: var(--pico-muted-color); font-size: 0.875rem; }
.entry-actions { display: flex; gap: 0.25rem; align-items: center; flex-wrap: wrap; }
.entry .entry-actions, .project-row .entry-actions { gap: 0.15rem; flex-wrap: nowrap; justify-content: flex-end; }
/* Pico makes a form's submit button full width; keep Save and Cancel side by side. */
.entry-actions button:not(.icon-button) { width: auto; }
.entry.editing, .project-row.editing { grid-template-columns: 1fr; }
.editing > *, .add-entry > *, .project-new > *, .preset-form > * { margin-bottom: 0; }
.editing label { margin: 0; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0 0.4rem;
  margin-left: 0.25rem;
  border-radius: 0.5rem;
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}
.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  margin-right: 0.4rem;
}
.badge {
  font-size: 0.75rem;
  padding: 0 0.4rem;
  border-radius: 0.5rem;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge.pending { color: var(--wc-pending); }
.badge.failed { color: var(--wc-danger); }

/* "Starts at 2:15 PM, right after ...": a full-width line under the timer's controls. */
.timer .start-at { grid-column: 1 / -1; margin: 0; font-size: 0.875rem; }
.timer .start-at button.link { padding-inline: 0.25rem; }

/* Rows mix bare controls with labelled ones ("Start", "Stop"): line up the controls. */
.add-entry, .project-new, .preset-form { display: grid; gap: 0.5rem; align-items: end; }
.entry.editing { align-items: end; }
.outbox-item { display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0.4rem 0; }

#flash {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2rem);
  background: var(--wc-danger);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--pico-border-radius);
}
#flash.notice { background: var(--pico-primary-background); color: var(--pico-primary-inverse); }

.login { max-width: 24rem; margin: 4rem auto; }

.recent-day + .recent-day .day-header { margin-top: 0.75rem; }
.week-day.empty .day-header { margin-top: 0.75rem; color: var(--pico-muted-color); }
.week-day.empty h3 { font-size: 1rem; font-weight: 500; }
.week-day.empty .total { font-weight: 400; }

/* Phones: the nav links need the room more than the app name does */
@media (max-width: 575px) {
  header nav ul:first-child { display: none; }
  header nav { --pico-nav-element-spacing-horizontal: 0.3rem; }
  header nav ul:last-child { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  /* Icons only: the labels don't fit next to the page links. */
  header nav button.nav-button { padding: 0.35rem 0.5rem; }
  header nav button.nav-button .label { display: none; }
}

/* Wider screens: one line per entry */
@media (min-width: 768px) {
  .timer { grid-template-columns: 2fr 1fr 1fr auto; }
  .timer.running { grid-template-columns: 1fr auto auto; }
  .timer.running button { grid-column: auto; }
  .entry { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) 11rem 4rem 6.5rem; }
  .entry-actions { justify-content: flex-end; }
  .entry.editing { grid-template-columns: 2fr 1fr 1fr; }
  .entry.editing .entry-actions, .entry.editing .error { grid-column: 1 / -1; }
  .project-row { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; }
  .project-row.editing, .project-new { grid-template-columns: 2fr 4rem 1fr auto auto; align-items: center; }
  .project-row.editing .error, .project-new .error { grid-column: 1 / -1; }
  .add-entry { grid-template-columns: 2fr 1fr 1fr; }
  .preset-form { grid-template-columns: 4rem 2fr 1fr 1fr auto; align-items: center; }
  .preset-form .error { grid-column: 1 / -1; }
}
