/* ── Layout ────────────────────────────────────────────── */
:root {
  --sidebar-w: 250px;
  --pico-font-size: 85%;

  /* Matte slate-blue palette */
  --pico-primary:               #3b5f8a;
  --pico-primary-hover:         #2d4d73;
  --pico-primary-focus:         rgba(59, 95, 138, 0.2);
  --pico-primary-inverse:       #fff;
  --pico-primary-background:    #edf1f7;
  
  --pico-secondary:             #6b7a8d;
  --pico-secondary-hover:       #55606e;
  --pico-secondary-focus:       rgba(107, 122, 141, 0.2);
  --pico-secondary-inverse:     #fff;
  --pico-secondary-background: #f5f7fa;

  /* Text */
  --pico-color:                 #1e2d3d;
  --pico-muted-color:           #6b7a8d;
  --pico-h1-color:              #1e2d3d;
  --pico-h2-color:              #1e2d3d;

  /* Surfaces */
  --pico-background-color:      #f5f7fa;
  --pico-card-background-color: #eef1f6;

  /* Borders */
  --pico-muted-border-color:    #d6dce6;
  --pico-border-color:          #c4cdd9;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  overflow: hidden;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pico-background-color);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
}

/* ── Sidebar ───────────────────────────────────────────── */
.cms-sidebar {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--pico-muted-border-color);
  padding: 1rem 0.75rem;
  background: var(--pico-card-background-color);
}

.sidebar-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  justify-content:space-between;
}

.sidebar-header strong {
  font-size: 0.95rem;
}

.user-badge-admin {
  font-size: 0.7rem;
  background: #ed3434;
  color: #fff;
  padding: 0.3rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
}

.user-badge-manager {
  font-size: 0.7rem;
  background: var(--pico-primary-background);
  color: #fff;
  padding: 0.3rem 0.4rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav details {
  margin-bottom: 0.25rem;
}

.sidebar-nav summary {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pico-muted-color);
  padding: 0.3rem 0;
  cursor: pointer;
}

.sidebar-nav ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0 0.75rem;
}

.sidebar-nav li { margin: 0; }

.sidebar-nav a {
  display: block;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--pico-color);
}

.sidebar-nav a:hover {
  background: var(--pico-secondary-background);
  color: var(--pico-primary-inverse);
}

.sidebar-nav a.active {
  background: var(--pico-secondary-background);
  color: var(--pico-primary-inverse);
  font-weight: 600;
}

.no-stores {
  font-size: 0.8rem;
  color: var(--pico-muted-color);
}

.sidebar-tools {
  padding: 0.6rem 0.75rem 0.6rem;
  border-top: 1px solid var(--pico-muted-border-color);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-tools a {
  font-size: 0.82rem;
  color: var(--pico-primary);
  text-decoration: none;
  padding: 0.15rem 0;
}

.sidebar-tools span{
  font-size: 0.8rem;
  color: var(--pico-muted-color);
  font-style: italic;
}

.sidebar-tools a:hover {
  color: var(--pico-primary);
}

.sidebar-footer {
  font-size: 0.78rem;
  padding-top: 0.75rem;
  padding-left: 0.5rem;
  border-top: 1px solid var(--pico-muted-border-color);
  color: var(--pico-muted-color);
}

.user-email {
  margin-top: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main content ──────────────────────────────────────── */
.cms-main {
  overflow-y: auto;
  padding: 1.5rem 2rem;
}

body > main.cms-main {
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

/* ── Shared ────────────────────────────────────────────── */
.inline-form {
  display: inline-flex;
}

.link-btn {
  background: none;
  border: none;
  color: var(--pico-primary);
  cursor: pointer;
  padding: 0;
  font: inherit;
  font-size: inherit;
}

.link-btn.danger { color: var(--pico-del-color); }

.flash-error {
  color: var(--pico-del-color);
  border: 1px solid var(--pico-del-color);
  padding: 0.5rem 0.75rem;
  border-radius: var(--pico-border-radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.small-btn {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
}

.small-btn.secondary {
  background-color: var(--pico-secondary);
  color: var(--pico-primary-inverse);
}

/* ── Pull banner ───────────────────────────────────────── */
.pull-banner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}

.pull-info {
  position: relative;
  cursor: help;
  font-size: 1rem;
  color: var(--pico-muted-color);
  line-height: 1;
}

.pull-info::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--pico-color);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 10;
}

.pull-info:hover::after {
  opacity: 1;
}

/* ── Screen ────────────────────────────────────────────── */
.screen-header { display:flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.screen-header h2 { margin: 0; font-size: 1.25rem; }
.screen-desc   { color: var(--pico-muted-color); font-size: 0.9rem; margin-bottom: 1rem; }

.screen-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1rem;
}
.screen-actions button { font-size: 0.85rem; } 
.screen-actions button.outlined { background-color: transparent; color:var(--pico-primary) } 

.screen-actions button:hover { border-bottom:2px solid var(--pico-primary); transform: translateY(-1px); } 
#grid-container { position: relative; margin-bottom: 1rem; }
#grid .tabulator-col { height: 40px !important; min-height: 40px !important; }
#grid:not(.filters-hidden) .tabulator-col { height: 70px !important; min-height: 80px !important; }
#grid.filters-hidden .tabulator-header-filter { display: none; }

/* ── Pending edits ─────────────────────────────────────── */
#pending-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  z-index: 10;
  background: #d97706;
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  pointer-events: none;
  line-height: 1.8;
}

.tabulator-row.row-pending { background-color: #fffbeb !important; cursor: pointer; }
.tabulator-row.row-pending:hover { background-color: #fef3c7 !important; }

/* ── Diff dialog ────────────────────────────────────────── */
#diff-dialog {
  border: none;
  border-radius: var(--pico-border-radius);
  padding: 1.5rem;
  min-width: 500px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  margin-top: 2rem;
  margin-bottom: auto;
  flex-direction: column;
}
#diff-dialog::backdrop { background: rgba(0,0,0,0.35); }

.diff-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.diff-header h3 { margin: 0; font-size: 1rem; }

.diff-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--pico-muted-color);
  padding: 0;
  line-height: 1;
}
.diff-close:hover { color: var(--pico-color); }

.diff-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.diff-table th,
.diff-table td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--pico-muted-border-color); }
.diff-table th { font-size: 0.75rem; font-weight: 600; color: var(--pico-muted-color); text-transform: uppercase; }

.diff-changed td:nth-child(2) { color: var(--pico-muted-color); text-decoration: line-through; }
.diff-changed td:nth-child(3) { color: #d97706; font-weight: 600; }

.diff-empty { color: var(--pico-muted-color); font-style: normal; }

.diff-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}
.diff-discard-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.9rem;
  background: none;
  border: 1px solid var(--pico-del-color);
  color: var(--pico-del-color);
  border-radius: var(--pico-border-radius);
  cursor: pointer;
}
.diff-discard-btn:hover { background: rgba(220,53,69,0.06); }

/* -- Row delete button (inside Tabulator cell) ----------- */
.row-delete-btn {
  cursor: pointer;
  color: var(--pico-muted-color);
  font-size: 0.9rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}
.row-delete-btn:hover {
  color: var(--pico-del-color);
  background: rgba(220, 53, 69, 0.08);
}
/* ── HTMX indicator ────────────────────────────────────── */
.htmx-indicator { display: none; font-size: 0.85rem; color: var(--pico-muted-color); }
.htmx-request .htmx-indicator { display: inline; }

.copy-loading-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  color: #1e40af;
  font-size: 0.9rem;
  font-weight: 500;
}
.htmx-request .copy-loading-banner.htmx-indicator {
  display: block;
  animation: copy-loading-pulse 1.4s ease-in-out infinite;
}
@keyframes copy-loading-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ── Result card ───────────────────────────────────────── */
.result-card {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--pico-border-radius);
  border: 1px solid var(--pico-muted-border-color);
  font-size: 0.9rem;
}
.result-ok {
  border-color: var(--pico-ins-color);
  animation: result-success-flash 5s ease-out;
}
.result-fail { border-color: var(--pico-del-color); }

@keyframes result-success-flash {
  0%, 70% {
    background: #dcfce7;
  }

  100% {
    background: transparent;
  }
}

/* ── Users ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.role-badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}
.role-admin   { background: #e8f4fd; color: #0369a1; }
.role-manager { background: #f0fdf4; color: #15803d; }

.badge-cms {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #ede9fe;
  color: #6d28d9;
}
.badge-auto {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #64748b;
}

.row-actions { display: flex; gap: 0.75rem; align-items: center; white-space: nowrap; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1.5rem;
}

/* ── Job status ────────────────────────────────────────── */
.status-success  { color: var(--pico-ins-color); }
.status-failed   { color: var(--pico-del-color); }
.status-running  { color: var(--pico-primary); }

/* ── Product copy ──────────────────────────────────────── */
.copy-products-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(180px, 260px) auto 1fr;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.copy-products-form label { margin: 0; }
.copy-products-form button { margin: 0; }

.product-copy-results { margin-top: 1rem; }

.product-copy-toolbar {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  margin: 1rem 0 0.75rem;
}

.product-copy-toolbar button {
  margin: 0 0 0 auto;
  width: auto;
}

.product-copy-table-wrap {
  max-height: 68vh;
  overflow: auto;
}

.product-copy-table {
  font-size: 0.84rem;
}

.product-copy-table th:first-child,
.product-copy-table td:first-child {
  width: 42px;
  text-align: center;
}

.product-copy-table th:nth-child(2),
.product-copy-table td:nth-child(2) {
  width: 170px;
}

.product-copy-table td {
  vertical-align: top;
}

.product-copy-sku {
  display: inline-block;
  padding: 0.18rem 0.45rem;
  border-radius: 4px;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.product-copy-state-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.product-copy-state {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
}

.product-copy-aligned .product-copy-state {
  background: #dcfce7;
  color: #166534;
}

.product-copy-copyable .product-copy-state {
  background: #fffbeb;
  color: #b45309;
}

.product-copy-target-only .product-copy-state {
  background: #e0f2fe;
  color: #0369a1;
}

.product-copy-field-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.product-copy-image-count {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--pico-color);
}

.product-copy-image-names {
  margin-top: 0.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}

.product-copy-image-names .product-copy-field-badge {
  font-weight: 400;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-copy-field-title {
  background: #fef3c7;
  color: #a16207;
  border-color: #fde68a;
}

.product-copy-field-handle {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

.product-copy-field-price {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

@media (max-width: 900px) {
  .copy-products-form {
    grid-template-columns: 1fr;
  }

  .product-copy-toolbar {
    flex-wrap: wrap;
  }

  .product-copy-toolbar button {
    margin-left: 0;
  }
}

/* ── Gallery ──────────────────────────────────────────── */
.gallery-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.gallery-folders,
.gallery-content {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 6px;
  background: #fff;
}

.gallery-folders {
  position: sticky;
  top: 0;
  max-height: calc(100vh - 3rem);
  overflow: auto;
}

.gallery-panel-header,
.gallery-content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.gallery-folder-list {
  display: flex;
  flex-direction: column;
  padding: 0.4rem;
}

.gallery-folder-list a {
  display: block;
  padding: 0.35rem 0.5rem 0.35rem calc(0.5rem + (var(--depth) * 0.8rem));
  border-radius: 4px;
  color: var(--pico-color);
  font-size: 0.84rem;
  text-decoration: none;
}

.gallery-folder-list a:hover,
.gallery-folder-list a.active {
  background: var(--pico-secondary-background);
  color: var(--pico-primary-inverse);
}

.gallery-content {
  min-width: 0;
  padding-bottom: 1rem;
}

.gallery-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.85rem;
}

.gallery-limit {
  color: var(--pico-muted-color);
  font-size: 0.78rem;
  white-space: nowrap;
}

.gallery-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: flex-end;
  padding: 0.75rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.gallery-toolbar button,
.gallery-toolbar select,
.gallery-toolbar input {
  margin: 0;
}

.gallery-selection-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.gallery-selection-count,
.gallery-status {
  color: var(--pico-muted-color);
  font-size: 0.82rem;
}

.gallery-status {
  min-height: 1.2rem;
  margin: 0;
  padding: 0.55rem 0.75rem 0;
}

.gallery-status-error { color: var(--pico-del-color); }

.gallery-dialog-copy {
  margin: 0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem;
}

.gallery-tile {
  position: relative;
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 6px;
  padding: 0.5rem;
  background: #f8fafc;
  color: var(--pico-color);
  text-decoration: none;
}

.gallery-tile:hover {
  border-color: var(--pico-primary);
}

.gallery-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background: #e2e8f0;
}

.gallery-thumb img,
.gallery-thumb video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-thumb video {
  background: #0f172a;
}

.gallery-video-badge {
  position: absolute;
  right: 0.4rem;
  bottom: 0.4rem;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.25rem 0.35rem;
}

.gallery-select {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 2;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  border-radius: 999px;
  accent-color: var(--pico-primary);
}

.gallery-copy-url-button {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  background: var(--pico-primary);
  color: var(--pico-color);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.16);
}

.gallery-copy-url-button:hover,
.gallery-copy-url-button.copied {
  background: rgba(255, 255, 255, 0.92);
  color: var(--pico-primary);
}

.gallery-copy-url-button svg {
  width: 0.9rem;
  height: 0.9rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.gallery-file-name {
  overflow: hidden;
  color: var(--pico-color);
  font-size: 0.8rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-tile small {
  overflow: hidden;
  color: var(--pico-muted-color);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-folder-icon,
.gallery-pdf-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: 4px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
}

.gallery-folder-icon::before {
  content: '';
  width: 60%;
  height: 46%;
  border-radius: 4px;
  background: currentColor;
  clip-path: polygon(0 18%, 38% 18%, 46% 0, 100% 0, 100% 100%, 0 100%);
  opacity: 0.85;
}

.gallery-pdf-thumb {
  background: #fee2e2;
  color: #b91c1c;
}

.cms-dialog {
  width: min(650px, calc(100vw - 2rem));
  border: none;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.cms-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.cms-dialog-form {
  display: grid;
  gap: 1rem;
  margin: 0;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 6px;
  background: #fff;
  padding: 1rem;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  min-width: 500px;
}

.cms-dialog-header,
.cms-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cms-dialog-header h3,
.cms-dialog-form label,
.cms-dialog-form input,
.cms-dialog-form button {
  margin: 0;
}

.cms-dialog-header h3 {
  font-size: 1rem;
}

.cms-dialog-form label {
  display: grid;
  gap: 0.35rem;
}

.cms-dialog-actions {
  justify-content: flex-end;
}

.dialog-close {
  width: auto;
  border: none;
  background: none;
  color: var(--pico-muted-color);
  font-size: 0.78rem;
  padding: 0;
}

.dialog-close:hover {
  color: var(--pico-color);
}

@media (max-width: 900px) {
  .gallery-shell {
    grid-template-columns: 1fr;
  }

  .gallery-folders {
    position: static;
    max-height: none;
  }
}

/* ── Home ──────────────────────────────────────────────── */
.home-welcome { padding-top: 2rem; }
.tabulator .tabulator-footer .tabulator-page{
  color: #000;
}