/* ==========================================
   Side Sheet (Bootstrap Offcanvas wrapper)
   ========================================== */

.side-sheet {
  --bs-offcanvas-width: 720px;
  width: 720px;
  max-width: 96vw;
  border-left: 1px solid var(--color-line);
  box-shadow: var(--shadow-sheet);
}

.side-sheet.offcanvas-start {
  border-left: none;
  border-right: 1px solid var(--color-line);
  box-shadow: var(--shadow-sheet-start);
}

.side-sheet-header {
  background: var(--color-shell);
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--shell-line);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-shrink: 0;
}

.side-sheet-header-text {
  flex: 1;
  min-width: 0;
}

.side-sheet-title {
  color: var(--color-surface);
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-sheet-subtitle {
  color: var(--shell-text-mute);
  font-size: 0.78rem;
  margin: 0.18rem 0 0;
  line-height: 1.3;
  min-height: 1em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-sheet-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--shell-line-strong);
  background: transparent;
  color: var(--shell-text-mute);
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
  padding: 0;
}

.side-sheet-close:hover {
  background: var(--shell-hover);
  color: var(--color-surface);
  border-color: var(--shell-line-strong);
}

.side-sheet-body {
  padding: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-line-strong) transparent;
}

.side-sheet-body::-webkit-scrollbar {
  width: 4px;
}

.side-sheet-body::-webkit-scrollbar-track {
  background: transparent;
}

.side-sheet-body::-webkit-scrollbar-thumb {
  background: var(--tint-3);
  border-radius: 2px;
}

/* ---- Editable fields ---- */
.sheet-field {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  border-radius: var(--radius);
  padding: 0.375rem 0.75rem;
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: var(--color-shell);
  width: 100%;
  resize: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.sheet-field:hover:not(:focus) {
  border-color: var(--color-ink-mute);
}

.sheet-field:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--field-ring);
}

/* Edited but unsaved: same field, accent border */
.sheet-field--dirty {
  border-color: color-mix(in srgb, var(--color-accent) 55%, transparent);
}

select.sheet-field {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234a5364' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 10px;
  padding-right: 2.25rem;
}

select.sheet-field:focus,
select.sheet-field.sheet-field--dirty {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b8283f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 10px;
}

textarea.sheet-field {
  display: block;
  min-height: 3.5rem;
  line-height: 1.55;
}

/* ---- Edit bar (sticky footer, hidden until dirty) ---- */
.sheet-edit-bar {
  position: sticky;
  bottom: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-line-soft);
  padding: 0.8rem 1.4rem;
  box-shadow: 0 -6px 20px rgba(16, 24, 40, 0.07); /* upward shadow for sticky bar */
  z-index: 1;
}

.sheet-edit-bar--always {
  display: flex;
}

.sheet-edit-error {
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
}

.sheet-edit-actions {
  display: flex;
  gap: 0.5rem;
}

.sheet-edit-actions .btn {
  flex: 1;
}

/* ---- Loading skeleton ---- */
.side-sheet-skeleton {
  padding: 1.5rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.side-sheet-skeleton__block {
  background: linear-gradient(90deg, var(--tint-2) 25%, var(--tint-3) 50%, var(--tint-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: sheet-shimmer 1.4s ease infinite;
}

@keyframes sheet-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.sheet-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  padding: 0.5rem 1.4rem 0.75rem;
  border-bottom: 1px solid var(--color-line-soft);
}

.sheet-meta__row {
  padding: 0.6rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sheet-meta__row:not(:last-child):not(:nth-last-child(2)) {
  border-bottom: 1px solid var(--color-line-soft);
}

.sheet-meta dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-ink-mute);
  margin: 0;
}

.sheet-meta dd {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-shell);
  margin: 0;
  line-height: 1.3;
}

.sheet-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-ink-mute);
  margin: 0;
}

/* Error / failed-load inline message */
.sheet-load-error {
  padding: 1.4rem;
  font-size: 0.875rem;
  color: var(--color-ink-mute);
}

/* ==========================================
   Create-form layout (label-above-input pattern)
   Used inside side sheets for entity creation.
   ========================================== */

.sheet-form-body {
  padding: 1.25rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Two-up grid for wide create forms (e.g. User with Name + Email side-by-side) */
.sheet-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.sheet-form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* .sheet-form-field--full spans both columns inside .sheet-form-row */
.sheet-form-row .sheet-form-field--full {
  grid-column: 1 / -1;
}

.sheet-form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-ink-soft);
  user-select: none;
}

/* .sheet-field--bordered is now an alias — base sheet-field already applies
   the bordered appearance. Kept for backward compatibility. */

/* Inline validation error inside the create form body */
.sheet-form-error {
  padding: 0.6rem 0.75rem;
  background: var(--tint-2);
  border: 1px solid var(--color-line);
  border-left: 3px solid var(--color-line-strong);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--color-shell);
  line-height: 1.5;
}

.sheet-form-error:empty,
.sheet-form-error .validation-summary-valid:only-child {
  display: none;
}

/* ==========================================
   Discard guard — sticky bar shown when user
   tries to close with unsaved changes
   ========================================== */

.sheet-discard-guard {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  border-bottom: 2px solid color-mix(in srgb, var(--color-accent) 25%, transparent);
  padding: 0.8rem 1.4rem;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-md);
  animation: sheet-guard-slide 0.15s ease;
}

@keyframes sheet-guard-slide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sheet-discard-guard__text {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--color-shell);
  margin: 0;
}

.sheet-discard-guard__actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.sheet-discard-guard__actions .btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
}

/* ==========================================
   Mobile layout
   ========================================== */

/* ==========================================
   Sheet tabs
   ========================================== */

.sheet-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-line-soft);
  padding: 0 1.4rem;
  flex-shrink: 0;
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.sheet-tab {
  padding: 0.7rem 0;
  margin-right: 1.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-ink-mute);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: color 0.14s, border-color 0.14s;
  white-space: nowrap;
  margin-bottom: -1px;
  line-height: 1.4;
}

.sheet-tab:hover {
  color: var(--color-shell);
}

.sheet-tab--active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.sheet-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius);
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--tint-3);
  color: var(--color-ink-mute);
  margin-left: 0.35em;
  letter-spacing: 0;
  vertical-align: middle;
}

.sheet-tab--active .sheet-tab-badge {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
  color: var(--color-accent);
}

.sheet-tab-panel[hidden] {
  display: none;
}

/* ==========================================
   Mobile layout
   ========================================== */

@media (max-width: 575.98px) {
  .side-sheet {
    width: 100%;
    max-width: 100%;
  }

  .sheet-meta {
    grid-template-columns: 1fr;
  }

  .sheet-form-row {
    grid-template-columns: 1fr;
  }

  .sheet-discard-guard {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .sheet-discard-guard__actions {
    width: 100%;
  }

  .sheet-discard-guard__actions .btn {
    flex: 1;
  }

}

/* ==========================================
   Product sheet: option lists, inline add rows, image cards
   ========================================== */

.sheet-tab-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-ink-mute);
}

.sheet-section-title--spaced {
  margin-top: 0.6rem;
}

.sheet-option-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sheet-option-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius);
  font-size: 0.88rem;
}

.sheet-option-row__label {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.sheet-option-row--empty {
  border-style: dashed;
  color: var(--color-ink-mute);
}

.sheet-swatch {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-line-strong);
  flex-shrink: 0;
}

.sheet-inline-add {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sheet-inline-add > .form-control,
.sheet-inline-add > .form-select {
  flex: 1 1 8rem;
  min-width: 0;
}

.sheet-inline-add > .sheet-inline-add__narrow {
  flex: 0 1 6.5rem;
}

.sheet-image-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem;
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-lg);
}

.sheet-image-card__thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius);
  flex-shrink: 0;
  background: var(--tint-2);
}

.sheet-image-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sheet-image-card__scope {
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--tint-3);
  color: var(--color-ink-soft);
}

.sheet-image-card__scope--specific {
  background: var(--color-ok-wash);
  color: var(--color-accent);
}

.sheet-image-card__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.sheet-image-replace {
  cursor: pointer;
  position: relative;
}

.sheet-image-replace > input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.sheet-image-card__name {
  font-size: 0.72rem;
  color: var(--color-ink-soft);
  overflow-wrap: anywhere;
}

.sheet-image-card__selects {
  display: flex;
  gap: 0.5rem;
}

.sheet-image-card__selects > select {
  flex: 1;
  min-width: 0;
}

.sheet-image-add {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@media (max-width: 575.98px) {
  .sheet-image-card {
    flex-wrap: wrap;
  }
  .sheet-image-card__selects {
    flex-direction: column;
  }

}

.sheet-attribute {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-lg);
}

.sheet-attribute__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sheet-attribute__name {
  font-weight: 600;
}
