/* go-tasker application styles.
 *
 * Built on Open Props design tokens (vendored at /static/vendor/
 * open-props.min.css). Layout is mobile-first for ~360 px screens with a
 * bottom tab bar; at --breakpoint-desktop the nav becomes a sidebar.
 *
 * Theming (FR 29): all colors flow through the semantic custom properties
 * below. The server renders <html data-theme="auto|light|dark"> from the
 * theme cookie; "auto" follows prefers-color-scheme.
 */

/* ---------- semantic tokens: light is the base ---------- */

:root {
  color-scheme: light dark;

  --surface-1: var(--gray-1);      /* page background */
  --surface-2: var(--gray-0);      /* cards, rows, bars */
  --surface-3: var(--gray-2);      /* hover, chips */
  --text-1: var(--gray-9);
  --text-2: var(--gray-6);
  --brand: var(--indigo-7);
  --brand-contrast: var(--gray-0);
  --border: var(--gray-3);
  --danger: var(--red-7);

  /* Subtle urgency accent scale for task rows (FR 8). */
  --urgency-none: var(--gray-4);
  --urgency-low: var(--blue-5);
  --urgency-med: var(--orange-6);
  --urgency-high: var(--red-6);

  --nav-size: 3.5rem;              /* bottom bar height / tap target floor */
}

[data-theme="light"] { color-scheme: light; }

/* Dark values, applied when forced ... */
[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: var(--gray-10);
  --surface-2: var(--gray-9);
  --surface-3: var(--gray-8);
  --text-1: var(--gray-1);
  --text-2: var(--gray-5);
  --brand: var(--indigo-4);
  --brand-contrast: var(--gray-10);
  --border: var(--gray-8);
  --danger: var(--red-4);
  --urgency-none: var(--gray-7);
  --urgency-low: var(--blue-4);
  --urgency-med: var(--orange-4);
  --urgency-high: var(--red-4);
}

/* ... and when the OS prefers dark while the theme is "auto". Keep this
 * block identical to [data-theme="dark"] above. */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    color-scheme: dark;
    --surface-1: var(--gray-10);
    --surface-2: var(--gray-9);
    --surface-3: var(--gray-8);
    --text-1: var(--gray-1);
    --text-2: var(--gray-5);
    --brand: var(--indigo-4);
    --brand-contrast: var(--gray-10);
    --border: var(--gray-8);
    --danger: var(--red-4);
    --urgency-none: var(--gray-7);
    --urgency-low: var(--blue-4);
    --urgency-med: var(--orange-4);
    --urgency-high: var(--red-4);
  }
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-system-ui);
  font-size: var(--font-size-1);
  line-height: var(--font-lineheight-3);
  background: var(--surface-1);
  color: var(--text-1);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: var(--font-weight-7); }
a { color: var(--brand); text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- app shell: mobile-first ---------- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--layer-2);
  display: flex;
  align-items: center;
  gap: var(--size-2);
  padding: var(--size-2) var(--size-3);
  background: var(--surface-2);
  border-bottom: var(--border-size-1) solid var(--border);
}

.topbar h1 {
  flex: 1;
  font-size: var(--font-size-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;              /* finger-sized (FR 30) */
  min-height: 2.75rem;
  border-radius: var(--radius-2);
  color: var(--text-2);
}
.iconbtn:hover { background: var(--surface-3); color: var(--text-1); }
.iconbtn svg { width: 1.4rem; height: 1.4rem; }
.iconbtn[disabled] { opacity: 0.4; cursor: not-allowed; }

main {
  flex: 1;
  width: 100%;
  max-width: 48rem;
  margin-inline: auto;
  padding: var(--size-3);
  /* Keep content clear of the bottom tab bar. */
  padding-bottom: calc(var(--nav-size) + env(safe-area-inset-bottom) + var(--size-3));
}

/* ---------- navigation: bottom tab bar on mobile ---------- */

.nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--layer-3);
  display: flex;
  justify-content: space-around;
  background: var(--surface-2);
  border-top: var(--border-size-1) solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav a, .nav .more-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 4rem;
  height: var(--nav-size);
  font-size: var(--font-size-0);
  color: var(--text-2);
  border-radius: var(--radius-2);
  cursor: pointer;
}
.nav a:hover, .nav .more-toggle:hover { color: var(--text-1); }
.nav a[aria-current="page"] { color: var(--brand); font-weight: var(--font-weight-6); }
.nav svg { width: 1.3rem; height: 1.3rem; }

.nav-section { display: contents; }
.nav-label { display: none; }      /* sidebar-only section headings */

/* "More" popover above the tab bar */
.nav-more { position: relative; }
.nav-more .more-panel {
  position: absolute;
  bottom: calc(var(--nav-size) + var(--size-2));
  right: 0;
  min-width: 11rem;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: var(--border-size-1) solid var(--border);
  border-radius: var(--radius-3);
  box-shadow: var(--shadow-3);
  padding: var(--size-1);
}
.nav-more .more-panel a {
  flex-direction: row;
  justify-content: flex-start;
  gap: var(--size-2);
  height: 2.75rem;
  min-width: 0;
  padding-inline: var(--size-2);
  font-size: var(--font-size-1);
}

/* ---------- navigation: sidebar on desktop ---------- */

@media (min-width: 48rem) {
  .app {
    display: grid;
    grid-template-columns: 14rem 1fr;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "nav topbar"
      "nav capture"
      "nav flash"
      "nav main";
  }
  .topbar { grid-area: topbar; }
  /* Without explicit areas these auto-place into implicit rows below
   * main — off-screen, which made the quick-capture panel look broken
   * on desktop. */
  .capture-panel { grid-area: capture; }
  .flash { grid-area: flash; }
  main { grid-area: main; padding-bottom: var(--size-3); }

  .nav {
    grid-area: nav;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    gap: var(--size-1);
    padding: var(--size-3) var(--size-2);
    border-top: none;
    border-right: var(--border-size-1) solid var(--border);
  }
  .nav a, .nav .more-toggle {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--size-2);
    width: 100%;
    height: 2.75rem;
    padding-inline: var(--size-2);
    font-size: var(--font-size-1);
  }
  .nav a[aria-current="page"] { background: var(--surface-3); }

  .nav-label {
    display: block;
    margin: var(--size-3) var(--size-2) var(--size-1);
    font-size: var(--font-size-0);
    text-transform: uppercase;
    letter-spacing: var(--font-letterspacing-2);
    color: var(--text-2);
  }
  /* Sidebar shows the "More" links inline; the popover disappears.
   * !important beats the inline display:none that data-show manages,
   * keeping the section visible no matter the toggle state. */
  .nav-more .more-toggle { display: none; }
  .nav-more .more-panel {
    position: static;
    border: none;
    box-shadow: none;
    background: none;
    padding: 0;
    min-width: 0;
    display: flex !important;
  }
}

/* ---------- task list fragments ---------- */

.task-list {
  display: flex;
  flex-direction: column;
  gap: var(--size-2);
  padding: 0;
  margin: 0;
  list-style: none;
}

.task-row {
  display: flex;
  align-items: center;
  gap: var(--size-2);
  padding: var(--size-2) var(--size-3);
  background: var(--surface-2);
  border: var(--border-size-1) solid var(--border);
  border-left: var(--border-size-3) solid var(--urgency-none);
  border-radius: var(--radius-2);
}
.task-row.urgency-low  { border-left-color: var(--urgency-low); }
.task-row.urgency-med  { border-left-color: var(--urgency-med); }
.task-row.urgency-high { border-left-color: var(--urgency-high); }

.task-body { flex: 1; min-width: 0; }
.task-desc { overflow-wrap: anywhere; }

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-1);
  margin-top: var(--size-1);
  font-size: var(--font-size-0);
  color: var(--text-2);
}

.task-annotations {
  margin: var(--size-1) 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--font-size-0);
  color: var(--text-2);
}
.task-annotations li {
  overflow-wrap: anywhere;
  padding-block: var(--size-1);
}
.annotation-date {
  margin-right: var(--size-1);
  opacity: 0.75;
}
.task-annotations a {
  color: var(--brand);
  text-decoration: underline;
  /* Inline links inside a small-text list still need a usable tap area. */
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  margin-block: calc(-1 * var(--size-1));
}
.chip {
  padding: 0 var(--size-2);
  border-radius: var(--radius-round);
  background: var(--surface-3);
  line-height: var(--font-lineheight-4);
}
/* Tag and project chips link to their filter views; keep the chip look. */
a.chip { color: var(--text-2); }
a.chip:hover { color: var(--text-1); text-decoration: underline; }
.chip.project, a.chip.project { color: var(--brand); }
.chip.due-overdue { color: var(--danger); font-weight: var(--font-weight-6); }

.empty-state {
  padding: var(--size-7) var(--size-3);
  text-align: center;
  color: var(--text-2);
}

/* ---------- forms & login ---------- */

input[type="text"], input[type="password"] {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--size-1) var(--size-2);
  font: inherit;
  color: var(--text-1);
  background: var(--surface-1);
  border: var(--border-size-1) solid var(--border);
  border-radius: var(--radius-2);
}
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn-primary {
  min-height: 2.75rem;
  padding-inline: var(--size-4);
  background: var(--brand);
  color: var(--brand-contrast);
  border-radius: var(--radius-2);
  font-weight: var(--font-weight-6);
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--size-3);
}
.login-card {
  width: 100%;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  gap: var(--size-3);
  padding: var(--size-5);
  background: var(--surface-2);
  border: var(--border-size-1) solid var(--border);
  border-radius: var(--radius-3);
  box-shadow: var(--shadow-2);
}
.login-card form { display: flex; flex-direction: column; gap: var(--size-2); }

.form-error { margin: 0; color: var(--danger); }

/* ---------- task actions (5.0) ---------- */

.task-actions {
  display: flex;
  align-items: center;
  gap: var(--size-1);
  flex-shrink: 0;
}
.task-actions .iconbtn.done:hover { color: var(--urgency-low); }
.row-form { display: contents; }

/* ---------- quick capture ---------- */

.capture-panel {
  padding: var(--size-2) var(--size-3);
  background: var(--surface-2);
  border-bottom: var(--border-size-1) solid var(--border);
}
.capture-form {
  display: flex;
  align-items: center;
  gap: var(--size-2);
  flex-wrap: wrap;
}
.capture-form input[type="text"] { flex: 1; min-width: 12rem; }
.capture-note { color: var(--text-2); font-size: var(--font-size-0); }
.capture-note.error { color: var(--danger); }
.capture-full {
  margin-left: auto;
  font-size: var(--font-size-0);
  color: var(--brand);
  text-decoration: none;
}
.capture-full:hover { text-decoration: underline; }

/* ---------- search ---------- */

.search-form {
  display: flex;
  align-items: center;
  gap: var(--size-2);
  padding: var(--size-2) var(--size-3);
}
.search-form input[type="search"] { flex: 1; min-width: 12rem; }

.btn {
  min-height: 2.75rem;
  padding-inline: var(--size-4);
  background: var(--brand);
  color: var(--brand-contrast);
  border-radius: var(--radius-2);
  font-weight: var(--font-weight-6);
}
.btn-secondary {
  background: var(--surface-3);
  color: var(--text-1);
}
.btn-danger {
  background: var(--danger);
  color: var(--brand-contrast);
}

/* ---------- delete confirmation ---------- */

.task-row.confirm-delete { display: block; }
.confirm-delete-form {
  display: flex;
  flex-direction: column;
  gap: var(--size-3);
}
.confirm-delete-text { margin: 0; overflow-wrap: anywhere; }

/* ---------- flash messages ---------- */

.flash { padding-inline: var(--size-3); }
.flash-error {
  padding: var(--size-2) var(--size-3);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-bottom: var(--border-size-1) solid var(--border);
}

/* ---------- inline edit form ---------- */

.task-row.editing { display: block; }
.edit-form {
  display: flex;
  flex-direction: column;
  gap: var(--size-2);
}
.edit-form label {
  display: flex;
  flex-direction: column;
  gap: var(--size-1);
  font-size: var(--font-size-0);
  color: var(--text-2);
}
.edit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--size-2);
}
@media (min-width: 30rem) {
  .edit-grid { grid-template-columns: 1fr 1fr; }
}
.edit-actions { display: flex; gap: var(--size-2); }

/* ---------- workflow tag chips ---------- */

.std-tags {
  border: none;
  margin: 0;
  padding: 0;
}
.std-tags legend {
  font-size: var(--font-size-0);
  color: var(--text-2);
  margin-bottom: var(--size-1);
  padding: 0;
}
.std-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
}
.chip-toggle {
  position: relative;
  display: inline-flex;
}
.chip-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip-toggle span {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding-inline: var(--size-3);
  border: var(--border-size-1) solid var(--border);
  border-radius: var(--radius-round);
  background: var(--surface-3);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.chip-toggle input:checked + span {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}
.chip-toggle input:focus-visible + span {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ---------- add-task form ---------- */

.add-form {
  display: flex;
  flex-direction: column;
  gap: var(--size-3);
  max-width: 32rem;
  padding: var(--size-3);
}
.add-form label {
  display: flex;
  flex-direction: column;
  gap: var(--size-1);
  font-size: var(--font-size-0);
  color: var(--text-2);
}
.form-note { color: var(--text-2); }

/* ---------- projects tree ---------- */

.project-tree {
  list-style: none;
  padding: 0;
  margin: 0;
}
.project-tree .project-tree {
  padding-left: var(--size-5);
  border-left: var(--border-size-1) solid var(--border);
  margin-left: var(--size-3);
}
.project-tree > li > a {
  display: flex;
  align-items: center;
  gap: var(--size-2);
  min-height: 2.75rem;
  padding: var(--size-1) var(--size-3);
  color: var(--text-1);
  text-decoration: none;
  border-radius: var(--radius-2);
}
.project-tree > li > a:hover { background: var(--surface-2); }
.project-tree svg { width: 1.1rem; height: 1.1rem; color: var(--text-2); }
.project-tree .chip.count { margin-left: auto; }

.backlink { padding: var(--size-2) var(--size-3) 0; margin: 0; }
.backlink a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--brand);
  text-decoration: none;
}
.backlink a:hover { text-decoration: underline; }

/* ---------- completed range selector ---------- */

.range-chips {
  display: flex;
  gap: var(--size-2);
  padding: var(--size-2) var(--size-3);
}
.range-chips a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding-inline: var(--size-3);
  border-radius: var(--radius-round);
  background: var(--surface-3);
  color: var(--text-2);
  text-decoration: none;
  font-size: var(--font-size-0);
}
.range-chips a[aria-current="page"] {
  background: var(--brand);
  color: var(--brand-contrast);
}

/* ---------- sync states ---------- */

.sync-ctl { display: contents; }
.sync-ok .iconbtn { color: var(--urgency-low); }
.sync-fail .iconbtn { color: var(--danger); }
.iconbtn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
