/* ==========================================================================
   NANOMAX admin panel (admin/*.php)
   Loaded after style.css, so it reuses its colour tokens, buttons and fields.
   ========================================================================== */

:root {
  --admin-bg: #F4F6FB;
  --admin-sidebar: 264px;
  --admin-radius: 16px;
  --success: #1E8A50;
  --danger: #B3243B;
}

body.admin { background: var(--admin-bg); }
.icon { flex: none; }

/* Shell ------------------------------------------------------------------ */
.admin-shell { display: grid; grid-template-columns: var(--admin-sidebar) minmax(0, 1fr); min-height: 100vh; }

.admin-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100vh;
  padding: 22px 16px;
  overflow-y: auto;
  background: var(--navy-900);
  color: var(--text-on-dark);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-decoration: none;
}
.admin-brand:hover { color: var(--accent); }
.admin-brand img { width: 38px; height: 38px; border-radius: var(--r-md); object-fit: cover; }
.admin-brand small {
  display: block;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--text-on-dark);
}

.admin-nav { display: flex; flex-direction: column; gap: 2px; }
.admin-nav__label {
  padding: 18px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(197, 211, 238, 0.55);
}
.admin-nav__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-on-dark);
  text-decoration: none;
  transition: background-color .15s, color .15s;
}
.admin-nav__item:hover { background: rgba(255, 255, 255, 0.06); color: var(--white); }
.admin-nav__item[aria-current="page"] { background: rgba(255, 255, 255, 0.1); color: var(--white); }
.admin-nav__item[aria-current="page"] .icon { color: var(--accent); }
.admin-sidebar__site { margin-top: auto; border-top: 1px solid var(--line-dark); border-radius: 0; padding-top: 18px; }

.admin-main { display: flex; flex-direction: column; min-width: 0; }
.admin-backdrop { display: none; } /* only used on small screens */

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 68px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.admin-topbar__menu { display: none; }
.admin-topbar__title { font-weight: 600; color: var(--text-muted); }

.admin-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.admin-user__avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blue-700);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
}
.admin-user__name { display: flex; flex-direction: column; font-size: 14px; font-weight: 600; line-height: 1.3; }
.admin-user__name small,
.person small,
.product-cell small { font-size: 13px; font-weight: 400; color: var(--text-muted); }

.admin-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 1320px;
  padding: 32px;
}

/* Buttons ---------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--white);
  color: var(--text-muted);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--blue-700); color: var(--blue-700); }
.icon-button--danger:hover { border-color: var(--danger); color: var(--danger); }

.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Page header ------------------------------------------------------------ */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px 24px; }
.page-head__title { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 2.4vw, 32px); letter-spacing: -0.02em; }
.page-head__lead { max-width: 720px; margin-top: 6px; color: var(--text-muted); }
.page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.page-head__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

/* Cards and grids -------------------------------------------------------- */
.card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 24px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--admin-radius);
}
.card--flush { gap: 0; padding: 0; overflow: hidden; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.card__title { font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.card__link { font-size: 14px; font-weight: 600; text-decoration: none; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 24px; align-items: start; }
.admin-grid--form { grid-template-columns: minmax(0, 440px) minmax(0, 1fr); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 16px;
  align-items: center;
  padding: 20px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--admin-radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}
a.stat-card:hover { border-color: var(--blue-700); box-shadow: 0 8px 24px rgba(15, 34, 76, 0.08); color: var(--text); }
.stat-card__icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--surface-tint);
  color: var(--blue-700);
}
.stat-card__value { font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1.1; }
.stat-card__label { font-size: 14px; color: var(--text-muted); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}

/* Tables ----------------------------------------------------------------- */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; text-align: left; }
.data-table th,
.data-table td { padding: 14px 20px; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table thead th {
  border-top: 0;
  background: #FAFBFD;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table .mono,
.data-table .badge { white-space: nowrap; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.product-cell, .person { display: flex; align-items: center; gap: 14px; color: var(--text); text-decoration: none; }
.product-cell span, .person > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.product-cell small { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table td { white-space: nowrap; }
.data-table td:first-child { white-space: normal; }
.thumb { flex: none; display: block; width: 64px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }

.badge,
.badge-button {
  display: inline-block;
  padding: 4px 10px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-button { cursor: pointer; }
.badge--success { background: #E3F4EA; color: #145A35; }
.badge--warning { background: #FFF1D6; color: #6B4A08; }
.badge--danger  { background: #FBE1E5; color: #8A1C2E; }
.badge--muted   { background: var(--surface-tint); color: var(--text-muted); }

/* Forms ------------------------------------------------------------------ */
.form-grid--tight { gap: 12px; }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix > span {
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1.5px solid var(--input-line);
  border-right: 0;
  border-radius: var(--r-md) 0 0 var(--r-md);
  background: var(--surface-tint);
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}
.input-prefix .input { flex: 1; min-width: 0; border-radius: 0 var(--r-md) var(--r-md) 0; }
.input--colour { height: 52px; padding: 6px; cursor: pointer; }

.search-box { position: relative; display: flex; align-items: center; }
.search-box .icon { position: absolute; left: 14px; color: var(--text-muted); pointer-events: none; }
.search-box .input { width: min(320px, 100%); padding: 10px 14px 10px 42px; }

.switch { display: flex; align-items: center; gap: 12px; font-weight: 500; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { position: relative; flex: none; width: 44px; height: 24px; border-radius: 999px; background: #C9D2E1; transition: background-color .15s; }
.switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform .15s;
}
.switch input:checked + .switch__track { background: var(--success); }
.switch input:checked + .switch__track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Product editor --------------------------------------------------------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.editor__main,
.editor__side { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.editor__side { position: sticky; top: 92px; }

.card__title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

/* Product images: existing photos, newly chosen ones, and the "Add images" tile */
.gallery-editor { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.gallery-editor__item {
  display: flex;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}
.gallery-editor__item img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: var(--surface-tint); transition: opacity .15s; }
.gallery-editor__item figcaption { display: flex; justify-content: space-between; gap: 6px; padding: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.gallery-editor__item:has(.pill-toggle--main input:checked) { border-color: var(--blue-700); box-shadow: 0 0 0 1px var(--blue-700); }
.gallery-editor__item:has(.pill-toggle--remove input:checked) img { opacity: 0.3; }
.gallery-editor__item--new { border-style: dashed; }
.gallery-editor__item--new figcaption { justify-content: center; color: var(--success); }
.gallery-editor__add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--surface-tint);
  font-size: 14px;
  font-weight: 600;
  color: var(--blue-700);
  cursor: pointer;
}
.gallery-editor__add:hover { border-color: var(--blue-700); }
.gallery-editor__add:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Small on/off pills built on real radio/checkbox inputs */
.pill-toggle { position: relative; cursor: pointer; }
.pill-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill-toggle span { display: inline-block; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line-strong); }
.pill-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill-toggle--main input:checked + span { background: var(--blue-700); border-color: var(--blue-700); color: var(--white); }
.pill-toggle--remove input:checked + span { background: #FBE1E5; border-color: #F1B8C1; color: #8A1C2E; }

.swatch-preview { height: 72px; border-radius: 12px; border: 1px solid var(--line); }

/* Login and setup -------------------------------------------------------- */
body.admin-auth {
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% -10%, rgba(59, 123, 255, 0.35), transparent 55%),
    var(--navy-900);
}
.admin-auth__panel { display: flex; flex-direction: column; align-items: center; gap: 24px; min-height: 100vh; padding: 48px 20px; justify-content: center; }
.admin-auth__card {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  max-width: 440px;
  padding: 36px;
  background: var(--white);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.admin-auth__head h1 { font-family: var(--font-display); font-weight: 700; font-size: 26px; }
.admin-auth__head p { margin-top: 6px; color: var(--text-muted); }
.admin-auth__note { font-size: 14px; color: var(--text-muted); text-align: center; }
.admin-auth__back { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-on-dark); text-decoration: none; }
.admin-auth__back:hover { color: var(--white); }
.admin-brand--dark { padding: 0; font-size: 22px; }

/* Small screens: the sidebar slides in from the left --------------------- */
@media (max-width: 1100px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor__side { position: static; }
  .admin-grid--form { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 960px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(var(--admin-sidebar), 85vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .admin-shell.is-open .admin-sidebar { transform: none; }
  .admin-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(10, 24, 56, 0.45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .admin-shell.is-open .admin-backdrop { opacity: 1; pointer-events: auto; }
  .admin-topbar { padding: 0 16px; }
  .admin-topbar__menu { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; color: var(--text); cursor: pointer; }
  .admin-user__name { display: none; }
  .admin-content { padding: 20px 16px 40px; }
  .data-table th, .data-table td { padding: 12px 16px; }
}
