/*
 * Loaded after the Bootstrap theme, so this file only holds what the themes
 * do not cover. Keep it small: anything that belongs to the look of the app
 * should come from the theme, which an admin can swap without a deploy.
 *
 * Themes name their variables differently — Tabler uses --tblr-*, Bootswatch
 * builds use Bootstrap's --bs-* — so the colours below are read through these
 * aliases, which try Tabler first and fall back to Bootstrap.
 */

:root,
[data-bs-theme] {
  --app-body-color: var(--tblr-body-color, var(--bs-body-color));
  --app-body-bg: var(--tblr-body-bg, var(--bs-body-bg));
  --app-border-color: var(--tblr-border-color, var(--bs-border-color));
  --app-border-radius: var(--tblr-border-radius, var(--bs-border-radius, 0.375rem));
  --app-font-monospace: var(--tblr-font-monospace, var(--bs-font-monospace, monospace));
  --app-sidebar-width: 15rem;
  --app-content-max-width: 1600px;
}

/* App shell: sidebar on the left, top bar and content on the right ------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-main {
  width: 100%;
  max-width: var(--app-content-max-width);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.app-sidebar {
  --bs-offcanvas-width: var(--app-sidebar-width);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--app-border-color);
}

.app-sidebar__scroll {
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.app-sidebar__heading {
  padding: 0 0.75rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
}

.app-sidebar .nav-link {
  color: var(--app-body-color);
  white-space: nowrap;
}

@media (min-width: 992px) {
  /* Always visible, full height, scrolling on its own. */
  .app-sidebar {
    position: sticky;
    top: 0;
    width: var(--app-sidebar-width);
    height: 100vh;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
  }
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
}

.app-topbar__scan {
  flex: 1;
  max-width: 32rem;
}

.app-topbar__logo .brand-logo {
  height: 1.5rem;
}

@media (max-width: 575.98px) {
  .app-topbar {
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
  }

  .app-topbar__scan {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .app-main {
    padding: 1rem 1rem 3rem;
  }
}

/* Branding ---------------------------------------------------------------- */

.brand-logo {
  display: block;
  height: 1.75rem;
  width: auto;
}

h1 .brand-logo {
  height: 2.5rem;
}

/* Warehouse staff work on phones, sometimes with gloves; this is the readable
 * setting they can switch on for themselves. */
body.text-larger {
  font-size: 1.125rem;
}

body.text-larger .btn,
body.text-larger .form-control,
body.text-larger .form-select {
  font-size: 1.05rem;
  padding: 0.55rem 0.9rem;
}

/* Some Bootswatch themes (Zephyr among them) set outline-secondary buttons to
   a dark text colour directly, not through Bootstrap's variables, which
   leaves the −/+ and "clear" buttons blank on a dark background. Tie them to
   the body colours instead, whatever theme is loaded. */
[data-bs-theme="dark"] .btn-outline-secondary {
  color: var(--app-body-color);
  border-color: var(--app-border-color);
}

[data-bs-theme="dark"] .btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn-outline-secondary:focus-visible {
  color: var(--app-body-bg);
  background-color: var(--app-body-color);
  border-color: var(--app-body-color);
}

/* Tables of products and lots are wide; let them scroll rather than squeeze. */
.table-scroll {
  overflow-x: auto;
}

.table-scroll table {
  min-width: 40rem;
}

/* Barcodes and lot numbers read better as fixed-width digits. */
.barcode,
.lot-number {
  font-family: var(--app-font-monospace);
  font-variant-numeric: tabular-nums;
}

/* Inline Bootstrap Icons (see IconsHelper): sized to the text beside them. */
.icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

.app-sidebar .nav-link .icon,
.app-topbar .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.dropdown-menu form {
  margin: 0;
}

/* Camera scanning drops a small preview under the scan field. */

.scan-camera {
  position: absolute;
  z-index: 1030;
  margin-top: 2.5rem;
  padding: 0.5rem;
  border: 1px solid var(--app-border-color);
  border-radius: var(--app-border-radius);
  background: var(--app-body-bg);
}

.scan-camera video {
  width: min(20rem, 70vw);
  border-radius: var(--app-border-radius);
}

/* Goods-in lines: the quantity controls must stay on screen, so product names
   wrap instead of pushing the table sideways. */

.receipt-lines td {
  white-space: normal;
}

.receipt-lines td:nth-child(2) {
  white-space: nowrap;
}

@media (max-width: 575.98px) {
  /* On a phone the barcode is already in the scan message; drop the column. */
  .receipt-lines th:nth-child(2),
  .receipt-lines td:nth-child(2) {
    display: none;
  }
}

/* Two-factor sign-in */
.otp-qr {
  width: 12rem;
  height: 12rem;
  padding: 0.5rem;
  background: #fff; /* scanners need dark on light, even in dark mode */
  border-radius: var(--app-border-radius);
}

/* Signing in: one narrow card in the middle of the screen, the logo above. */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 6rem);
  padding-top: 2rem;
}

.auth-box {
  width: 100%;
  max-width: 26rem;

  .auth-logo {
    margin-bottom: 1.5rem;

    .brand-logo {
      margin-inline: auto;
    }
  }
}

.otp-code-input {
  font-family: var(--app-font-monospace);
  letter-spacing: 0.15em;
}

.recovery-codes {
  columns: 2;
}

/* Breadcrumbs: the full trail from tablets up, a single "back" link on phones. */
.app-breadcrumbs {
  margin-bottom: 0.75rem;
  font-size: 0.875rem;

  /* Tabler boxes breadcrumbs in; here they are a quiet line above the title. */
  .breadcrumb {
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
  }

  a {
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }
}

.app-breadcrumbs__home,
.app-breadcrumbs__back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.app-breadcrumbs__back {
  min-height: 2.75rem; /* a comfortable thumb target */
}

/* Strain catalog */
/* Strain photos are squares; aspect-ratio keeps them so when a theme sets
   images to height: auto and a flex row would stretch them. */
.strain-photo {
  display: block;
  flex: none;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--app-border-radius);
  background: var(--app-border-color);
}

/* The strain form: the main photo and the picked extra photos as squares. */
.photo-preview__main {
  width: 96px;
  max-width: none;
  height: 96px;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
  gap: 0.5rem;
}

.photo-preview__item {
  position: relative;
  cursor: grab;
}

/* Photos put in order by dragging (saved ones on the edit page, picked ones
   on the form): what can be grabbed, and the gap left where one will land. */
.photo-order__handle {
  cursor: grab;
}

.photo-order__ghost {
  opacity: 0.35;
}

.photo-preview__item .strain-photo {
  width: 100%;
  height: auto;
}

.photo-preview__item--problem .strain-photo {
  outline: 3px solid var(--bs-danger, #d63939);
  outline-offset: -3px;
}

.photo-preview__remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  padding: 0 0.4rem;
  line-height: 1.4;
}

.photo-preview__problem {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  line-height: 1.3;
}

.strain-photo--empty {
  display: grid;
  place-items: center;
  color: var(--app-body-color);
  opacity: 0.4;
}

.strain-photo--hero {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.strain-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: 0.5rem;

  img {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
}

.strain-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 1rem;

  img {
    aspect-ratio: 1;
  }
}

/* Rows that open their record when clicked anywhere (row-link controller). */
tr[data-controller~="row-link"] {
  cursor: pointer;
}

/* Language versions: only the chosen one shows (language-switch controller).
   Until the script runs, the server-rendered data-language decides. */
[data-language="pl"] [data-lang="en"],
[data-language="en"] [data-lang="pl"] {
  display: none !important;
}

/* One card per strain for what is written per language; its sections
   (name and description, cultivation) are boxes inside it. */
.language-card__section {
  padding: 1rem 1.25rem;
  border: 1px solid var(--app-border-color);
  border-radius: var(--app-border-radius);
}

.language-card__section + .language-card__section {
  margin-top: 1.25rem;
}

/* Wide lists: column headings one step smaller and never wrapped, and
   tighter cells, so the data gets the width (fits a 14" MacBook Pro). */
.table-dense > thead th {
  font-size: 0.6875rem;
  white-space: nowrap;
}

.table-dense > :not(caption) > * > * {
  padding-inline: 0.5rem;
}

/* "Na stronie www" switch. */
.strain-publication .form-check-input,
.product-activation .form-check-input {
  cursor: pointer;
}

/* Strain page and form headings: sections clearly above the stages in them,
   whatever the theme does with h5/h6. */
.strain-section-heading {
  display: block;
  margin-bottom: 1rem;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.3;
}

.strain-subheading {
  margin-top: 1.75rem;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.stage-name {
  font-size: 0.875rem;
  font-weight: 600;
}

/* Stage numbers in the form follow the visible stages. */
.cultivation-stage-list {
  counter-reset: stage;
}

.cultivation-stage:not([hidden]) {
  counter-increment: stage;
}

.stage-number::before {
  content: counter(stage) ".";
}

/* The cultivation section, laid out as on the website's strain page: the
   preparation in tiles, a card per stage with only the parameters it has
   (side by side where there is room, one under another on a phone). Only
   sizes and spacing here: colours, borders and backgrounds come from the
   theme's own classes in the markup, so every theme draws them. */
.cultivation-section {
  font-size: 0.9375rem;
}

.cultivation-section .alert,
.cultivation-section dl {
  font-size: inherit;
}

/* "PRZYGOTOWANIE", "ETAPY UPRAWY": small capitals above each group. */
.cultivation-heading {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cultivation-label {
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cultivation-value {
  font-size: 1rem;
  line-height: 1.5;
}

.cultivation-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
}

.stage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
}

.stage-card {
  margin-bottom: 0;
}

.stage-card__number {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.stage-card__title {
  margin-bottom: 1rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.stage-card__values {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 0;
}

/* As on the website: the icon and label on one line, the value under them. */
.stage-card__values dt {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.15rem;
  font-size: 0.85rem;
  font-weight: 400;
}

.stage-card__values dd {
  margin: 0 0 0 1.5rem;
  font-size: 1rem;
  line-height: 1.45;
}

.stage-card__icon {
  width: 1.1rem;
  height: 1.1rem;
}

.stage-card__notes {
  margin: 1rem 0 0;
  padding-top: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.cultivation-notes__icon {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.05rem;
}

/* Product list grouped by strain: the strain cell spans its products and
   stays put while a single product row is hovered. */
.product-table .product-group__strain {
  vertical-align: top;
  min-width: 9rem;
  max-width: 14rem;
}

.product-table.table-hover > tbody > tr:hover > .product-group__strain {
  --bs-table-bg-state: transparent;
}

/* An inactive product fades, but not the strain cell its row happens to
   carry for the whole group. */
.product-table .product-row--inactive > td {
  opacity: 0.5;
}

.product-table .product-group + .product-group > tr:first-child > * {
  border-top: 2px solid var(--bs-border-color);
}

/* Strain edit: each photo with its description fields beside it. */
.strain-photo-descriptions {
  display: grid;
  gap: 1rem;
}

.strain-photo-description {
  display: flex;
  gap: 1rem;
  align-items: flex-start;

  > img {
    width: 96px;
    height: 96px;
    object-fit: cover;
    flex: none;
  }
}

/* Strain form: the Aktywna / Nowość switches sit level with the inputs of
   their row (below the labels), one per line. */
.strain-flags {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  @media (min-width: 576px) {
    padding-top: 2rem;
  }
}

/* Flash messages as toasts (layouts/_flash): fixed in the bottom right
   corner, over the page, so they neither push the content down nor pull the
   view up, and clear of the top bar's menus. Opaque, since they sit over
   whatever is beneath; under modals. */
.toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1045;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(26rem, calc(100vw - 2rem));
  pointer-events: none;
}

.app-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  pointer-events: auto;
  background-color: var(--tblr-bg-surface);
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;

  .app-toast__message {
    flex: 1;
  }

  &.is-hiding {
    opacity: 0;
    transform: translateX(1rem);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-toast {
    animation: none;
    transition: none;
  }
}
