.admin-body { margin: 0; font-family: 'Jost', sans-serif; background: var(--surface-alt-color, #f5efe4); color: var(--text-color, #2c1e12); }
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar { width: 240px; background: var(--primary-color, #814827); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; }
.admin-logo { font-family: 'Fraunces', serif; font-size: 1.3rem; padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.15); }
.admin-logo span { display: block; font-size: 0.8rem; opacity: 0.8; font-family: 'Jost', sans-serif; }
.admin-nav { flex: 1; display: flex; flex-direction: column; padding: 10px 0; }
.admin-nav a { color: #f3e6d8; padding: 12px 20px; text-decoration: none; display: flex; gap: 10px; align-items: center; font-size: 0.95rem; }
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,255,255,0.12); color: #fff; }
.admin-user { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.15); font-size: 0.9rem; }
.admin-link-btn { background: none; border: none; color: #f3e6d8; text-decoration: underline; cursor: pointer; padding: 6px 0; font-size: 0.85rem; }
.admin-main { margin-left: 240px; flex: 1; padding: 0; }
.admin-topbar { display: flex; justify-content: space-between; align-items: center; padding: 22px 32px; background: #fff; border-bottom: 1px solid #e6ddcf; }
.admin-topbar h1 { margin: 0; font-family: 'Fraunces', serif; font-size: 1.5rem; color: var(--primary-color, #814827); }
.admin-content { padding: 28px 32px; }
.admin-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 6px; font-weight: 500; cursor: pointer; text-decoration: none; border: none; font-size: 0.9rem; }
.admin-btn-primary { background: var(--primary-color, #814827); color: #fff; }
.admin-btn-primary:hover { background: #6c3b1f; }
.admin-btn-secondary { background: #fff; color: var(--text-color); border: 1px solid #d8cdbb; }
.admin-btn-danger { background: #c0392b; color: #fff; }
.admin-card { background: #fff; border-radius: 10px; padding: 22px; margin-bottom: 22px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
.admin-stat { background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.admin-stat .num { font-size: 1.8rem; font-weight: 700; color: var(--primary-color, #814827); font-family: 'Fraunces', serif; }
.admin-stat .label { color: #7a6a58; font-size: 0.85rem; margin-top: 4px; }
table.admin-table { width: 100%; border-collapse: collapse; background: #fff; }
table.admin-table th, table.admin-table td { padding: 12px 14px; border-bottom: 1px solid #ede4d4; text-align: left; font-size: 0.92rem; }
table.admin-table th { background: #f7f1e6; font-weight: 600; color: #5b4632; }
table.admin-table img.thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 6px; }

/* Wraps ONLY the table so a wide table scrolls inside its own card
   instead of forcing the whole page wider than the viewport. Applied
   unconditionally (not just inside a mobile media query, and not via
   the :has() selector some older mobile browsers/webviews don't
   support) so it always works no matter the screen size or browser. */
.table-responsive { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; box-sizing: border-box; }
.table-responsive table.admin-table { min-width: 640px; }
.admin-form-row { margin-bottom: 16px; }
.admin-form-row label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.9rem; }
.admin-form-row input[type=text], .admin-form-row input[type=number], .admin-form-row input[type=email],
.admin-form-row input[type=password], .admin-form-row select, .admin-form-row textarea, .admin-form-row input[type=url], .admin-form-row input[type=file] {
  width: 100%; padding: 10px 12px; border: 1px solid #d8cdbb; border-radius: 6px; font-family: inherit; font-size: 0.95rem; box-sizing: border-box;
}
.admin-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.admin-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge-pending { background: #fff3cd; color: #856404; }
.badge-confirmed { background: #d4edda; color: #155724; }
.badge-shipped { background: #cce5ff; color: #004085; }
.badge-delivered { background: #d1f2e0; color: #0f6b3f; }
.badge-cancelled { background: #f8d7da; color: #721c24; }
.badge-paid { background: #d4edda; color: #155724; }
.badge-failed { background: #f8d7da; color: #721c24; }
.badge-refunded { background: #e2e3e5; color: #383d41; }
.admin-alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 0.9rem; }
.admin-alert-success { background: #d4edda; color: #155724; }
.admin-alert-error { background: #f8d7da; color: #721c24; }
.admin-login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--surface-alt-color, #f5efe4); }
.admin-login-card { background: #fff; padding: 40px; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
.admin-login-card h1 { font-family: 'Fraunces', serif; color: var(--primary-color, #814827); margin-top: 0; text-align: center; }
.admin-image-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.admin-image-list .img-item { position: relative; }
.admin-image-list img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; }
.admin-image-list .img-item.is-main img { border-color: var(--primary-color, #814827); }
.admin-image-list form { position: absolute; top: -6px; right: -6px; }
.admin-image-list button { background: #c0392b; color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; cursor: pointer; line-height: 1; }
.admin-image-list .img-item.is-main::after { content: 'Main'; position: absolute; bottom: -2px; left: -2px; background: var(--primary-color, #814827); color: #fff; font-size: 9px; padding: 1px 5px; border-radius: 4px; }

/* Upload dropzone + client-side preview, used on product-add / product-edit / categories */
.upload-dropzone { border: 2px dashed #d8cdbb; border-radius: 8px; padding: 18px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; background: #fbf8f3; }
.upload-dropzone:hover, .upload-dropzone.is-dragover { border-color: var(--primary-color, #814827); background: #f4ece0; }
.upload-dropzone p { margin: 0; color: #7a6f5f; font-size: 0.9rem; }
.upload-dropzone input[type="file"] { display: none; }
.upload-preview { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.upload-preview img { width: 70px; height: 70px; object-fit: cover; border-radius: 6px; border: 1px solid #d8cdbb; }
.upload-preview .preview-item { position: relative; }
.upload-preview .preview-item.is-first::after { content: 'Main'; position: absolute; bottom: -2px; left: -2px; background: var(--primary-color, #814827); color: #fff; font-size: 9px; padding: 1px 5px; border-radius: 4px; }
.admin-nav-toggle { display: none; align-items: center; justify-content: center; background: none; border: none; color: var(--primary-color, #814827); cursor: pointer; width: 44px; height: 44px; padding: 0; margin-right: 4px; flex-shrink: 0; }
/* Pure-CSS hamburger icon: three bars drawn with a background + two
   pseudo-elements. Doesn't depend on any icon font/CDN loading, so it
   is always visible even when a third-party font (e.g. Font Awesome)
   fails to load over the network. */
.admin-nav-toggle-bars,
.admin-nav-toggle-bars::before,
.admin-nav-toggle-bars::after {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}
.admin-nav-toggle-bars { position: relative; }
.admin-nav-toggle-bars::before, .admin-nav-toggle-bars::after { content: ''; position: absolute; left: 0; }
.admin-nav-toggle-bars::before { top: -7px; }
.admin-nav-toggle-bars::after { top: 7px; }
.admin-sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  /* --- Sidebar becomes a slide-in drawer instead of a full-width
     block stacked above the page content. These are the properties
     that take the sidebar OUT of the desktop flex flow and give the
     content its full width back — !important on purpose, so this
     drawer behaviour can never silently lose to some other rule
     (present or future, in this file or a shared stylesheet loaded
     earlier) that happens to match with equal or higher specificity. --- */
  .admin-nav-toggle { display: inline-flex !important; align-items: center; }
  .admin-shell { display: block !important; }
  .admin-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 260px !important;
    max-width: 82vw !important;
    height: 100vh;
    transform: translateX(-100%) !important;
    transition: transform .22s ease;
    z-index: 1000;
    overflow-y: auto;
  }
  .admin-sidebar.is-open { transform: translateX(0) !important; box-shadow: 4px 0 24px rgba(0,0,0,0.18); }
  .admin-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 12, 4, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
    z-index: 999;
  }
  .admin-sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
  /* The sidebar is `position:fixed`, so it no longer takes up space in
     the (now block, not flex) .admin-shell — .admin-main is simply the
     full width of the viewport, edge to edge, on mobile. */
  .admin-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  /* --- Topbar: title truncates instead of forcing the button to wrap
     onto a second line / off the edge of the screen --- */
  .admin-topbar { display: flex; width: 100%; max-width: 100%; box-sizing: border-box; padding: 14px 16px; gap: 10px; }
  .admin-topbar h1 { font-size: 1.15rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .admin-topbar .admin-btn-secondary { padding: 8px 10px; font-size: 0.8rem; white-space: nowrap; }

  .admin-content { width: 100%; max-width: 100%; box-sizing: border-box; padding: 16px; }
  .admin-card { width: 100%; max-width: 100%; box-sizing: border-box; padding: 16px; border-radius: 8px; }

  .admin-grid-2 { grid-template-columns: 1fr; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .admin-stat { padding: 14px; }
  .admin-stat .num { font-size: 1.4rem; }

  /* --- Any inline flex row (search/filter bars, per-row admin forms)
     that didn't already opt into wrapping now wraps instead of
     overflowing the screen width --- */
  .admin-content div[style*="display:flex"],
  .admin-content form[style*="display:flex"] { flex-wrap: wrap !important; }
  .admin-content form[style*="display:flex"] input[type="text"] { flex: 1 1 140px; min-width: 0; }

  /* --- Safety net for any plain (non-.admin-form-row) input/select that
     carries a hardcoded pixel width via an inline style — e.g. the
     customers.php search box (width:300px). Rather than only patching
     that one file, every such control is capped at the width of its
     container so a fixed inline width can never push the page wider
     than the viewport, wherever it turns up. --- */
  .admin-content input[type="text"],
  .admin-content input[type="search"],
  .admin-content input[type="email"],
  .admin-content input[type="number"],
  .admin-content input[type="url"],
  .admin-content select {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* --- Locks background scroll while the mobile drawer is open (class
     is only ever toggled by the sidebar script, see footer.php) --- */
  body.admin-sidebar-open { overflow: hidden; }

  /* --- Slightly larger touch target for the small circular "remove
     image" button on the Edit Product page, without changing its look
     on desktop --- */
  .admin-image-list button { width: 26px; height: 26px; font-size: 13px; }

  .admin-login-card { padding: 26px 22px; max-width: 92vw; }
}

@media (max-width: 480px) {
  .admin-stats { grid-template-columns: 1fr 1fr; }
  .admin-topbar h1 { font-size: 1.05rem; }
  table.admin-table th, table.admin-table td { padding: 10px 12px; font-size: 0.85rem; }
}