/*
  Rules:
  - Use flex and grid for layout. Use the inline and stack classes to align items.
  - Use rem for sizes. Borders and outlines use px.
  - Use HSL for colours. Use the colour tokens below.
  - Do not use margin. Use gap and padding.
*/

:root {
  --color-bg: light-dark(hsl(60, 11%, 96%), hsl(150, 5%, 8%));
  --color-panel: light-dark(hsl(0, 0%, 100%), hsl(160, 5%, 12%));
  --color-text: light-dark(hsl(210, 6%, 12%), hsl(90, 4%, 90%));
  --color-muted: light-dark(hsl(213, 5%, 41%), hsl(150, 3%, 64%));
  --color-border: light-dark(hsl(60, 6%, 88%), hsl(156, 5%, 19%));
  --color-brand: light-dark(hsl(166, 56%, 28%), hsl(161, 43%, 60%));
  --color-brand-alt: light-dark(hsl(166, 56%, 20%), hsl(161, 43%, 70%));
  --color-brand-soft: light-dark(hsl(159, 33%, 92%), hsl(161, 28%, 16%));
  --color-warn: light-dark(hsl(35, 100%, 30%), hsl(36, 73%, 59%));
  --color-warn-soft: light-dark(hsl(37, 79%, 92%), hsl(37, 45%, 16%));
  --color-error: light-dark(hsl(7, 58%, 40%), hsl(8, 75%, 71%));
  --color-edge: light-dark(hsl(0, 0%, 0%, 0.08), hsl(0, 0%, 100%, 0.08));
  --color-shadow: light-dark(hsl(0, 0%, 0%, 0.1), hsl(0, 0%, 0%, 0.5));
  --color-backdrop: hsl(0, 0%, 0%, 0.45);
  --easing-base: cubic-bezier(0.2, 1.75, 0.5, 0.6);
  --font-stack: system-ui, sans-serif;
  --font-size: clamp(1rem, 3vw, 1.25rem);
  --font-size-small: 0.75rem;
  --font-size-note: 0.875rem;
  --radius: 0.375rem;
  --radius-large: 0.5rem;
  /* A 1px ring as the border. It blends with the drop shadow, thus the edge is darker at the bottom. */
  --shadow-box: 0 0 0 1px var(--color-edge), 0 1px 3px var(--color-shadow);
  --shadow-float: 0 0 0 1px var(--color-edge), 0 var(--size-half) var(--size-2x) var(--color-shadow);
  --size-base: 0.75rem;
  --size-half: 0.375rem;
  --size-quarter: 0.1875rem;
  --size-2x: 1.5rem;
  --size-4x: 3rem;

  color-scheme: light dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  overflow-wrap: break-word;
}

html {
  font-family: var(--font-stack);
  font-size: var(--font-size);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top);
  -webkit-font-smoothing: antialiased;
}

body:has(dialog[open]) {
  overflow: hidden;
}

::selection {
  background: var(--color-brand);
  color: var(--color-bg);
}

svg {
  flex-shrink: 0;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

button {
  all: unset;
  line-height: 1;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.6s var(--easing-base), color 0.1s ease-out;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;

  svg {
    pointer-events: none;
  }

  &.icon {
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    color: var(--color-brand);
  }

  &.icon:hover, &.icon:focus-visible {
    border-color: var(--color-brand-alt);
  }
}

button:not(:disabled):hover,
button:not(:disabled):focus-visible {
  transform: scale(1.04);
}

button:not(:disabled):active {
  transform: scale(0.97, 1.04);
}

/* "all: unset" removes the browser focus ring. */
button:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

/* Inline and Stack layout */
[class^='inline'],
[class*=' inline'],
[class^='stack'],
[class*=' stack'] {
  --gap: var(--size-base);
  display: flex;
  gap: var(--gap);
}

ul[class] {
  list-style: none;
  padding: 0;
}

[class^='inline'],
[class*=' inline'] {
  align-items: center;
  justify-content: flex-start;
}

[class^='stack'],
[class*=' stack'] {
  flex-direction: column;
}

[class^='inline'] > [class^='stack'] {
  flex: 1;
}

.inline-zero,
.stack-zero {
  display: inline-flex;
  gap: 0;
}

.inline-quarter,
.stack-quarter {
  --gap: var(--size-quarter);
}

.inline-half,
.stack-half {
  --gap: var(--size-half);
}

.inline-2x,
.stack-2x {
  --gap: var(--size-2x);
}

.inline-4x,
.stack-4x {
  --gap: var(--size-4x);
}

.inline-between {
  justify-content: space-between;
}

.inline-wrap {
  flex-wrap: wrap;
}

.align-top {
  align-items: flex-start;
  align-self: flex-start;
}

/* Elements */
a {
  color: var(--color-brand);
}

h1 {
  font-size: 1.75rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.125rem;
}

select, input, textarea {
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--size-half) var(--size-base);
}

textarea {
  resize: vertical;
}

button {
  padding: var(--size-half) var(--size-base);
  border: 1px solid var(--color-brand);
  border-radius: var(--radius);
  background: var(--color-brand);
  color: var(--color-panel);
}

button.secondary {
  background: none;
  color: var(--color-muted);
  border-color: var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: var(--size-half) var(--size-base);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-note);
}

th {
  color: var(--color-muted);
  font-weight: 600;
  font-size: var(--font-size-small);
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tr.self td {
  font-weight: 650;
}

td {
  line-height: 1.5;
}

td .title {
  font-weight: 600;
  color: var(--color-text);
}

dialog {
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  max-width: 30rem;
  border: 0;
  padding: var(--size-2x);
  color: var(--color-text);

  h2 {
    font-size: 1.25rem;
  }
}

dialog::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(3px);
}

dialog .actions {
  justify-content: flex-end;
  padding-top: var(--size-base);
}

/* Boxes. The .scroll box holds a table. */
.card, .login, .stat, .empty, .scroll {
  background: var(--color-panel);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-box);
}

dialog, .menu .items {
  background: var(--color-panel);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-float);
}

/* Top bar */
.top {
  padding: var(--size-half) var(--size-2x);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-panel);

  a {
    text-decoration: none;
    color: var(--color-muted);
    padding: var(--size-quarter)
  }

  a.on {
    color: var(--color-text);
    font-weight: 600;
  }
}

.brand {
  flex-grow: 1;
  font-weight: 700;
  font-size: 1rem;

  img {
    height: 2.5rem;
  }
}

.search input {
  width: 100%;
}

.menu {
  position: relative;
}

.menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  padding: var(--size-quarter);
  border-radius: var(--radius);
  color: var(--color-muted);
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu summary:hover,
.menu[open] summary {
  color: var(--color-text);
  background: var(--color-bg);
}

.menu .items {
  position: absolute;
  right: 0;
  top: calc(100% + var(--size-half));
  z-index: 10;
  min-width: 9rem;
  padding: var(--size-half);

  a, button {
    justify-content: flex-start;
    padding: var(--size-half) var(--size-base);
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--color-text);
    font-size: var(--font-size-note);
    line-height: 1.5;
  }

  a:hover, button:hover {
    background: var(--color-bg);
  }
}

/* Page */
.page {
  grid-row: 2;
  width: 100%;
  max-width: 60rem;
  justify-self: center;
  padding: var(--size-2x) var(--size-base) var(--size-4x);
}

.page:has(> .login) {
  justify-content: center;
}

.page > h2 {
  padding-top: var(--size-base);
}

.sub {
  color: var(--color-muted);
  font-size: 1.125rem;
}

.count {
  font-weight: 600;
}

.note {
  font-size: var(--font-size-note);
  color: var(--color-muted);
}

.error {
  color: var(--color-error);
}

.empty {
  color: var(--color-muted);
  padding: var(--size-2x);
  text-align: center;
}

.nowrap {
  white-space: nowrap;
}

.scroll {
  overflow-x: auto;
}



/* Omni-bar. The input text is transparent. The mirror behind it shows the same text, with the tokens in colour. */
.omni-box {
  position: relative;

  input, .omni-mirror {
    width: 100%;
    padding: var(--size-half) var(--size-base);
    border: 1px solid transparent;
    font: inherit;
    letter-spacing: normal;
    white-space: pre;
  }

  input {
    position: relative;
    background: transparent;
    border-color: var(--color-border);
    color: transparent;
    caret-color: var(--color-text);
  }

  input::placeholder {
    color: var(--color-muted);
  }

  input:focus {
    outline: 2px solid var(--color-brand);
    outline-offset: -1px;
  }

  .omni-mirror {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--color-panel);
    color: var(--color-text);
    pointer-events: none;
  }
}

.omni .k {
  color: var(--color-muted);
}

.omni .v {
  color: var(--color-brand);
}

/* Bold only in the list. Bold in the mirror makes the text wider than the input text, thus the caret is in the wrong place. */
.omni-pop .v {
  font-weight: 600;
}

.omni .v.bad {
  color: var(--color-error);
  text-decoration: underline wavy;
}

.omni-pop {
  position: absolute;
  top: calc(100% + var(--size-half));
  left: 0;
  z-index: 10;
  width: min(26rem, 100%);
  max-height: min(24rem, 60vh);
  overflow-y: auto;
  padding: var(--size-half);
  background: var(--color-panel);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-float);
  font-size: var(--font-size-note);
}

.omni-head {
  padding: var(--size-half) var(--size-base) var(--size-quarter);
  font-size: var(--font-size-small);
  font-weight: 600;
  color: var(--color-muted);
}

.omni-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--size-base);
  padding: var(--size-half) var(--size-base);
  border-radius: var(--radius);
  cursor: pointer;

  .note {
    text-align: right;
  }
}

.omni-item:hover, .omni-item.on {
  background: var(--color-bg);
}

.omni-toggles {
  font-size: var(--font-size-note);
}

.check {
  cursor: pointer;

  input {
    accent-color: var(--color-brand);
    width: 1rem;
    height: 1rem;
  }
}

.login {
  width: min(100%, 17rem);
  align-self: center;
  padding: var(--size-2x);

  img {
    height: 2.5rem;
    width: auto;
  }
}

/* Cards */
.card {
  position: relative;
  padding: var(--size-base) var(--size-2x);

  .title {
    font-size: 1.125rem;
    font-weight: 650;
    line-height: 1.3;
    color: var(--color-text);
    text-decoration: none;
  }

  .title:hover {
    color: var(--color-brand);
    text-decoration: underline;
  }

  .body {
    font-size: var(--font-size-note);
    color: var(--color-muted);
    white-space: pre-line;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
  }

  .summary {
    font-size: var(--font-size-note);
  }

  .summary ul {
    padding-left: var(--size-base);
    color: var(--color-muted);
  }
}

.meta {
  --gap: var(--size-quarter) var(--size-base);
  font-size: var(--font-size-note);
  color: var(--color-muted);
}

.tags {
  --gap: var(--size-half);
}

.tag {
  font-size: var(--font-size-small);
  padding: 0.1rem var(--size-half);
  border-radius: 99rem;
  background: var(--color-brand-soft);
  color: var(--color-brand);
}

.tag.warn {
  background: var(--color-warn-soft);
  color: var(--color-warn);
}

a.tag {
  text-decoration: none;
}

a.tag:hover {
  outline: 1px solid currentColor;
}

a.tag.on {
  outline: 2px solid currentColor;
}

.prio, .pill {
  font-weight: 600;
  padding: 0 var(--size-half);
  border-radius: var(--size-quarter);
  width: fit-content;
}

.prio.high {
  background: var(--color-brand);
  color: var(--color-panel);
}

.prio.medium,
.pill.done {
  background: var(--color-brand-soft);
  color: var(--color-brand);
}

.prio.low {
  background: var(--color-border);
  color: var(--color-muted);
}

.pill.acting {
  background: var(--color-warn-soft);
  color: var(--color-warn);
}

.pill.dismissed {
  background: var(--color-border);
  color: var(--color-muted);
}

/* Triage. The buttons are at the bottom of the card. */
.triage {
  border-top: 1px solid var(--color-border);
  padding-top: var(--size-half);
  font-size: var(--font-size-note);

  button {
    padding: var(--size-quarter) var(--size-base);
    font-size: var(--font-size-note);
  }

  .pill {
    font-size: var(--font-size-small);
  }
}

.triage-note {
  color: var(--color-text);
  white-space: pre-line;
  font-size: var(--font-size-note);
}

td .pill {
  display: inline-block;
  font-size: var(--font-size-small);
}

/* Tabs */
.tabs {
  --gap: var(--size-2x);
  border-bottom: 1px solid var(--color-border);

  a {
    padding: var(--size-half) 0;
    text-decoration: none;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
  }

  a.on {
    color: var(--color-text);
    font-weight: 600;
    border-bottom-color: var(--color-brand);
  }

  .sort {
    margin-inline-start: auto;
  }

  select {
    font-size: var(--font-size-note);
    padding: var(--size-quarter) var(--size-half);
  }
}

.pager {
  padding-top: var(--size-base);
}

/* Report */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: var(--size-base);
}

.stat {
  padding: var(--size-base);

  .value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
  }
}

@media print {
  .top, .no-print, dialog, .triage {
    display: none !important;
  }

  html {
    font-size: 12pt;
    color: hsl(0, 0%, 0%);
    background: hsl(0, 0%, 100%);
  }

  .page {
    padding: 0;
    max-width: none;
  }

  a {
    color: hsl(0, 0%, 0%);
  }
}
