/* Page header, cards, buttons, fields, the modal, dropdowns and the status
 * line. See base.css for the order. */

/* ---- Page header and cards (DESIGN_SYSTEM §4, §6) ---------------------- */

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.eyebrow .icon {
  width: 0.875rem;
  height: 0.875rem;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.3;
}

@media (min-width: 768px) {
  .page-title {
    font-size: 1.5rem;
  }
}

.card {
  border: 1px solid var(--hairline);
  border-radius: calc(var(--radius) + 4px);
  background: var(--card);
}

.card-muted {
  background: color-mix(in srgb, var(--muted) 50%, transparent);
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--hairline);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.card-body {
  padding: 1rem;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem 1rem;
  background: var(--background);
}

.auth-card {
  display: grid;
  gap: 1.25rem;
  width: 100%;
  max-width: 24rem;
  padding: 1.5rem;
}

.auth-card .brand {
  padding: 0;
}

.stack-form {
  display: grid;
  gap: 1rem;
}

.error-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 1.5rem;
  background: var(--background);
  text-align: center;
}

/* ---- Buttons: one filled primary per view, outline secondaries ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary-fill);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  background: var(--primary-fill-hover);
}

.btn-outline {
  border-color: var(--border);
  background: var(--card);
}

.btn-outline:hover,
.btn-ghost:hover {
  background: var(--accent);
}

/* Red with white on it in both themes: that pairing is what the control means. */
.btn-destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  height: 2rem;
  padding: 0 0.625rem;
  font-size: 0.8125rem;
}

.btn-icon {
  width: 2rem;
  height: 2rem;
  padding: 0;
}

/* ---- Form fields: visible label, error under the field ----------------- */

.field {
  display: grid;
  gap: 0.375rem;
}

.label {
  font-size: 0.75rem;
  font-weight: 500;
}

/* The input border clears 3:1 on purpose (WCAG 1.4.11): it is the edge that
   says "you can type here", not decoration. */
.input {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--input);
}

.textarea {
  height: auto;
  min-height: 4.5rem;
  padding: 0.5rem 0.75rem;
  resize: vertical;
}

select.input {
  padding-right: 0.5rem;
}

.fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.fieldset legend {
  margin-bottom: 0.375rem;
  padding: 0;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 1rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  font-size: 0.875rem;
}

.check input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--primary-fill);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  color: var(--danger);
  font-size: 0.75rem;
}

/* ---- Modal: the one <dialog>, see src/ui/dialog.tsx --------------------- */

.modal {
  width: calc(100% - 2rem);
  max-width: 32rem;
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--foreground);
}

.modal:has([data-dialog-size="wide"]) {
  max-width: 48rem;
}

/* Header and footer stay put; only the body scrolls, so Save is always in
   reach on a phone. */
.modal [data-dialog-size] {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 2rem);
}

.modal .modal-body {
  overflow-y: auto;
}

/* Both rules are needed, or scrolling over the backdrop or inside the dialog
   scrolls the page behind it. Locking <body> instead would shift the layout. */
.modal:modal {
  overscroll-behavior: contain;
}

.modal::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--hairline);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-body {
  display: grid;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--hairline);
}

/* ---- Dropdown: a popover anchored to its trigger, see src/ui/dropdown.tsx */

.dropdown {
  min-width: 11rem;
  padding: 0.25rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--popover);
  color: var(--foreground);
}

.dropdown > :is(a, button) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.375rem 0.5rem;
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  background: none;
  font-size: 0.875rem;
  text-align: start;
  cursor: pointer;
}

/* A fingertip needs a taller row than a mouse pointer. */
@media (pointer: coarse) {
  .dropdown > :is(a, button) {
    min-height: 2.75rem;
  }
}

.dropdown > :is(a, button):hover,
.dropdown > :is(a, button)[aria-current="page"] {
  background: var(--accent);
}

.dropdown-label {
  display: grid;
  padding: 0.375rem 0.5rem 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--hairline);
  font-weight: 500;
}

.dropdown > [data-tone="danger"] {
  color: var(--danger);
}

/* Anchored below the trigger, flipping when it would run off screen. */
@supports (position-area: block-end) {
  .dropdown {
    inset: auto;
    margin: 0.25rem 0;
    position-area: block-end span-inline-end;
    position-try-fallbacks:
      flip-block,
      flip-inline,
      flip-block flip-inline;
  }

  .dropdown[data-align="end"] {
    position-area: block-end span-inline-start;
  }
}

/* No anchor positioning: a sheet along the bottom edge, which suits a phone,
   rather than a panel floating in the middle of the screen. */
@supports not (position-area: block-end) {
  .dropdown {
    position: fixed;
    inset: auto 0 0 0;
    width: auto;
    margin: 0;
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

/* Older browsers wait for the popover polyfill (app.js); keep panels hidden
   until it has loaded. */
@supports not selector(:popover-open) {
  [popover]:not(.\:popover-open) {
    display: none;
  }
}

/* ---- Status line: messages from failed htmx requests ------------------- */

.status {
  position: fixed;
  inset: auto 1rem 1rem;
  z-index: 50;
  max-width: 28rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--danger);
}

.status:empty {
  padding: 0;
  border: 0;
}
