/* =============================================================================
   css/screens/items.css
   Where things go on the Items screens (js/screens/items.js and
   js/screens/items-import.js): the list with its filters, one item, the
   Add / Edit form, and the import (ITEM-01 to ITEM-14).

   Tablet and laptop (768px and up): list on the left, the chosen item on
   the right, both scrolling on their own, like bill history. The form
   takes the whole width (data-mode="form"), so its two-column rows have
   room. Phone: one pane at a time; #/items is the list, #/items/:code is
   the item with a back arrow (docs/05-ux-spec.md section 3, PWA-03).

   Positioning only. The rows, form pieces, switch, chips and timeline are
   components in components.css; every value here is a token
   (docs/05-ux-spec.md section 8, CLAUDE.md rule 9).
   ============================================================================= */


/* -----------------------------------------------------------------------------
   THE TWO PANES
   ----------------------------------------------------------------------------- */

.items {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: var(--space-4);
  height: 100%;
  min-height: 0;
  padding: var(--space-3) var(--space-4);
}

.items__list,
.items__right {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* The form has the screen to itself. */
.items[data-mode='form'] {
  grid-template-columns: minmax(0, 1fr);
}

.items[data-mode='form'] .items__list {
  display: none;
}

/* Phone: one pane fills the screen; which one is data-mode on the root. */
@media (max-width: 767px) {
  .items {
    display: block;
    height: auto;
    padding: var(--space-3);
  }

  .items[data-mode='list'] .items__right,
  .items[data-mode='detail'] .items__list {
    display: none;
  }

  .items__list,
  .items__right {
    overflow: visible;
  }
}

/* The back arrow is only for a phone; on a tablet the list is beside. */
.items__back {
  align-self: flex-start;
}

@media (min-width: 768px) {
  .items__back {
    display: none;
  }
}


/* -----------------------------------------------------------------------------
   THE LIST: title row, filters, results
   ----------------------------------------------------------------------------- */

.items__title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  flex: none;
}

.items__title h1 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-heading);
}

.items__filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: none;
}

/* Never shrunk: the column scrolls as a whole, so the count line always
   sits under the last row rather than over it. */
.items__results {
  flex: none;
}

.items__count {
  flex: none;
  font-size: var(--text-small);
}


/* -----------------------------------------------------------------------------
   ONE ITEM: a card
   ----------------------------------------------------------------------------- */

.items__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.items__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.items__name {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: var(--font-bold);
  overflow-wrap: anywhere;
}

.items__code {
  font-size: var(--text-body);
  font-weight: var(--font-medium);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.items__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  color: var(--color-text-muted);
}

.items__meta span,
.items__meta a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* The supplier is a link to their page (SUP-04). */
.items__link {
  color: var(--color-primary);
  text-decoration: none;
}

.items__section-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  font-weight: var(--font-medium);
  color: var(--color-text-muted);
}

.items__notes {
  margin: 0;
  white-space: pre-wrap;
}

/* Edit and Adjust on the left; Deactivate and Delete on the right. */
.items__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.items__actions .spacer {
  flex: 1 1 auto;
}

@media (max-width: 480px) {
  .items__actions .btn {
    flex: 1 1 40%;
  }
}

.items__sold {
  margin: 0;
  font-size: var(--text-small);
}


/* -----------------------------------------------------------------------------
   THE FORM
   ----------------------------------------------------------------------------- */

.items__form-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  flex: none;
}

.items__form-title {
  margin: 0;
  font-size: var(--text-heading);
  overflow-wrap: anywhere;
}

/* Centred, with room to read, on a wide screen. */
.items__form {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-4);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

/* The sticky Save bar sits flush with the card's edges. */
.item-form .sticky-bar {
  margin: var(--space-2) calc(var(--space-4) * -1) calc(var(--space-4) * -1);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* The stock dialog: everything in a column, buttons inside the body. */
.stock-dialog .summary {
  margin: 0;
}

/* The new-category dialog is wider so the icon grid has room. */
.category-dialog {
  width: min(560px, calc(100vw - var(--space-6)));
}


/* -----------------------------------------------------------------------------
   IMPORT
   ----------------------------------------------------------------------------- */

.import {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
}

.import__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.import__head h1 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-heading);
}

.import__step {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.import__step p {
  margin: 0;
}

/* The file button is a label round a hidden input. */
.import__pick {
  align-self: flex-start;
}

.import__counts {
  font-weight: var(--font-medium);
}

.import__actions {
  display: flex;
  justify-content: flex-end;
}

.import__saved {
  margin: 0;
  padding: 0 0 0 var(--space-4);
  columns: 2;
  column-gap: var(--space-5);
}

@media (max-width: 480px) {
  .import__saved {
    columns: 1;
  }
}
