/* Nomios web UI: base (element defaults). Design system: docs/design/DESIGN_SYSTEM.md.
   The four stylesheets are linked in this order: tokens, base, shell, components. */

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* Room for the scrollbar is always reserved: the page does not jump sideways when it grows
       past one screen (a short page next to a long one), and a swapped-in region does not shift. */
    scrollbar-gutter: stable;
  }

  /* Scrolling inside a panel stays inside it: at its end the wheel or the trackpad does not carry
     on into the page behind (the sidebar list, the task window, a wide table in its card). Not a
     text box: in Chromium a short one, which does not scroll, would swallow the wheel instead of
     passing it on to the window. */
  .nav,
  .modal-body,
  .table-scroll,
  #run-live > section {
    overscroll-behavior: contain;
  }

  body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-base);
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  /* The page background is a fixed layer behind everything (steady on mobile, easy to swap). */
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image: var(--bg-image);
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
  }

  h1,
  h2,
  h3 {
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-2xl);
    margin: 0 0 var(--space-4);
    letter-spacing: -0.01em;
  }

  h2 {
    font-size: var(--text-lg);
  }

  h3 {
    font-size: var(--text-base);
  }

  p {
    text-wrap: pretty;
  }

  a {
    color: var(--color-link);
    text-underline-offset: 0.2em;
    text-decoration-thickness: 0.07em;
  }

  a:hover {
    text-decoration-thickness: 0.12em;
  }

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

  /* A placeholder is text: the browser's own grey on glass is only about 4:1. */
  input::placeholder,
  textarea::placeholder {
    color: var(--color-text-subtle);
    opacity: 1;
  }

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

  [hidden] {
    display: none !important;
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* Controls: one secondary style for now; the primary style is .btn-primary. */
  button,
  .btn {
    font: inherit;
    font-weight: 600;
    color: var(--color-text);
    background: var(--glass-raised-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition:
      transform var(--dur-fast) var(--ease-spring),
      background-color var(--dur-fast) var(--ease-standard),
      border-color var(--dur-fast) var(--ease-standard);
  }

  button:hover,
  .btn:hover {
    transform: translateY(var(--lift));
    border-color: var(--color-border-strong);
  }

  button:active,
  .btn:active {
    transform: scale(var(--press-scale));
  }

  /* A request is running for this control: a spinner, no double clicks. */
  button.htmx-request {
    position: relative;
    padding-inline-end: calc(var(--space-4) + 1.25rem);
    cursor: progress;
    opacity: 0.8;
  }

  button.htmx-request::after {
    content: "";
    position: absolute;
    inset-inline-end: var(--space-3);
    inset-block-start: 50%;
    width: 0.9rem;
    height: 0.9rem;
    margin-top: -0.45rem;
    border: 2px solid currentcolor;
    border-inline-end-color: transparent;
    border-radius: 50%;
  }

  @media (prefers-reduced-motion: no-preference) {
    button.htmx-request::after {
      animation: spin 0.8s linear infinite;
    }
  }

  @keyframes spin {
    to {
      transform: rotate(1turn);
    }
  }

  a.htmx-request {
    cursor: progress;
    opacity: 0.7;
  }

  button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
  }

  .btn-quiet {
    color: var(--color-text-muted);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    padding-inline: var(--space-3);
  }

  .btn-quiet:hover {
    color: var(--color-text);
    background: var(--color-hover);
  }

  .btn-primary {
    color: var(--color-accent-contrast);
    background: var(--color-accent);
    border-color: transparent;
  }

  input,
  select,
  textarea {
    font: inherit;
    color: var(--color-text);
    background: var(--color-field-bg);
    border: 1px solid var(--color-field-border);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
  }

  input:is([type="checkbox"], [type="radio"]) {
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
    vertical-align: -0.2em;
    accent-color: var(--color-accent);
    cursor: pointer;
  }

  label {
    cursor: pointer;
  }

  table {
    border-collapse: collapse;
    width: 100%;
    margin: var(--space-2) 0;
  }

  th,
  td {
    text-align: left;
    padding: var(--space-2) var(--space-3) var(--space-2) 0;
    vertical-align: top;
    font-size: var(--text-sm);
  }

  tbody tr + tr > * {
    border-top: 1px solid var(--color-border);
  }

  /* A column of figures: right-aligned, with digits of equal width so they line up. */
  .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding-inline: var(--space-3) 0;
  }

  .num .badge {
    white-space: nowrap;
  }

  thead th {
    border-bottom: 1px solid var(--color-border-strong);
    color: var(--color-text-muted);
    font-weight: 600;
  }

  details {
    margin: var(--space-2) 0;
  }

  summary {
    cursor: pointer;
  }
}
