/* Backpack: what Visalia UI does not provide, on Visalia's own tokens.
 *
 * Visalia (/static/visalia/css/visalia.css, loaded first) draws the shell,
 * buttons, fields, tables, badges, alerts, cards, pagination and timeline.
 * This file only arranges Backpack's pages and draws its own widgets. It
 * defines no colours: every one is a Visalia token, so both themes follow.
 */

/* --- Visalia's elements, visible before their scripts ------------------ */

/* host.css hides vis-* until defined, against a flash of unstyled content.
   Backpack renders these with the classes their scripts would add, so they
   are already styled; hiding them would blank the page without JavaScript. */
vis-app-shell:not(:defined),
vis-sidebar:not(:defined),
vis-topbar:not(:defined),
vis-alert:not(:defined),
vis-input-stepper:not(:defined) {
  visibility: visible;
}

/* A collapse restored on load is not animated (backpack.js). */
.is-restoring-shell .app-shell,
.is-restoring-shell .app-shell * {
  transition: none !important;
}

/* --- Visalia fixes ------------------------------------------------------- */

/* Visalia's .btn is drawn for <button>; a link that looks like one is not
   underlined either. */
a.btn {
  text-decoration: none;
}

/* Visalia's dark inputs reset the background shorthand, which would tile the
   select's chevron across the field; put it back in place. */
[data-theme="dark"] select.input {
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* --- Shell ------------------------------------------------------------- */

a.brand {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
}

.sidebar-brand a.brand {
  flex: 1;
}

.sidebar-logo svg {
  width: 18px;
  height: 18px;
}

.topbar a.brand .sidebar-title {
  max-width: none;
}

/* Sign-out is a form, because it must be a POST, but reads as a nav item. */
.sidebar-footer form {
  margin: 0;
}

.sidebar-footer button.nav-item {
  text-align: left;
  font-family: inherit;
}

.sidebar-footer .sidebar-user-static .avatar {
  flex-shrink: 0;
}

/* The menu and theme buttons need backpack.js. theme.js always sets
   data-theme, so without it JavaScript is off: hide what would do nothing. */
:root:not([data-theme]) [data-shell-toggle],
:root:not([data-theme]) [data-theme-toggle] {
  display: none;
}

/* The theme switch shows what it switches to. */
[data-theme="dark"] .theme-icon-dark,
:root:not([data-theme="dark"]) .theme-icon-light {
  display: none;
}

.app-content {
  width: 100%;
  margin-inline: auto;
}

.app-content > * + * {
  margin-top: var(--gap-lg);
}

.app-content .page-header {
  margin-bottom: var(--gap-lg);
}

.app-content a:not(.btn, .ms-sign-in) {
  color: var(--accent);
}

.app-footer {
  padding: var(--gap-md) var(--gap-xl);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-meta);
}

/* --- Text ---------------------------------------------------------------- */

.app-content p + p {
  margin-top: var(--gap-sm);
}

.hint,
.read-only-note {
  color: var(--muted);
  font-size: 13px;
}

.card-header h2 {
  font-size: var(--fs-h3);
}

.card > h3,
.stock-site h3 {
  margin: var(--gap-md) 0 var(--gap-sm);
  font-size: 13px;
  color: var(--muted);
}

/* --- Page actions and filters --------------------------------------------- */

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
}

form.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap-md);
  padding: var(--gap-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

/* No bottom margin, unlike fields in other forms: the bar aligns its items
   by their bottom edge, and a margin would lift the fields above the button. */
form.filters .field {
  flex: 0 1 11rem;
  min-width: 0;
  margin-bottom: 0;
}

form.filters .field.search {
  flex: 1 1 16rem;
}

/* As tall as the fields beside it: Visalia pads .input 1px more than .btn. */
form.filters .btn {
  padding-block: 9px;
}

/* --- Tables ---------------------------------------------------------------- */

.ds-table td,
.ds-table th {
  white-space: nowrap;
}

.ds-table td.code {
  font-family: var(--font-mono);
  font-weight: 600;
}

.ds-table a {
  text-decoration: none;
}

.ds-table a:hover {
  text-decoration: underline;
}

.ds-table td.free,
.holder .free {
  color: var(--muted);
}

.ds-table th.num-col {
  text-align: right;
}

.ds-table th.count,
.ds-table td.count {
  white-space: normal;
}

.pagination-bar {
  margin-top: var(--gap-sm);
}

/* --- Export to Excel ------------------------------------------------------- */

.results-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--gap-sm);
}

/* In the modal, the form is the panel's body and footer: the slot htmx fills
   and the form itself take no box of their own. */
.export-slot {
  display: contents;
}

.modal .export-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.modal .export-form .modal-body {
  overflow-y: auto;
  color: var(--fg);
}

.export-form fieldset {
  margin-bottom: var(--gap-md);
  padding: var(--gap-sm) var(--gap-md) var(--gap-md);
}

.export-columns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: var(--gap-xs) var(--gap-md);
}

.export-split {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-xs) var(--gap-lg);
}

.export-form .modal-footer {
  gap: var(--gap-sm);
}

/* On its own page, the form sits in a card: no panel chrome. */
.export-card .modal-body {
  padding: 0;
  color: var(--fg);
}

.export-card .modal-footer {
  padding: var(--gap-md) 0 0;
  border-top: none;
  background: none;
}

/* --- Asset page ------------------------------------------------------------ */

.details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--gap-md);
}

.details > .card {
  margin: 0;
}

dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--gap-xs) var(--gap-md);
  margin: 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.timeline-desc {
  color: var(--muted);
}

.timeline-desc.note {
  margin-top: 2px;
  font-style: italic;
}

/* «Nivel de acceso SI»: the colours of the printed band, the same in both
   themes, and the level always written. */
.access-level {
  display: inline-block;
  padding: 1px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.access-level-internal {
  border-color: #1a1a1a;
  color: #1a1a1a;
  background: #ffffff;
}

.access-level-restricted {
  color: #1a1a1a;
  background: #ffd400;
}

.access-level-confidential {
  color: #ffffff;
  background: #d92d20;
}

/* --- Label scanner --------------------------------------------------------- */

.scan-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--gap-md);
  align-items: start;
}

.scan-layout > .card {
  margin: 0;
}

/* Square, as the QR code it frames, and never wider than a phone's screen. */
.scan-video {
  display: block;
  width: 100%;
  max-width: 28rem;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: #000;
}

.scan-status {
  margin: var(--gap-sm) 0 0;
  color: var(--muted);
}

.scan-status:empty {
  display: none;
}

/* --- Asset label ----------------------------------------------------------- */

/* The first row: the current holder, and the label in the last third. */
.asset-summary {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}

.asset-summary > .card {
  margin: 0;
}

@media (max-width: 1100px) {
  .asset-summary {
    grid-template-columns: 1fr;
  }
}

/* The QR code beside the URL it holds and the label links. */
.label {
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: start;
  gap: var(--gap-sm) var(--gap-lg);
}

.label > .card-header {
  grid-column: 1 / -1;
}

.label > .qr-label {
  grid-row: span 2;
}

.qr-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-xs);
  margin: 0;
}

/* The label as printed: the QR black on white, the code, and the level's
   band. It reads in the dark theme too. Its height follows its width. */
.qr-label svg {
  display: block;
  width: 9rem;
  height: auto;
  border-radius: var(--radius-sm);
}

.qr-target {
  margin: 0;
  overflow-wrap: anywhere;
}

.qr-actions {
  display: flex;
  flex-wrap: wrap;
  align-self: end;
  gap: var(--gap-sm);
}

/* The printable label: no shell, only the label, in mm. */
body:has(.label-sheet) {
  background: #fff;
}

.label-sheet {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: #fff;
}

.label-sheet .qr-label svg {
  width: 30mm;
  height: auto;
  border-radius: 0;
}

@media print {
  @page {
    margin: 0;
  }

  .label-sheet {
    min-height: 0;
  }
}

/* Read by assistive technology, not shown. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Pages without a user: the group's corporate layout ------------------- */

/* As the group's other applications draw their sign-in page (Yoda's
   /login/): a navy brand panel beside a white one, Titillium Web for headings
   and Open Sans for text, served from /static/fonts. Always light: the
   corporate colours do not follow Visalia's theme. */

@font-face {
  font-family: "Open Sans";
  src: url("fonts/open-sans-latin-wght.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Titillium Web";
  src: url("fonts/titillium-web-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Titillium Web";
  src: url("fonts/titillium-web-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

html:has(.public) {
  color-scheme: light;
}

body:has(.public) {
  background: #fff;
}

.public {
  /* The group's palette, named as Yoda names it. */
  --brand-navy: #082549;
  --brand-band: linear-gradient(35deg, #02b0c4, #a0d720);
  --ink: #1a1a1a;
  --ink-heading: var(--brand-navy);
  --ink-muted: #5a6b80;
  --ink-on-dark: #fff;
  --ink-on-dark-muted: #a9bcd6;
  --surface-plate: #fff;
  --font-ui: "Open Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Titillium Web", var(--font-ui);

  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(22rem, 30rem);
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  line-height: 1.5;
}

.public h1,
.public-headline {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: normal;
  line-height: 1.15;
}

/* The brand panel: mark at the top, pitch in the middle, group at the foot,
   and the group's band along the bottom edge. */
.public-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 2.5rem;
  overflow: hidden;
  color: var(--ink-on-dark-muted);
  background: var(--brand-navy);
}

.public-brand::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 3px;
  background: var(--brand-band);
}

.public-brand p {
  margin: 0;
}

.public-mark {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink-on-dark);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}

.public-mark-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  background: var(--brand-band);
}

.public-mark-icon svg {
  width: 20px;
  height: 20px;
}

.public-pitch {
  display: grid;
  gap: 0.75rem;
}

.public-headline {
  color: var(--ink-on-dark);
  font-size: 3rem;
}

.public-pitch p:last-child {
  max-width: 40ch;
  font-size: 1rem;
}

.public-group {
  font-size: 0.8125rem;
}

/* The white panel: the page itself, centred in its height. */
.public-panel {
  display: grid;
  align-content: center;
  gap: 1.5rem;
  padding: 2.5rem 2rem;
  background: var(--surface-plate);
}

.public-panel > * {
  margin: 0;
}

.public-panel h1 {
  color: var(--ink-heading);
  font-size: 1.5rem;
}

.public-panel .hint {
  color: var(--ink-muted);
}

.public-panel a:not(.ms-sign-in) {
  color: #0077aa;
}

/* On a phone the brand panel shortens above the white one. */
@media (max-width: 860px) {
  .public {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }

  .public-brand {
    padding: 1.5rem;
  }

  .public-headline {
    font-size: 2rem;
  }

  .public-panel {
    align-content: start;
    padding: 1.5rem 1rem;
  }
}

/* Microsoft's sign-in branding: light button, dark text, thin border, logo
   first. Kept light in the dark theme too, as the guidelines ask. */
a.ms-sign-in {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border: 1px solid #8c8c8c;
  border-radius: 2px;
  color: #5e5e5e;
  background: #ffffff;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
}

a.ms-sign-in:hover {
  color: #1b1b1b;
  background: #f3f3f3;
}

a.ms-sign-in svg {
  flex: none;
}

/* --- Forms ----------------------------------------------------------------- */

form .field {
  margin-bottom: var(--gap-md);
}

.field .input,
.field .textarea {
  max-width: 32rem;
}

.field .textarea {
  min-height: 0;
}

.required {
  color: var(--danger);
  font-weight: 400;
}

/* A field at fault: border and message, never colour alone. Specific enough
   to win over Visalia's dark inputs, which reset the border colour. */
.field.invalid .input,
.field.invalid .textarea {
  border-width: 2px;
  border-color: var(--danger);
}

/* A number stepper draws the border around its buttons and input: the fault
   goes on it, and the input inside keeps none. */
.field.invalid .input-stepper {
  border-width: 2px;
  border-color: var(--danger);
}

.field.invalid .input-stepper .input {
  border: 0;
}

.field-error,
.form-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

/* Visalia's checkbox inside a field: hint and error under the label. */
.field-checkbox {
  gap: var(--gap-xs);
}

.field-checkbox .field-hint,
.field-checkbox .field-error {
  padding-left: 28px;
}

.alert-body {
  min-width: 0;
}

.error-summary .alert-icon {
  align-self: flex-start;
}

.error-summary {
  margin-bottom: var(--gap-md);
}

.error-summary .alert-title {
  font-size: var(--fs-body);
}

.error-summary ul {
  margin: var(--gap-xs) 0 0;
  padding-left: 1.25rem;
}

.app-content .error-summary a {
  color: inherit;
}

.error-summary:focus {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-sm);
  margin-top: var(--gap-md);
}

/* The asset form's groups read as cards. */
form fieldset {
  min-width: 0;
  margin: 0 0 var(--gap-md);
  padding: var(--gap-md) var(--gap-lg) var(--gap-xs);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

form legend {
  padding: 0 var(--gap-xs);
  font-family: var(--font-display);
  font-weight: 600;
}

.code-fixed {
  margin-bottom: var(--gap-md);
  padding: 0;
  border: none;
  background: none;
}

.code-fixed .code {
  margin: 0 0 var(--gap-xs);
  font-family: var(--font-mono);
  font-size: 16px;
}

/* --- Custody and status panel ---------------------------------------------- */

.custody-panel > .alert {
  margin-bottom: var(--gap-md);
}

.custody-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: var(--gap-lg);
}

.custody-action {
  margin: 0;
  min-width: 0;
}

.custody-action h3 {
  margin-bottom: var(--gap-sm);
}

.custody-action .field {
  margin-bottom: var(--gap-sm);
}

/* --- Directory search in the custody panel --------------------------------- */

.directory-search .search-row {
  display: flex;
  gap: var(--gap-xs);
  max-width: 32rem;
  margin-top: var(--gap-xs);
}

.directory-search .search-row .input {
  flex: 1 1 auto;
  min-width: 0;
}

.directory-results {
  margin-top: var(--gap-sm);
}

.directory-choice fieldset {
  margin: 0 0 var(--gap-sm);
  padding: 0;
  border: none;
  background: none;
}

.directory-choice legend {
  margin-bottom: var(--gap-xs);
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}

/* One account per row: the radio, then name, email and department. */
label.directory-user {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 var(--gap-sm);
  align-items: baseline;
  padding: var(--gap-xs) var(--gap-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

label.directory-user + label.directory-user {
  margin-top: var(--gap-xs);
}

label.directory-user:hover {
  background: var(--fg-soft);
}

label.directory-user:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

label.directory-user input {
  grid-row: span 3;
  accent-color: var(--accent);
}

label.directory-user .name {
  font-weight: 600;
}

label.directory-user .email,
label.directory-user .department {
  grid-column: 2;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

label.directory-user .badge {
  grid-column: 2;
  justify-self: start;
  margin-top: 2px;
}

/* --- Changes on the asset page --------------------------------------------- */

ol.change-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

li.change {
  padding: var(--gap-sm) 0;
  border-bottom: 1px solid var(--border-subtle);
}

li.change:first-child {
  padding-top: 0;
}

li.change:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

li.change time {
  margin-right: var(--gap-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--muted);
}

li.change .actor {
  font-weight: 600;
}

ul.change-lines {
  margin: var(--gap-xs) 0 0;
  padding-left: 1.25rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* --- Stock ----------------------------------------------------------------- */

.stock-site .location + .location {
  margin-top: var(--gap-md);
}

form.quantity-form {
  display: flex;
  align-items: flex-end;
  gap: var(--gap-xs);
}

form.quantity-form .field {
  gap: 2px;
  margin: 0;
}

/* The column heading, «Recuento», already says what the field is; its label
   stays for screen readers only. */
form.quantity-form .field-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

form.quantity-form .input {
  width: 6rem;
  padding-block: 5px;
}

form.quantity-form .btn {
  padding-block: 6px;
}

/* --- Reference data -------------------------------------------------------- */

.reference-data {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: var(--gap-lg);
}

.reference-data > .error-summary {
  grid-column: 1 / -1;
}

.catalog {
  min-width: 0;
}

ul.catalog-entries,
ul.locations {
  margin: 0 0 var(--gap-md);
  padding: 0;
  list-style: none;
}

ul.locations {
  margin: var(--gap-xs) 0 var(--gap-xs) var(--gap-lg);
}

li.catalog-entry {
  padding: var(--gap-xs) 0;
  border-bottom: 1px solid var(--border-subtle);
}

ul.locations li.catalog-entry:last-child {
  border-bottom: none;
}

.entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-xs) var(--gap-sm);
}

.entry-name {
  overflow-wrap: anywhere;
}

li.catalog-entry.site > .entry .entry-name {
  font-weight: 600;
}

details.rename {
  margin-left: auto;
}

details.rename summary {
  list-style: none;
}

details.rename summary::-webkit-details-marker {
  display: none;
}

details.rename[open] {
  flex-basis: 100%;
  margin-left: 0;
}

/* A serialized type's settings: their own row under the name, the
   checkboxes and the button side by side; rename stays on the name's row. */
.settings-form {
  display: flex;
  flex-basis: 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-xs) var(--gap-sm);
  order: 1;
}

.settings-form .field {
  margin: 0;
}

.rename-form,
.create-form {
  margin-top: var(--gap-sm);
}

.create-form {
  padding: var(--gap-md);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.create-form h3 {
  margin-bottom: var(--gap-sm);
}

.create-form.invalid,
.rename-form.invalid {
  border-color: var(--danger);
}

/* --- Narrow screens -------------------------------------------------------- */

@media (max-width: 720px) {
  .app-content {
    padding: var(--gap-md);
  }

  .app-footer {
    padding-inline: var(--gap-md);
  }

  vis-topbar,
  .topbar {
    padding: 0 var(--gap-md);
  }

  :root {
    --fs-h1: 22px;
  }

  form.filters .field {
    flex: 1 1 calc(50% - var(--gap-md));
  }

  form.filters .field.search {
    flex-basis: 100%;
  }

  .custody-actions,
  .reference-data {
    grid-template-columns: 1fr;
  }
}
