/* ==========================================================================
   AYS.HƏDİYYƏ — Backoffice (custom admin panel)
   App-shell styles for admin.ayshediyye.store. Loaded on top of tokens.css,
   reusing the same palette/type/spacing/radius scale as the storefront (and
   its shared .btn classes) so the panel reads as the same brand, not a
   generic bolted-on admin theme.
   ========================================================================== */

body.bo {
  font-family: var(--font-ui);
}

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

/* --------------------------- Sidebar --------------------------- */
.bo-sidebar {
  display: flex;
  flex-direction: column;
  width: 264px;
  flex: 0 0 264px;
  padding: var(--space-3);
  background: var(--color-ink);
  color: var(--color-paper-text);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform var(--duration-base) var(--ease-editorial);
  overflow-y: auto;
}
.bo-sidebar.is-open { transform: translateX(0); }

.bo-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-line-on-ink);
  font-family: var(--font-display);
  color: var(--color-paper-text);
}
.bo-sidebar__logo { width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto; }
.bo-sidebar__brand span { display: flex; flex-direction: column; font-size: 1rem; }
.bo-sidebar__brand em { font-style: normal; font-size: var(--text-ui-xs); opacity: 0.6; letter-spacing: var(--tracking-wide); }

.bo-sidebar__nav { display: flex; flex-direction: column; gap: 4px; }
.bo-sidebar__nav a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-ui-sm);
  font-weight: 500;
  color: var(--color-paper-text);
  opacity: 0.75;
  transition: background-color var(--duration-fast) var(--ease-editorial), opacity var(--duration-fast) var(--ease-editorial);
}
.bo-sidebar__nav a .icon { width: 18px; height: 18px; }
.bo-sidebar__nav a:hover { opacity: 1; background: rgba(247, 242, 234, 0.06); }
.bo-sidebar__nav a.is-active { opacity: 1; background: var(--color-gold); color: var(--color-ink); }

.bo-sidebar__footer {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-line-on-ink);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.bo-sidebar__django-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-ui-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  opacity: 0.55;
  color: var(--color-paper-text);
}
.bo-sidebar__django-link .icon { width: 14px; height: 14px; }
.bo-sidebar__django-link:hover { opacity: 0.9; }
.bo-sidebar__logout-form { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.bo-sidebar__logout-form span { font-size: var(--text-ui-sm); opacity: 0.7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bo-sidebar__logout-form button {
  font-size: var(--text-ui-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-gold-soft);
  padding: 6px 12px;
  border: 1px solid var(--color-line-on-ink);
  border-radius: var(--radius-full);
  flex: 0 0 auto;
}
.bo-sidebar__logout-form button:hover { border-color: var(--color-gold-soft); }

.bo-scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgba(22, 21, 26, 0.5);
  z-index: 55;
}
.bo-scrim.is-open { display: block; }

/* Locked while the mobile sidebar drawer is open, so the page behind the
   scrim can't scroll underneath it (applied/removed by backoffice.js). */
body.bo-scroll-lock { overflow: hidden; }

/* --------------------------- Main / topbar --------------------------- */
.bo-main { flex: 1; min-width: 0; padding: var(--space-3) var(--space-4) var(--space-16); }

.bo-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.bo-topbar__title { font-family: var(--font-display); font-weight: 500; font-size: var(--text-display-sm); flex: 1; min-width: 0; overflow-wrap: break-word; }
.bo-topbar__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.bo-topbar__actions .btn { flex: 1 1 auto; justify-content: center; }

/* --------------------------- Top tab bar (mobile/tablet) ---------------------------
   The app's primary navigation below 1024px, replacing the old top-left
   hamburger — fixed to the top of the viewport (always visible, like the
   desktop sidebar), safe-area-aware for notched phones. */
.bo-tabbar {
  display: none;
  position: fixed; left: 0; right: 0; top: 0; z-index: 70;
  background: var(--color-paper);
  border-bottom: 1px solid var(--border-subtle);
  padding: calc(4px + env(safe-area-inset-top, 0px)) max(env(safe-area-inset-right, 0px), 4px) 4px max(env(safe-area-inset-left, 0px), 4px);
  box-shadow: 0 12px 24px -18px rgba(36, 30, 22, 0.35);
}
.bo-tabbar__item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 54px;
  padding: 6px 2px;
  border-radius: var(--radius-sm);
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  color: var(--text-primary); opacity: 0.5;
  transition: opacity var(--duration-fast) var(--ease-editorial), color var(--duration-fast) var(--ease-editorial);
}
.bo-tabbar__item .icon { width: 22px; height: 22px; }
.bo-tabbar__item.is-active { opacity: 1; color: var(--color-gold-deep); }
.bo-tabbar__item:active { opacity: 1; background: var(--bg-surface); }

/* A page's primary "+ Yeni ..." action (page_actions' .btn--primary) floats
   as a FAB near the bottom of the screen on mobile instead of sitting in
   the topbar — secondary actions (e.g. "Excel-dən idxal et") stay put. */
@media (max-width: 1023px) {
  .bo-topbar__actions .btn--primary {
    position: fixed;
    right: max(env(safe-area-inset-right, 0px), var(--space-3));
    bottom: max(env(safe-area-inset-bottom, 0px), var(--space-3));
    z-index: 65;
    box-shadow: var(--shadow-lift);
  }
}

@media (max-width: 640px) {
  .bo-main { padding-left: var(--space-2); padding-right: var(--space-2); }
  .bo-card { padding: var(--space-2); }
  .bo-topbar__title { font-size: 1.375rem; }
}

@media (max-width: 1023px) {
  .bo-tabbar { display: flex; }
  .bo-main { padding-top: calc(64px + env(safe-area-inset-top, 0px) + var(--space-3)); }
}

@media (min-width: 1024px) {
  .bo-sidebar { transform: none; position: sticky; height: 100vh; }
  .bo-scrim { display: none !important; }
  body.bo-scroll-lock { overflow: auto; }
}

/* --------------------------- Buttons (danger variant) --------------------------- */
.bo-btn--danger { background: var(--color-rose-deep); border-color: var(--color-rose-deep); color: var(--color-paper-text); }
.bo-btn--danger:hover { background: transparent; color: var(--color-rose-deep); }
.bo-link--danger { color: var(--color-rose-deep); }

/* --------------------------- Alerts --------------------------- */
.bo-messages { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }
.bo-alert {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-ui-sm);
  border: 1px solid transparent;
}
.bo-alert--success { background: rgba(110, 122, 92, 0.12); border-color: var(--color-sage); color: var(--color-sage); }
.bo-alert--error { background: rgba(140, 92, 86, 0.12); border-color: var(--color-rose-deep); color: var(--color-rose-deep); }
.bo-alert--warning { background: rgba(169, 129, 79, 0.12); border-color: var(--color-gold-deep); color: var(--color-gold-deep); }
.bo-alert--info { background: var(--bg-surface); border-color: var(--border-subtle); color: var(--text-primary); }

/* --------------------------- Card / table --------------------------- */
.bo-card {
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-soft);
}
.bo-card__footer { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border-subtle); }

/* Below ~640px the table itself would squeeze columns unreadably thin —
   the wrapper scrolls horizontally instead, so the page never does. */
.bo-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bo-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: var(--text-ui-sm); }
.bo-table th {
  text-align: left;
  font-size: var(--text-ui-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  opacity: 0.55;
  padding: 0 var(--space-2) var(--space-2);
}
.bo-table td { padding: 10px var(--space-2); border-top: 1px solid var(--border-subtle); vertical-align: middle; }
.bo-table tbody tr:hover { background: var(--bg-surface); }
.bo-table__thumb { width: 52px; }
.bo-table__thumb img { width: 44px; height: 44px; object-fit: cover; border-radius: var(--radius-sm); }
.bo-table__thumb-placeholder { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--bg-surface); opacity: 0.4; }
.bo-table__actions { text-align: right; white-space: nowrap; }
.bo-table__actions a { font-weight: 600; font-size: var(--text-ui-xs); text-transform: uppercase; letter-spacing: var(--tracking-wide); margin-left: var(--space-2); }
.bo-table__title { font-family: var(--font-display); font-size: 1.05rem; }

/* On a phone, a table (even a horizontally-scrolling one) reads as "a
   website", not an app — below 768px each row becomes its own card instead,
   field labels taken from each cell's data-label. .bo-card--table sheds its
   own chrome here so the row-cards are the visible unit, not double-nested
   inside an outer card. */
@media (max-width: 767px) {
  .bo-card--table { background: transparent; border: 0; box-shadow: none; padding: 0; }
  /* The card's own padding no longer exists to inset it — restore it just
     for the footer (e.g. category list's "Sıralamanı yadda saxla" button),
     since each row now carries its own card padding instead. */
  .bo-card--table > .bo-card__footer { padding-left: var(--space-2); padding-right: var(--space-2); }
  .bo-table-wrap { overflow-x: visible; }
  .bo-table { min-width: 0; }
  .bo-table thead { display: none; }
  .bo-table, .bo-table tbody, .bo-table tr, .bo-table td { display: block; width: 100%; }
  .bo-table tr {
    margin-bottom: var(--space-2);
    background: var(--bg-page);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0 var(--space-2);
    box-shadow: var(--shadow-soft);
  }
  .bo-table tbody tr:hover { background: var(--bg-page); }
  .bo-table td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
    padding: 10px 0; border-top: 1px solid var(--border-subtle);
  }
  .bo-table tr td:first-child { border-top: 0; }
  .bo-table td::before {
    content: attr(data-label);
    font-size: var(--text-ui-xs); font-weight: 700; text-transform: uppercase;
    letter-spacing: var(--tracking-wide); opacity: 0.45; flex: 0 0 auto;
  }
  .bo-table__thumb, .bo-table__title, .bo-table__actions { justify-content: flex-start; }
  .bo-table__thumb::before, .bo-table__title::before { display: none; }
  .bo-table__actions { justify-content: flex-end; }
  .bo-table__actions::before { display: none; }
  .bo-table__actions a { margin-left: 0; margin-right: var(--space-3); }
  .bo-table__actions a:last-child { margin-right: 0; }
}

.bo-order-input { width: 64px; padding: 6px 8px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); font: inherit; background: var(--bg-page); color: var(--text-primary); }

.bo-pill {
  font-size: var(--text-ui-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}
.bo-pill--on { background: rgba(110, 122, 92, 0.14); color: var(--color-sage); }
.bo-pill--off { background: var(--bg-surface); color: var(--text-primary); opacity: 0.5; }
.bo-pill:hover { border-color: currentColor; }

.bo-empty { padding: var(--space-6) 0; text-align: center; font-family: var(--font-display); font-style: italic; opacity: 0.6; }

.bo-pagination { display: flex; align-items: center; justify-content: center; gap: var(--space-3); margin-top: var(--space-3); font-size: var(--text-ui-sm); }
.bo-pagination a { font-weight: 600; }

/* --------------------------- Filters --------------------------- */
.bo-filters { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-3); }
.bo-filters select, .bo-filters input[type="search"] {
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-ui-sm);
  background: var(--bg-page);
  color: var(--text-primary);
}
.bo-filters__search { flex: 1 1 220px; min-width: 180px; }
.bo-filters__reset { font-size: var(--text-ui-sm); text-decoration: underline; opacity: 0.7; }

@media (max-width: 560px) {
  .bo-filters { flex-direction: column; align-items: stretch; }
  .bo-filters select, .bo-filters input[type="search"] { width: 100%; }
  .bo-filters .btn { width: 100%; justify-content: center; }
}

/* --------------------------- Forms --------------------------- */
.bo-form { max-width: 640px; }
.bo-form__intro { max-width: 640px; margin-bottom: var(--space-3); opacity: 0.75; font-size: var(--text-ui-sm); }
.bo-form__subheading { font-family: var(--font-display); font-weight: 500; font-size: var(--text-ui-lg); margin: var(--space-4) 0 var(--space-2); }

.bo-field { margin-bottom: var(--space-3); }
.bo-field label { display: block; font-size: var(--text-ui-sm); font-weight: 600; margin-bottom: 6px; }
.bo-field input[type="text"],
.bo-field input[type="number"],
.bo-field input[type="password"],
.bo-field input[type="search"],
.bo-field select,
.bo-field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--text-ui-base);
  background: var(--bg-page);
  color: var(--text-primary);
}
.bo-field textarea { resize: vertical; }
.bo-field input:focus-visible, .bo-field select:focus-visible, .bo-field textarea:focus-visible {
  outline: 2px solid var(--color-gold); outline-offset: 2px;
}
.bo-field--checkbox label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.bo-field--checkbox input { width: auto; }
.bo-field__hint { font-size: var(--text-ui-xs); opacity: 0.55; margin-top: 4px; }

/* ---- Styled (non-image) file picker (backoffice.widgets.StyledFileInput
   and the plain "images" bulk-upload input on the Excel import page) ---- */
.bo-file-input { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.bo-file-input__button { cursor: pointer; }
.bo-file-input__name { font-size: var(--text-ui-sm); opacity: 0.65; word-break: break-word; }
.bo-field__error { font-size: var(--text-ui-xs); color: var(--color-rose-deep); margin-top: 4px; }
.bo-field.has-error input, .bo-field.has-error select, .bo-field.has-error textarea { border-color: var(--color-rose-deep); }
/* ---- Thumbnail file input (backoffice.widgets.ThumbnailFileInput) ----
   One clickable-thumbnail component reused for every image field: the main
   product/category image (inside .bo-field, capped to a modest size) and
   each gallery formset slot (inside .bo-gallery-formset__item, filling the
   grid cell). Replaces the raw browser "Choose File" control and Django's
   default "Currently: <link>" text with a live preview + "+ şəkil"
   placeholder. ---- */
.bo-thumbnail-input { position: relative; width: 100%; max-width: 160px; }
.bo-gallery-formset__item .bo-thumbnail-input { max-width: none; }

.bo-thumbnail-input__preview-label {
  display: block;
  position: relative;
  aspect-ratio: 1;
  cursor: pointer;
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-surface);
}
.bo-thumbnail-input__preview { width: 100%; height: 100%; object-fit: cover; }
.bo-thumbnail-input__preview[hidden] { display: none; }
.bo-thumbnail-input__placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: var(--text-ui-xs); opacity: 0.45; text-align: center; padding: var(--space-1);
}
.bo-thumbnail-input__placeholder[hidden] { display: none; }
.bo-thumbnail-input__preview-label input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; padding: 0;
}
.bo-thumbnail-input__clear-pending {
  position: absolute; top: 4px; right: 4px; z-index: 1;
  width: 22px; height: 22px; line-height: 20px; text-align: center; padding: 0;
  border-radius: 50%; background: var(--color-ink); color: var(--color-paper-text);
  font-size: 14px; opacity: 0.85;
}
.bo-thumbnail-input__clear-pending:hover { opacity: 1; }
.bo-thumbnail-input__clear-pending[hidden] { display: none; }
.bo-thumbnail-input__clear-existing {
  display: flex; align-items: center; gap: 6px; margin-top: var(--space-1);
  font-size: var(--text-ui-xs); color: var(--color-rose-deep); font-weight: 600;
}
.bo-thumbnail-input__clear-existing input { width: auto; }

.bo-gallery-picker { display: inline-flex; cursor: pointer; margin-bottom: var(--space-2); }

.bo-gallery-formset { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-3); }
.bo-gallery-formset__item { display: flex; flex-direction: column; gap: var(--space-1); }

.bo-gallery-formset__meta { display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); }
.bo-gallery-formset__meta label { font-size: var(--text-ui-xs); font-weight: 600; display: flex; align-items: center; gap: 4px; margin: 0; }
.bo-gallery-formset__meta input[type="number"] {
  width: 52px; padding: 4px 6px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); font: inherit; font-size: var(--text-ui-xs);
}
.bo-gallery-formset__delete { color: var(--color-rose-deep); }
.bo-gallery-formset__delete input { width: auto; }

.bo-confirm { max-width: 480px; }
.bo-confirm p { margin-bottom: var(--space-3); }
.bo-confirm form { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.bo-confirm form .btn { flex: 1 1 auto; justify-content: center; }

/* --------------------------- Login --------------------------- */
.bo-login-page { background: var(--color-ink); }
.bo-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-3); }
.bo-login__card {
  width: 100%; max-width: 360px;
  background: var(--bg-page);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-4);
  box-shadow: var(--shadow-lift);
  text-align: center;
}
.bo-login__logo { width: 56px; height: 56px; margin: 0 auto var(--space-2); border-radius: 50%; }
.bo-login__card h1 { font-family: var(--font-display); font-weight: 500; font-size: var(--text-display-sm); }
.bo-login__sub { opacity: 0.6; font-size: var(--text-ui-sm); margin: var(--space-1) 0 var(--space-3); }
.bo-login__card label { display: block; text-align: left; font-size: var(--text-ui-sm); font-weight: 600; margin-bottom: 6px; }
.bo-login__card input {
  width: 100%; padding: 10px 14px; margin-bottom: var(--space-2);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  font: inherit; background: var(--bg-page); color: var(--text-primary);
}
.bo-login__card input:focus-visible { outline: 2px solid var(--color-gold); outline-offset: 2px; }
.bo-login__submit { width: 100%; justify-content: center; margin-top: var(--space-2); }
.bo-login__card .bo-alert { text-align: left; margin-bottom: var(--space-2); }
