/*
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. This file sets the theme, the element
defaults and the pieces several pages share (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.

daisyUI's rules all sit in cascade layers, so unlayered CSS beats them whatever its specificity. That is why:
- element defaults go in @layer base, where daisyUI's components and colour classes still override them;
- a class here beats a daisyUI class on the same element, so it 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.
*/

/* The one theme, from the old palette. daisyUI's components read these variables; a dark theme would be a second
   block like this one under [data-theme=dark]. */
:root {
  color-scheme: light;

  /* the page is grey and what sits on it is white; base-300 is the line */
  --color-base-100: #ffffff;
  --color-base-200: #f4f5f7;
  --color-base-300: #dce0e8;
  --color-base-content: #10151d;

  --color-primary: #1b4fa0;
  --color-primary-content: #ffffff;
  --color-secondary: #3e4654;
  --color-secondary-content: #ffffff;
  /* the avatar and the far end of the brand gradient */
  --color-accent: #2b62bf;
  --color-accent-content: #ffffff;
  /* the dark sections: the landing hero, the dashboard's assistant band and the login aside */
  --color-neutral: #10151d;
  --color-neutral-content: #c7ceda;
  /* on the dark sections, a step above their text: the headings, and the lines and fills of what sits there */
  --neutral-bright: #ffffff;

  --color-info: #1b4fa0;
  --color-info-content: #ffffff;
  --color-success: #047857;
  --color-success-content: #ffffff;
  --color-warning: #a16207;
  --color-warning-content: #ffffff;
  --color-error: #9a2a2a;
  --color-error-content: #ffffff;

  /* flat and quiet: thin lines, no depth or noise */
  --radius-selector: 0.3125rem;
  --radius-field: 0.4375rem;
  --radius-box: 0.625rem;
  --size-selector: 0.25rem;
  --size-field: 0.25rem;
  --border: 1px;
  --depth: 0;
  --noise: 0;

  /* the page behind everything, overscroll included (daisyUI paints the root base-100) */
  --root-bg: var(--color-base-200);

  /* what the stylesheets here share; the templates use daisyUI's colour classes instead */
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --muted: color-mix(in oklab, var(--color-base-content) 70%, transparent);
  --subtle: color-mix(in oklab, var(--color-base-content) 60%, transparent);
  --line: var(--color-base-300);
  --line-strong: color-mix(in oklab, var(--color-base-content) 20%, transparent);
  --hover: color-mix(in oklab, var(--color-base-content) 5%, transparent);
  --mark: #fde68a;
  --shadow-sm: 0 1px 3px 0 rgb(16 21 29 / 0.1), 0 1px 2px -1px rgb(16 21 29 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(16 21 29 / 0.1), 0 4px 6px -4px rgb(16 21 29 / 0.1);
  --text-read: 15.5px;
  --page-width: 1240px;
}

@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: 0.875rem;
    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: pretty;
  }
  h1 { font-size: 26px; }
  h2 { font-size: 19px; }
  h3 { font-size: 17px; }
  /* 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 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 focused field rings in the brand colour, where daisyUI rings it in the text's */
: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: 1rem;
  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: color-mix(in oklab, var(--color-base-content) 30%, transparent);
    box-shadow: var(--shadow-sm);
  }
}
/* what follows a result's kicker, after a dot */
.result-meta {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  &::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 3px;
    margin-right: 0.625rem;
    border-radius: 50%;
    background: color-mix(in oklab, var(--color-base-content) 30%, transparent);
    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: 1rem;
  font-weight: 500;
  color: color-mix(in oklab, var(--color-base-content) 80%, transparent);
}

/* 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; }
}

/* HTML we do not write: a stored decision, an act, a chat answer */
.richtext {
  font-size: var(--text-read);
  line-height: 1.7;
  & :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: 17px;
    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-left: 2px solid color-mix(in oklab, var(--color-base-content) 25%, transparent);
    padding-left: 0.875rem;
    color: color-mix(in oklab, var(--color-base-content) 80%, transparent);
  }
  & 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 { width: 100%; border-collapse: collapse; font-size: 13px; }
  & :is(td, th) { border: 1px solid var(--line); padding: 0.375rem 0.5rem; text-align: left; }

  /* 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: 12.5px;
  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;
  }
}
