/* tokens.css is linked separately by index.html rather than @import-ed here.
   A CSS @import is discovered only after this file has been fetched and
   parsed, so it serialises two round trips before anything can paint -- and
   the file it would be waiting on is the one that defines every colour. */

/* The shell: app frame, navigation, and the controls the first module needs.

   Hand-written and token-based rather than utility classes, for one specific
   reason that is worth stating once. PomoDone loads @tailwindcss/forms, and its
   control audit then has to hand-model that plugin's base layer and assert the
   model has not gone stale -- forty lines of test that exist only because a
   plugin loaded after the stylesheet wins specificity ties. Writing the dozen
   controls this app uses directly deletes that whole apparatus. */

* { box-sizing: border-box; }

/* The `hidden` attribute has to keep working.

   Its effect comes from the UA stylesheet's `[hidden] { display: none }`, which
   any author rule setting `display` beats on specificity. So the moment a
   component gets `display: inline-block` or `display: grid`, every element of
   that kind marked hidden becomes visible again -- and nothing in the markup or
   the JavaScript looks wrong, because both are correct. One rule, at the top,
   for every component in the app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  /* dvh, not vh: on mobile Safari vh is the tallest the viewport ever gets, so
     a 100vh shell is permanently taller than the screen and the bottom bar sits
     below the fold. */
  height: 100dvh;
}

body {
  background: var(--page);
  color: var(--ink-1);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Numerals in a column have to line up, or scanning a list of money is
   impossible. Applied to every amount, date, quantity and id. */
.tnum { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ------------------------------------------------------------------ frame */

.app {
  display: grid;
  height: 100dvh;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "sidebar header" "sidebar main";
}

.app__header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}

.app__sidebar {
  grid-area: sidebar;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  overflow-y: auto;
}

.app__main {
  grid-area: main;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -.01em;
  padding: 4px 8px 14px;
}
.brand img { width: 26px; height: 26px; border-radius: 7px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-control);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
}
.nav__link:hover { background: var(--row-hover); color: var(--ink-1); }
.nav__link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.app__bottom { display: none; }

/* ------------------------------------------------------------- mobile */

@media (max-width: 767px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "header" "main" "bottom";
  }
  .app__sidebar { display: none; }

  /* Four slots and a More sheet, rather than a sideways-scrolling strip.
     PomoDone learned this the hard way: nine tabs in a scrolling strip left the
     last three unreachable because nothing indicated they were there. With
     fifteen modules that failure is guaranteed, so the sheet is not optional. */
  .app__bottom {
    grid-area: bottom;
    display: grid;
    grid-auto-flow: column;
    background: var(--surface-1);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app__bottom a, .app__bottom button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 9px 4px;
    font-size: 11px;
    color: var(--ink-2);
    text-decoration: none;
    background: none;
    border: 0;
    font-family: inherit;
  }
  .app__bottom [aria-current="page"] { color: var(--accent); }
}

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--field-h);
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface-1);
  color: var(--ink-1);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  /* A button's label is short and its meaning depends on reading it in one
     piece; wrapping "New contact" onto two lines makes the control taller than
     everything beside it and looks broken. */
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn--primary:hover { filter: brightness(1.07); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--row-hover); color: var(--ink-1); }

.field {
  width: 100%;
  min-height: var(--field-h);
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface-1);
  color: var(--ink-1);
  font: inherit;
  /* Below 768px every text control must be at least 16px or mobile Safari
     zooms the page on focus and never zooms back out. */
  font-size: 16px;
}
@media (min-width: 768px) { .field { font-size: 14px; } }
.field::placeholder { color: var(--ink-3); }

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 4px;
}

/* ------------------------------------------------------------------ pieces */

.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.page__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page__title { margin: 0; font-size: 20px; font-weight: 680; letter-spacing: -.015em; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: var(--font-size-table); }
.table th {
  position: sticky;
  top: 0;
  background: var(--surface-sticky);
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  padding: 8px var(--cell-pad-x);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  height: var(--row-h);
  padding: 0 var(--cell-pad-x);
  border-bottom: 1px solid var(--line-table);
}
.table tbody tr:hover { background: var(--row-hover); }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-2);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: color-mix(in srgb, var(--state-open) 12%, transparent);
  color: var(--state-open);
}
.badge--offline {
  background: color-mix(in srgb, var(--state-stale) 14%, transparent);
  color: var(--state-stale);
}

.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-overlay);
  color: var(--ink-1);
  box-shadow: var(--shadow-pop);
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(8, 11, 16, .45); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------------------------------------------------------------- utilities

   A deliberately tiny set, and the reason they exist rather than inline
   `style` attributes is the Content-Security-Policy: style-src 'self' blocks
   a style attribute in markup just as script-src blocks an inline script. The
   alternative was adding 'unsafe-inline' to style-src, which is a real
   loosening bought for the sake of half a dozen one-line rules. Setting
   element.style from JavaScript is CSSOM rather than an inline style and stays
   allowed, so dynamic positioning does not need anything here. */

.u-w-260 { max-width: 260px; }
.u-w-320 { max-width: 320px; }
.u-mt { margin-top: 12px; }
.u-right { text-align: right; }
.u-pad { padding: 18px; }
.u-end { justify-content: flex-end; }
.u-err { color: var(--critical); margin: 0; }
.u-noscript { padding: 24px; }
.dialog__title { margin: 0 0 4px; font-size: 17px; }
.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 99;
  box-shadow: var(--shadow-pop);
}
