/* =========================================================
   NSW Car Parts - Admin Panel Stylesheet
   Theme: White / Dark Gray / Red — Modern, animated, mobile-first
   ========================================================= */

:root {
  --color-white: #ffffff;
  --color-bg: #f4f5f8;
  --color-dark: #16181c;
  --color-dark-2: #24272e;
  --color-gray: #6b7280;
  --color-gray-light: #e5e7eb;
  --color-red: #e2231a;
  --color-red-dark: #b91c1c;
  --color-red-light: #ff4d42;
  --sidebar-w: 258px;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 18px rgba(20,20,30,0.06);
  --shadow-lg: 0 12px 34px rgba(20,20,30,0.12);
  --shadow-pop: 0 18px 40px rgba(226,35,26,0.18);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition: all 0.2s var(--ease);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { max-width: 100%; overflow-x: hidden; background: var(--color-bg); }
html { scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-dark);
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
ul { list-style: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Entrance animation ---------- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(226,35,26,0.35); }
  100% { box-shadow: 0 0 0 10px rgba(226,35,26,0); }
}
@keyframes float-y {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login screen ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--color-dark) 0%, var(--color-dark-2) 55%, var(--color-red-dark) 140%);
  background-size: 200% 200%;
  animation: gradient-shift 12s ease infinite;
  padding: 20px;
}
@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.login-card {
  background: #fff; border-radius: 20px; box-shadow: 0 25px 60px rgba(0,0,0,0.3);
  padding: 44px 38px; width: 100%; max-width: 380px; text-align: center;
  animation: scale-in 0.5s var(--ease-spring);
}
.login-card img { height: 50px; margin: 0 auto 20px; animation: float-y 3.5s ease-in-out infinite; }
.login-card h1 { font-size: 1.3rem; margin-bottom: 24px; }

/* ---------- Layout ---------- */
.admin-layout { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-w); background: var(--color-dark); color: #cbd0d8;
  padding: 20px 0; padding-top: calc(20px + var(--safe-t));
  position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; overflow-y: auto; flex-shrink: 0; z-index: 200;
  transition: transform 0.32s var(--ease);
  scrollbar-width: thin;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 20px 22px; }
.sidebar .brand img { height: 34px; }
.sidebar .brand span { color: #fff; font-weight: 700; font-size: 0.95rem; flex: 1; letter-spacing: 0.01em; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(10,10,14,0.5);
  backdrop-filter: blur(2px);
  z-index: 190; opacity: 0; transition: opacity 0.28s var(--ease);
}
.sidebar-backdrop.open { display: block; opacity: 1; }

.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 13px 22px;
  font-size: 0.92rem; font-weight: 500; border-left: 3px solid transparent;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), padding-left 0.2s var(--ease);
  position: relative; overflow: hidden;
}
.sidebar nav a::before {
  content: ''; position: absolute; inset: 0; background: rgba(255,255,255,0.08);
  transform: translateX(-100%); transition: transform 0.3s var(--ease);
}
.sidebar nav a:hover::before { transform: translateX(0); }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,0.06); color: #fff; border-left-color: var(--color-red); padding-left: 26px; }
.sidebar nav a.active { background: rgba(226,35,26,0.12); }
.sidebar nav .icon { width: 20px; text-align: center; position: relative; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); }

.topbar {
  background: rgba(255,255,255,0.92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: var(--shadow); padding: 14px 28px;
  padding-top: calc(14px + var(--safe-t));
  display: flex; align-items: center; justify-content: space-between;
  position: fixed; top: 0; left: var(--sidebar-w); right: 0; z-index: 100;
  transition: box-shadow 0.25s ease;
}
.topbar.scrolled { box-shadow: 0 6px 22px rgba(20,20,30,0.1); }

/* Push content below the fixed topbar */
.content {
  padding: 28px;
  padding-top: calc(70px + var(--safe-t) + 14px);
}
.topbar .mobile-toggle {
  display: none; background: none; border: none; cursor: pointer;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  padding: 0;
}

/* Modern hamburger bars */
.hamburger-icon {
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  gap: 5px; width: 22px; height: 22px;
}
.hamburger-icon .bar {
  display: block;
  height: 2px; border-radius: 2px;
  background: #1a1a2e;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1),
              opacity   0.3s cubic-bezier(0.4,0,0.2,1),
              width     0.3s cubic-bezier(0.4,0,0.2,1);
}
.hamburger-icon .bar-1 { width: 22px; }
.hamburger-icon .bar-2 { width: 16px; align-self: flex-start; }
.hamburger-icon .bar-3 { width: 22px; }

/* Animated X state when open */
.topbar .mobile-toggle.is-open .bar-1 {
  transform: translateY(7px) rotate(45deg);
}
.topbar .mobile-toggle.is-open .bar-2 {
  opacity: 0; width: 0;
}
.topbar .mobile-toggle.is-open .bar-3 {
  transform: translateY(-7px) rotate(-45deg);
}
.topbar h2 { font-size: 1.15rem; }
.admin-chip { display: flex; align-items: center; gap: 10px; }
.admin-chip .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-red), var(--color-red-dark));
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
  box-shadow: 0 3px 10px rgba(226,35,26,0.35);
}

/* Push content below the fixed topbar */
.content {
  padding: 28px;
  padding-top: calc(70px + var(--safe-t) + 14px);
  animation: fade-in 0.35s ease;
}

/* ── iOS Install Banner ─────────────────────────────────────────────────── */
.ios-install-banner {
  position: fixed; bottom: calc(16px + var(--safe-b)); left: 16px; right: 16px; z-index: 500;
  background: var(--color-dark); color: #fff; border-radius: 16px;
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  animation: toast-in 0.4s var(--ease-spring);
}
.ios-install-banner img { width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; }
.ios-install-banner .text { flex: 1; font-size: 0.82rem; line-height: 1.4; }
.ios-install-banner .text strong { display: block; font-size: 0.9rem; margin-bottom: 2px; }
.ios-install-banner .arrow { font-size: 1.4rem; }
.ios-install-banner .close-banner {
  background: rgba(255,255,255,0.15); border: none; color: #fff; border-radius: 50%;
  width: 26px; height: 26px; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ---------- Cards / stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 28px; }
.stat-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
  display: flex; align-items: center; gap: 16px;
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
  animation: fade-up 0.45s var(--ease) both;
  will-change: transform;
}
.stat-card:nth-child(1) { animation-delay: 0.02s; }
.stat-card:nth-child(2) { animation-delay: 0.08s; }
.stat-card:nth-child(3) { animation-delay: 0.14s; }
.stat-card:nth-child(4) { animation-delay: 0.20s; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.stat-card .icon {
  width: 50px; height: 50px; border-radius: 14px; background: rgba(226,35,26,0.1); color: var(--color-red);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
  transition: transform 0.3s var(--ease-spring);
}
.stat-card:hover .icon { transform: scale(1.1) rotate(-4deg); }
.stat-card .value { font-size: 1.5rem; font-weight: 700; }
.stat-card .label { font-size: 0.82rem; color: var(--color-gray); }

.panel {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px;
  animation: fade-up 0.4s var(--ease) both; animation-delay: 0.1s;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.panel-head h3 { font-size: 1.05rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 10px; border: none; font-weight: 600; font-size: 0.88rem;
  cursor: pointer; transition: transform 0.15s var(--ease), box-shadow 0.2s ease, background 0.2s ease;
  position: relative; overflow: hidden; -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn .ripple {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,0.5);
  transform: scale(0); animation: ripple-anim 0.6s ease-out; pointer-events: none;
}
@keyframes ripple-anim { to { transform: scale(2.6); opacity: 0; } }
.btn-primary { background: linear-gradient(135deg, var(--color-red-light), var(--color-red)); color: #fff; box-shadow: 0 4px 14px rgba(226,35,26,0.28); }
.btn-primary:hover { background: var(--color-red-dark); box-shadow: 0 6px 18px rgba(226,35,26,0.38); }
.btn-dark { background: var(--color-dark); color: #fff; }
.btn-dark:hover { background: var(--color-dark-2); }
.btn-outline { background: transparent; border: 1.5px solid var(--color-gray-light); color: var(--color-dark); }
.btn-outline:hover { border-color: var(--color-red); color: var(--color-red); }
.btn-sm { padding: 7px 14px; font-size: 0.8rem; line-height: 1; }
.btn-block { width: 100%; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--color-gray-light); white-space: nowrap; vertical-align: middle; }
th { background: var(--color-bg); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.04em; color: var(--color-gray); }
tr td { transition: background 0.15s ease; }
tr:hover td { background: #fafafa; }
td img.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; transition: transform 0.25s var(--ease); }
td img.thumb:hover { transform: scale(1.6); box-shadow: var(--shadow-lg); position: relative; z-index: 5; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; animation: scale-in 0.25s var(--ease); }
.badge-active, .badge-completed { background: #dcfce7; color: #166534; }
.badge-disabled, .badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-processing { background: #dbeafe; color: #1e40af; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.88rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1.5px solid var(--color-gray-light);
  outline: none; font-size: 0.9rem; font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--color-red); box-shadow: 0 0 0 4px rgba(226,35,26,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.current-image { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; margin-bottom: 10px; }

/* ---------- Alerts / toasts ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 0.88rem; animation: fade-up 0.3s var(--ease); }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

#toast-container {
  position: fixed; bottom: calc(24px + var(--safe-b)); right: 24px; left: auto; z-index: 999;
  display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--color-dark); color: #fff; padding: 13px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 0.85rem; min-width: 220px;
  animation: toast-in 0.4s var(--ease-spring);
}
.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid var(--color-red); }
@keyframes toast-in { from{opacity:0;transform:translateY(16px) scale(0.95);} to{opacity:1;transform:translateY(0) scale(1);} }

/* ---------- Pagination / breadcrumbs ---------- */
.breadcrumbs { font-size: 0.82rem; color: var(--color-gray); margin-bottom: 18px; }
.breadcrumbs a { color: var(--color-gray); transition: color 0.15s ease; }
.breadcrumbs a:hover { color: var(--color-red); }
.pagination { display: flex; gap: 6px; justify-content: flex-end; margin-top: 18px; }
.pagination a, .pagination span {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 8px;
  background: var(--color-bg); font-size: 0.82rem; font-weight: 600; transition: var(--transition);
}
.pagination a:hover { background: var(--color-gray-light); }
.pagination .active { background: var(--color-dark); color: #fff; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--color-gray); animation: fade-in 0.4s ease; }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 12px; animation: float-y 3s ease-in-out infinite; }

.actions-cell { display: flex; gap: 8px; align-items: center; white-space: nowrap; flex-wrap: nowrap; }
.actions-cell form { display: contents; }

.admins-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.order-detail-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }

/* ---------- Loading spinner (optional use) ---------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.4); border-top-color: #fff;
  animation: spin 0.7s linear infinite; display: inline-block;
}
.spinner-dark {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2.5px solid rgba(226,35,26,0.25); border-top-color: var(--color-red);
  animation: spin 0.7s linear infinite; display: inline-block; flex-shrink: 0;
}

/* ---------- AI generate button states ---------- */
#ai-generate-status { font-size: 0.82rem; color: var(--color-gray); display: inline-flex; align-items: center; gap: 6px; }
#ai-generate-btn { transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease; }
#ai-generate-btn.is-loading { opacity: 0.85; cursor: progress; }
#ai-generate-btn.is-done { background: #dcfce7; border-color: #86efac; color: #166534; }
#ai-generate-status.is-error { color: #991b1b !important; }
#ai-generate-status.is-success { color: #166534 !important; font-weight: 600; }
@keyframes ai-pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
#ai-generate-status .ai-check { display: inline-block; animation: ai-pop 0.35s var(--ease); }

/* =========================================================
   Responsive — mobile-first refinements
   ========================================================= */
@media (max-width: 960px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .admins-layout { grid-template-columns: 1fr; }
  .order-detail-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; z-index: 200;
    width: min(var(--sidebar-w), 82vw);
    box-shadow: 0 0 40px rgba(0,0,0,0.35);
    transform: translateX(-100%); transition: transform 0.36s var(--ease);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav a { padding: 15px 22px; font-size: 0.98rem; }
  .sidebar nav a:hover, .sidebar nav a.active { padding-left: 26px; }

  .topbar { padding: 12px 16px; padding-top: calc(12px + var(--safe-t)); left: 0; }
  .content { padding: 16px; padding-top: calc(64px + var(--safe-t) + 12px); padding-bottom: calc(16px + var(--safe-b)); }
  .topbar .mobile-toggle { display: flex; }
  .main { margin-left: 0; }
  .topbar h2 { font-size: 1rem; }
  .admin-chip span { display: none; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 16px; gap: 12px; border-radius: var(--radius-sm); }
  .stat-card .icon { width: 42px; height: 42px; font-size: 1.15rem; }
  .stat-card .value { font-size: 1.2rem; }

  .panel { padding: 16px; border-radius: var(--radius-sm); }

  .btn { padding: 11px 16px; font-size: 0.86rem; }
  .btn-sm { padding: 8px 12px; }

  table.stack-mobile thead { display: none; }
  table.stack-mobile, table.stack-mobile tbody, table.stack-mobile tr, table.stack-mobile td {
    display: block; width: 100%;
  }
  table.stack-mobile tr {
    background: #fff; border: 1px solid var(--color-gray-light); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 14px; padding: 6px 4px; overflow: hidden;
    animation: fade-up 0.3s var(--ease) both;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
  }
  table.stack-mobile tr:active { transform: scale(0.99); }
  table.stack-mobile tr:hover td { background: transparent; }
  table.stack-mobile td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 11px 14px; border-bottom: 1px solid #f0f1f3; white-space: normal; text-align: right;
  }
  table.stack-mobile td:last-child { border-bottom: none; }
  table.stack-mobile td::before {
    content: attr(data-label); font-weight: 700; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--color-gray); text-align: left; margin-right: auto;
  }
  table.stack-mobile td.cell-plain { justify-content: center; }
  table.stack-mobile td.cell-plain::before { content: none; }
  table.stack-mobile td.actions-cell { justify-content: flex-end; flex-wrap: wrap; }

  .login-card { padding: 32px 24px; border-radius: 18px; }

  .pagination { justify-content: center; flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}
