/* App-shell layout: header and banner take their natural height, the board
   fills the rest of the viewport. `.board`'s grid rows then have a genuinely
   bounded height to lay out against, so overflowing quadrants scroll
   internally (task.list's `overflow-y: auto`) instead of growing the whole
   page and every quadrant along with it — see the matrix-board spec's
   "Quadrant overflow" requirement. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4) var(--space-2);
}

.banner-container {
  flex: 0 0 auto;
}

.app-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-size: var(--font-size-app-title);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

@media (max-width: 767.98px) {
  .app-title {
    font-size: 1.6rem;
  }
}

.app-logo {
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
}

.app-header-controls {
  display: flex;
  gap: var(--space-1);
}

/* Quiet icon-only buttons (design D21). */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--color-hover);
  color: var(--color-text);
}

.icon-button .icon {
  width: 20px;
  height: 20px;
}

/* The theme button holds all three icons; show the one for the current preference. */
#theme-button .icon {
  display: none;
}

#theme-button[data-pref='system'] .icon-monitor,
#theme-button[data-pref='light'] .icon-sun,
#theme-button[data-pref='dark'] .icon-moon {
  display: block;
}

.banner-container:not(:empty) {
  padding: var(--space-2) var(--space-4);
}

.banner {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 0.9rem;
}

.banner-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    'plan do'
    'drop limit';
  gap: var(--space-4);
  padding: var(--space-4);
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
}

:root[data-layout='urgent-left'] .board {
  grid-template-areas:
    'do plan'
    'limit drop';
}

.axis-header {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-axis);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.axis-col-not-urgent {
  grid-area: colN;
}

.axis-col-urgent {
  grid-area: colU;
}

.axis-row-top,
.axis-row-bottom {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.axis-row-top {
  grid-area: rowT;
}

.axis-row-bottom {
  grid-area: rowB;
}

@media (min-width: 768px) {
  /* Pin the page to the viewport height so `.board`'s flex sizing (above)
     resolves to a real, bounded value instead of growing with content —
     that's what makes overflowing quadrants scroll internally rather than
     stretching the whole page and every quadrant along with them. */
  body {
    height: 100vh;
    overflow: hidden;
  }

  .board {
    grid-template-columns: 2rem 1fr 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
      '.    colN colU'
      'rowT plan do'
      'rowB drop limit';
  }

  :root[data-layout='urgent-left'] .board {
    grid-template-areas:
      '.    colU colN'
      'rowT do   plan'
      'rowB limit drop';
  }
}

.quadrant {
  --add-row-height: 32px;
  grid-area: var(--quadrant-area, auto);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  /* See-through: only Do (below) gets a surface. */
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

/* Do is the one card with a surface, raised by a large shadow; the other
   three are see-through outlines on the page. No outline, so it can't be mistaken for focus, and
   the same border width as the others, so its content lines up with theirs. */
.quadrant-do {
  --quadrant-area: do;
  background: var(--color-surface-do);
  box-shadow: var(--shadow-raised);
}

/* High contrast adds weight to Do's border on top of the shadow. */
:root[data-contrast='high'] .quadrant-do {
  border-color: var(--color-border-strong);
  box-shadow: inset 0 0 0 1px var(--color-border-strong), var(--shadow-raised);
}

.quadrant-plan {
  --quadrant-area: plan;
}

.quadrant-limit {
  --quadrant-area: limit;
}

.quadrant-drop {
  --quadrant-area: drop;
}

.quadrant-header {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: var(--space-2);
  row-gap: 2px;
  margin-bottom: var(--space-3);
}

.quadrant-title {
  margin: 0;
  font-size: var(--font-size-quadrant-title);
  font-weight: 700;
  line-height: 1.2;
}

.quadrant-do .quadrant-title {
  font-weight: 800;
}

.quadrant-subtitle {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-quadrant-subtitle);
}

.task-list {
  flex: 1;
  min-height: 3rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Rows bleed into the quadrant's padding by their own inline padding, so
     checkboxes line up with the heading while hover and focus still get a
     full-width row. */
  margin: 0 calc(-1 * var(--space-2));
  padding: var(--space-1) 0;
  scrollbar-color: var(--color-scrollbar) transparent;
}

.add-task-button {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  margin-top: var(--space-2);
  /* Same box as the add form's input that replaces it: same left edge, same
     height, and the label starts where typed text will. */
  height: var(--add-row-height);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  padding: 0 var(--space-2);
  font-size: var(--font-size-meta);
}

.add-task-button:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

:root[data-contrast='high'] .add-task-button {
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

/* One line — input, Add, Cancel — the same height as the button it replaces,
   so opening it doesn't move anything. The error wraps onto its own line. */
.add-form {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}

.add-form input[type='text'] {
  flex: 1 1 6rem;
  min-width: 0;
  height: var(--add-row-height);
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.add-form .field-error {
  order: 1;
  flex-basis: 100%;
}

.add-form-actions {
  display: flex;
  gap: var(--space-1);
}

.add-form input[type='text'][aria-invalid='true'] {
  border-color: var(--color-danger);
}

.add-form-actions button {
  height: var(--add-row-height);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  font-size: var(--font-size-meta);
}

.add-form-actions button[type='submit'] {
  background: var(--color-inverse-bg);
  border-color: var(--color-inverse-bg);
  color: var(--color-inverse-text);
}

.completed-toggle {
  margin-top: var(--space-2);
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  text-decoration: underline;
  padding: var(--space-1) 0;
  min-height: 24px;
}

.archived-list {
  margin: var(--space-1) calc(-1 * var(--space-2)) 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 12rem;
  overflow-y: auto;
}

@media (max-width: 767.98px) {
  .axis-header {
    display: none;
  }

  /* Priority order in both layout directions (the urgent-left selector
     above is more specific, so it is matched here explicitly). */
  .board,
  :root[data-layout='urgent-left'] .board {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-template-areas:
      'do'
      'plan'
      'limit'
      'drop';
  }

  .quadrant {
    min-height: 16rem;
  }

  /* Stacked layout: let the page grow with its content and scroll as a
     whole. Squeezing the board into the viewport height (as the wide layout
     does) made the quadrants overflow it, which lost the board's bottom
     padding and turned <body> into a nested scroller. */
  html,
  body {
    height: auto;
  }

  body {
    min-height: 100dvh;
  }

  .board {
    flex: 0 0 auto;
    min-height: auto;
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  }
}

html,
body {
  overflow-x: hidden;
}
