/*
 * inventory.css — Inventory tab: grid of inventory cards + inventory editor overlay.
 *
 * Mirrors the habits tab layout (header with title/count/add, a responsive
 * card grid). Each card shows the item's name + unit, a large remaining
 * amount (the countdown), a "Low — reorder" badge when remaining is at/below
 * the lower limit, and the habits linked to it.
 *
 * Load after habits.css.
 */

/* ---- Panel container ---------------------------------------------------- */
.inventory {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Header (title + count + add) --------------------------------------- */
.inventory__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.inventory__header .panel__title {
  margin: 0;
}

.inventory__count {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.inventory__header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.inventory__add {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.inventory__add:hover {
  background: color-mix(in srgb, var(--accent) 25%, var(--surface));
}

/* ---- Grid ---------------------------------------------------------------- */
.inventory__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  align-content: start;
}

/* ---- Empty state --------------------------------------------------------- */
.inventory__empty {
  grid-column: 1 / -1;
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ---- Inventory card ------------------------------------------------------ */
.inventory-card {
  display: flex;
  flex-direction: column;
  min-height: 110px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition);
}

.inventory-card:hover,
.inventory-card:focus-visible {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  outline: none;
}

.inventory-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
}

.inventory-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inventory-card__title-group {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.inventory-card__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-card__unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Remaining amount — the countdown, shown large */
.inventory-card__remaining {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.inventory-card__linked {
  margin-top: auto;
  font-size: 0.6875rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Low state: danger-tinted border + badge */
.inventory-card--low {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.inventory-card--low .inventory-card__remaining {
  color: var(--danger);
}

.inventory-card__badge {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  width: fit-content;
}

.inventory-card__badge--low {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

/* ---- Inventory module row (in entry detail) ------------------------------ */
.entry-detail__module--inventory {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.entry-detail__inventory-input {
  width: 4.5em;
  padding: 0.25em 0.5em;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input, transparent);
  color: var(--text);
}

.entry-detail__module--low .overlay__label {
  color: var(--danger);
  font-weight: 600;
}

/* ---- Inventory editor overlay -------------------------------------------- */
.inventory-editor__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inventory-editor__row {
  display: flex;
  gap: 12px;
}

.inventory-editor__row .inventory-editor__field {
  flex: 1;
  min-width: 0;
}

.inventory-editor__footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

@media (prefers-reduced-motion: reduce) {
  .inventory-card,
  .inventory__add {
    transition: none;
  }
}
