/*
Advokator's own CSS, served as written: there is no build step.

daisyUI (static/vendor/daisyui-*.css, loaded first, made by `make daisyui`) brings the reset, the components the
templates use (the Makefile lists them), the colour classes text-*, bg-* and border-* of every theme colour in steps of
/10 with the hover: forms of the solid ones, and rounded-box/field/selector. tokens.css sets the theme and the site's
tokens; this file the element defaults and the pieces several pages share (components.css the interactive ones,
fonts.css the faces); each page's own layout is in the file its template loads in the page_css block (search.css,
chat.css, ...). Breakpoints: 40rem, 48rem, 64rem (chat.js's) and 80rem.

The cascade's order is declared before any stylesheet (web/base.html): daisyUI's `base` and `utilities`, then `site`.
- element defaults go in `base`, after daisyUI's reset, where daisyUI's components and colour classes still override
  them;
- every other rule of the site's is in `site`, which beats daisyUI whatever the specificity: so a class here should
  not set a property a template varies with a colour class, and a daisyUI component is adjusted through its own
  variables (--btn-color, --input-color, ...) rather than by overriding the properties its states set;
- CSS outside any layer is left for one-off overrides (and a script's inline style).
*/

@layer base {
  [hidden]:where(:not([hidden='until-found'])) { display: none !important; }
  *, ::after, ::before, ::backdrop, ::file-selector-button {
    border-color: var(--line);
  }
  /* a column as tall as the screen, so the footer sits at the bottom of a short page */
  body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background: var(--color-base-200);
    color: var(--color-base-content);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.005em;
    text-wrap: balance;
  }
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }
  /* links inside translated sentences carry no class, so they get the link look here */
  a:not([class]) {
    color: var(--color-primary);
    text-underline-offset: 3px;
    &:hover { text-decoration: underline; }
  }
  :focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }
  ::selection, mark {
    background: var(--mark);
    color: inherit;
  }
  [x-cloak] { display: none !important; }
  /* the search landmark: a block where a browser predates the element */
  search { display: block; }
  /* daisyUI mixes the placeholder in oklch and halves it again on a field: 4.8:1 here */
  ::placeholder { color: var(--subtle); }
  /* a work's title in a caption (account/base.html's quote) keeps the text's own style */
  cite { font-style: normal; }
}

@layer site {

  /* the search and chat screens pin the body to the viewport, so their panes scroll on their own */
  body.pinned { height: 100dvh; }
  @media (width >= 64rem) {
    body.pinned-lg { height: 100dvh; }
  }

  /* ---- daisyUI, adjusted ---- */

  /* daisyUI draws .card-border in base-200, the page's own grey here: a card on the page would lose its edge */
  .card-border { border-color: var(--line); }
  /* an outline badge (a status, a citation) takes a light line, not its full text colour */
  .badge-outline { border-color: color-mix(in oklab, currentColor 25%, transparent); }
  /* a badge may hold a whole court outcome, which wraps at phone width: it grows instead of spilling over its line */
  .badge { height: auto; min-height: var(--size); padding-block: 0.125rem; }
  /* a field's edge at 3:1 (--field-line); focused, it rings in the brand colour, where daisyUI rings it in the text's */
  :is(.input, .select, .textarea) { --input-color: var(--field-line); }
  :is(.input, .select, .textarea):is(:focus, :focus-within) { --input-color: var(--color-primary); }
  /* 16px on a touch screen: below that, iOS Safari zooms the page in on focus and stays zoomed */
  @media (pointer: coarse) {
    :is(.input, .select, .textarea) { font-size: 1rem; }
  }

  /* ---- small helpers ---- */

  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border-width: 0;
  }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabular { font-variant-numeric: tabular-nums; }
  .w-full { width: 100%; }
  /* a 1240px column with the page's side padding */
  .page {
    width: 100%;
    max-width: var(--page-width);
    margin-inline: auto;
    padding-inline: 1.5rem;
  }

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

  /* the small capitals over a title */
  .kicker {
    font-size: 0.75rem;
    line-height: 1.3333;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-primary);
  }

  /* a search hit or a listed act, on a .card; its heading's link stretches over it, so a click anywhere opens it */
  .result {
    position: relative;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
    transition: border-color 150ms, box-shadow 150ms;
    &:hover {
      border-color: var(--dot);
      box-shadow: var(--shadow-sm);
    }
  }
  /* what follows a result's kicker, after a dot */
  .result-meta {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted);
    &::before {
      content: '';
      display: inline-block;
      width: 3px;
      height: 3px;
      margin-inline-end: 0.625rem;
      border-radius: 50%;
      background: var(--dot);
      vertical-align: 0.3em;
    }
  }

  /* a case number or an article, on a .badge: every citation is set in mono */
  .ref {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.3333;
    font-weight: 500;
    color: var(--soft);
  }

  /* an act's state and area (laws/components/act_tags.html), under its search hit and in its reader */
  .act-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.125rem;
    &:empty { display: none; }
  }

  /* the sources' lists, in the chat's panel and on a predmet's page: a list's label (the chat's list of chats too), a
     count beside a heading, and a row's § or page (as an answer cites them) before its name and a line of detail */
  .list-heading {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.6875rem;
    line-height: 1.4545;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }
  .count-pill {
    min-width: 1.125rem;
    padding-inline: 0.3125rem;
    border-radius: 9999px;
    background: var(--color-base-200);
    color: var(--muted);
    text-align: center;
    font-size: 0.65625rem;
    letter-spacing: 0;
  }
  .source-icon {
    display: grid; flex: none; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 0.375rem;
    font-size: 0.875rem; font-weight: 600;
    & svg { width: 0.9375rem; height: 0.9375rem; }
  }
  .source-text {
    display: flex; flex-direction: column; min-width: 0;
    & > span:first-child { max-width: 100%; font-size: 0.8125rem; font-weight: 500; }
    & > span + span { font-size: 0.75rem; line-height: 1.3333; }
  }
  /* a decision's case number */
  .source-case { font-family: var(--font-mono); }

  /* HTML we do not write: a stored decision, an act, a chat answer. A long URL breaks rather than widening the page, and
     a wide table scrolls inside its own box (reflow at 320px). */
  .richtext {
    font-size: var(--text-read);
    line-height: 1.7;
    overflow-wrap: break-word;
    & :is(p, ul, ol, pre, blockquote, table, hr) { margin-bottom: 0.75rem; }
    & > :last-child { margin-bottom: 0; }
    & :is(h1, h2, h3, h4, h5, h6) {
      margin: 1.25rem 0 0.5rem;
      font-size: var(--text-lg);
      line-height: 1.375;
      font-weight: 600;
      letter-spacing: normal;
    }
    & > :first-child { margin-top: 0; }
    & :is(ul, ol) { padding-inline-start: 22px; }
    & ul { list-style: disc; }
    & ol { list-style: decimal; }
    & li + li { margin-top: 0.375rem; }
    & strong { font-weight: 600; }
    & a { color: var(--color-primary); text-decoration: underline; text-underline-offset: 3px; }
    & blockquote {
      border-inline-start: 2px solid color-mix(in oklab, var(--color-base-content) 25%, transparent);
      padding-inline-start: 0.875rem;
      color: var(--soft);
    }
    & code {
      border-radius: 0.25rem;
      background: var(--color-base-200);
      padding: 0.125rem 5px;
      font-family: var(--font-mono);
      font-size: 0.88em;
    }
    & pre {
      overflow-x: auto;
      border-radius: var(--radius-field);
      background: var(--color-base-200);
      padding: 0.75rem 0.875rem;
      & code { background: transparent; padding: 0; }
    }
    & table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: var(--text-sm); }
    & :is(td, th) { border: 1px solid var(--line); padding: 0.375rem 0.5rem; text-align: start; }

    /* the link after a citation in an answer (apps/chat/citations.py): an icon with no text of its own, so the copy
       button copies none; a law's is its § */
    & .cite {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 1.1em;
      height: 1.1em;
      margin-inline-start: 0.125rem;
      border-radius: 0.25rem;
      vertical-align: -0.15em;
      font-weight: 600;
      color: var(--color-primary);
      text-decoration: none;
      &:hover { background: color-mix(in oklab, var(--color-primary) 10%, transparent); }
      &.htmx-request { opacity: 0.5; }
      & svg { width: 0.9em; height: 0.9em; }
      &.cite-law::before { content: '§'; }
    }
  }

  /* Django's own error markup */
  .errorlist {
    margin-top: 0.375rem;
    font-size: 0.78125rem;
    color: var(--color-error);
    &.nonfield {
      margin-bottom: 1rem;
      border: 1px solid color-mix(in oklab, var(--color-error) 30%, transparent);
      border-radius: var(--radius-field);
      background: color-mix(in oklab, var(--color-error) 8%, transparent);
      padding: 0.5rem 0.75rem;
    }
  }
}
