/* =====================================================================
   3 Monkey — Admin Dashboard styles
   Reuses design tokens from css/style.css (loaded first).
   Premium red/white/cream theme, responsive app shell, accessible.
   ===================================================================== */

:root {
  --admin-side: 248px;
  --admin-topbar-h: 60px;
}

.admin-body {
  background: var(--c-cream);
  min-height: 100vh;
}

/* ----------------------------- Buttons ----------------------------- */
.btn {
  border: none;
  border-radius: var(--r-pill);
  font-weight: 700;
  padding: var(--s-3) var(--s-5);
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  transition: transform var(--t-fast), box-shadow var(--t-fast),
              background var(--t-fast), opacity var(--t-fast), color var(--t-fast);
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn--sm { padding: var(--s-2) var(--s-3); font-size: 0.82rem; }
.btn--block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }

.btn--primary { background: var(--c-primary); color: #fff; box-shadow: var(--sh-primary); }
.btn--primary:hover { background: var(--c-primary-dark); }
.btn--ghost { background: var(--c-white); color: var(--c-ink); border: 1px solid var(--c-line); }
.btn--ghost:hover { background: var(--c-cream-2); }
.btn--danger { background: var(--c-white); color: var(--c-primary); border: 1px solid var(--c-primary); }
.btn--danger:hover { background: var(--c-primary); color: #fff; }

.iconbtn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none;
  background: transparent;
  border-radius: var(--r-pill);
  color: var(--c-ink);
  transition: background var(--t-fast), transform var(--t-fast);
}
.iconbtn:hover { background: var(--c-cream-2); }
.iconbtn:active { transform: scale(0.92); }
.iconbtn svg { width: 22px; height: 22px; }

/* ----------------------------- Login ----------------------------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(120% 90% at 50% -10%, var(--c-primary) 0%, var(--c-primary-dark) 60%),
    var(--c-primary-dark);
}
.login__card {
  width: 100%;
  max-width: 400px;
  background: var(--c-white);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  padding: var(--s-8) var(--s-6);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  animation: card-in var(--t-base) both;
}
.login__logo {
  width: 72px; height: 72px;
  margin: 0 auto var(--s-2);
  object-fit: contain;
  background: var(--c-white);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md);
  padding: 4px;
}
.login__title { font-size: 1.5rem; font-weight: 800; color: var(--c-primary); }
.login__sub { color: var(--c-ink-soft); font-size: 0.9rem; margin-bottom: var(--s-2); }
.login__error {
  color: var(--c-primary);
  background: var(--c-primary-soft);
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  font-size: 0.85rem;
  font-weight: 600;
}
.login__submit { margin-top: var(--s-2); width: 100%; }
.login__back { margin-top: var(--s-2); color: var(--c-ink-soft); font-size: 0.85rem; text-decoration: none; }
.login__back:hover { color: var(--c-primary); }

/* ----------------------------- App shell ----------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--admin-topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-4);
  background: color-mix(in srgb, var(--c-white) 90%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--c-line);
}
.topbar__menu { display: none; }
.topbar__brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 800; color: var(--c-primary); }
.topbar__brand img { border-radius: var(--r-sm); }
.topbar__title { font-size: 1.05rem; }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

.shell {
  display: grid;
  grid-template-columns: var(--admin-side) 1fr;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--admin-topbar-h);
  height: calc(100vh - var(--admin-topbar-h));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--s-4) var(--s-3);
  border-right: 1px solid var(--c-line);
  background: var(--c-white);
}
.sidebar__nav { display: flex; flex-direction: column; gap: var(--s-1); }
.navitem {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-4);
  border: none;
  background: transparent;
  color: var(--c-ink-soft);
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.navitem .ic { width: 20px; height: 20px; flex: none; }
.navitem:hover { background: var(--c-cream-2); color: var(--c-ink); }
.navitem.is-active { background: var(--c-primary); color: #fff; box-shadow: var(--sh-primary); }
.sidebar__foot { padding-top: var(--s-3); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(20, 14, 12, 0.45);
}

.admin-main {
  min-width: 0;
  padding: var(--s-6) var(--s-5) var(--s-10);
  max-width: 1000px;
}

/* ----------------------------- Views ----------------------------- */
.view__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.view__title { font-size: 1.5rem; font-weight: 800; }
.view__sub { color: var(--c-ink-soft); font-size: 0.9rem; }
.view__head .btn { margin-left: auto; }

/* ----------------------------- Dashboard ----------------------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-6);
}
.stat {
  background: var(--c-white);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  padding: var(--s-5);
}
.stat__value { font-size: 2rem; font-weight: 800; color: var(--c-ink); line-height: 1; }
.stat__label { margin-top: var(--s-2); color: var(--c-ink-soft); font-size: 0.85rem; font-weight: 600; }
.stat--primary { background: var(--c-primary); border-color: var(--c-primary); }
.stat--primary .stat__value, .stat--primary .stat__label { color: #fff; }
.stat--ok .stat__value { color: #1b8a4b; }
.stat--muted .stat__value { color: var(--c-ink-soft); }

.panel-card {
  background: var(--c-white);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  margin-bottom: var(--s-5);
  overflow: hidden;
}
.panel-card__head {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-line);
}
.panel-card__head h2 { font-size: 1.05rem; font-weight: 800; }

.breakdown { padding: var(--s-4) var(--s-5); display: flex; flex-direction: column; gap: var(--s-3); }
.bd-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: var(--s-3); align-items: center; }
.bd-row__label { font-weight: 700; font-size: 0.9rem; }
.bd-row__bar { height: 10px; background: var(--c-cream-2); border-radius: var(--r-pill); overflow: hidden; }
.bd-row__bar span { display: block; height: 100%; background: var(--c-primary); border-radius: var(--r-pill); }
.bd-row__num { font-weight: 800; font-size: 0.9rem; white-space: nowrap; }
.bd-row__sub { color: var(--c-ink-soft); font-weight: 600; font-size: 0.78rem; }

/* ----------------------------- Toolbar ----------------------------- */
.toolbar {
  display: flex;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.toolbar__search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--c-white);
  border: 1px solid var(--c-line);
  border-radius: var(--r-pill);
  padding: var(--s-2) var(--s-4);
}
.toolbar__search .ic { width: 18px; height: 18px; color: var(--c-ink-soft); flex: none; }
.toolbar__input { flex: 1; min-width: 0; border: none; background: transparent; font-size: 0.95rem; color: var(--c-ink); }
.toolbar__input:focus { outline: none; }
.toolbar__select {
  border: 1px solid var(--c-line);
  background: var(--c-white);
  border-radius: var(--r-pill);
  padding: var(--s-2) var(--s-4);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--c-ink);
}

/* ----------------------------- Fields ----------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); text-align: left; }
.field__label { font-size: 0.8rem; font-weight: 700; color: var(--c-ink-soft); }
.field__input {
  width: 100%;
  border: 1px solid var(--c-line);
  background: var(--c-white);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: 0.95rem;
  color: var(--c-ink);
  font-family: inherit;
}
.field__input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }
textarea.field__input { resize: vertical; }
.field__file { padding: var(--s-2) var(--s-3); font-size: 0.85rem; }
.field-error {
  color: var(--c-primary);
  background: var(--c-primary-soft);
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  font-size: 0.85rem;
  font-weight: 600;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); padding: var(--s-5); }
.field--full { grid-column: 1 / -1; }
.field--toggle { justify-content: flex-end; }
.form-preview { align-items: flex-start; }
.form-actions { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.form-actions__spacer { flex: 1; }
.form-hint { font-size: 0.8rem; color: var(--c-ink-soft); }

/* ----------------------------- Category group + rows ----------------------------- */
.grp { margin-bottom: var(--s-6); }
.grp__head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); font-weight: 800; font-size: 1.05rem; }
.grp__count { font-size: 0.78rem; font-weight: 700; color: var(--c-ink-soft); background: var(--c-cream-2); border-radius: var(--r-pill); padding: 2px var(--s-2); }

.arow {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--s-3);
  align-items: center;
  background: var(--c-white);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  margin-bottom: var(--s-2);
}
.arow.is-passive { opacity: 0.62; }
.arow.is-passive .arow__name { text-decoration: line-through; }

.thumb {
  width: 56px; height: 56px;
  border-radius: var(--r-sm);
  object-fit: contain;
  background: var(--c-white);
  box-shadow: inset 0 0 0 1px var(--c-line);
  padding: 4px;
}
.thumb--lg { width: 96px; height: 96px; border-radius: var(--r-md); }

.arow__body { min-width: 0; }
.arow__name { font-weight: 800; color: var(--c-ink); }
.arow__meta { font-size: 0.82rem; color: var(--c-ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.arow__price { color: var(--c-primary); font-weight: 800; }
.badge { display: inline-block; font-size: 0.68rem; font-weight: 800; border-radius: var(--r-pill); padding: 1px var(--s-2); margin-left: var(--s-2); vertical-align: middle; }
.badge--passive { background: var(--c-cream-2); color: var(--c-ink-soft); }
.arow__actions { display: flex; align-items: center; gap: var(--s-2); }

/* ----------------------------- Switch ----------------------------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch__track { width: 44px; height: 26px; border-radius: var(--r-pill); background: var(--c-cream-2); border: 1px solid var(--c-line); position: relative; transition: background var(--t-fast); flex: none; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--c-white); box-shadow: var(--sh-sm); transition: transform var(--t-fast); }
.switch input:checked + .switch__track { background: var(--c-primary); border-color: var(--c-primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--c-primary-soft); }
.switch__text { font-size: 0.82rem; font-weight: 700; color: var(--c-ink-soft); }

/* ----------------------------- Modal ----------------------------- */
.modal { position: fixed; inset: 0; z-index: 120; visibility: hidden; }
.modal.is-open { visibility: visible; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(20, 14, 12, 0.5); opacity: 0; transition: opacity var(--t-base); }
.modal.is-open .modal__backdrop { opacity: 1; }
.modal__panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -48%);
  width: min(620px, calc(100% - 2 * var(--s-4)));
  max-height: 92vh;
  overflow-y: auto;
  background: var(--c-cream);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  opacity: 0;
  transition: opacity var(--t-base), transform var(--t-spring);
}
.modal.is-open .modal__panel { opacity: 1; transform: translate(-50%, -50%); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--c-line);
  position: sticky; top: 0; background: var(--c-cream); z-index: 1;
}
.modal__title { font-size: 1.2rem; font-weight: 800; }

/* ----------------------------- Toast / empty ----------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--s-5));
  transform: translateX(-50%) translateY(160%);
  z-index: 200;
  background: var(--c-ink);
  color: #fff;
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-lg);
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform var(--t-spring);
  max-width: calc(100% - 2 * var(--s-4));
}
.toast.is-visible { transform: translateX(-50%) translateY(0); }
.empty-note { text-align: center; color: var(--c-ink-soft); padding: var(--s-8) var(--s-4); }

/* ----------------------------- Responsive ----------------------------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .topbar__menu { display: grid; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 82%;
    max-width: 300px;
    height: 100vh;
    height: 100dvh;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform var(--t-base);
    box-shadow: var(--sh-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .admin-main { padding: var(--s-5) var(--s-4) var(--s-10); }
}

@media (min-width: 861px) {
  .scrim { display: none !important; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .arow { grid-template-columns: 48px 1fr; }
  .arow__actions { grid-column: 1 / -1; justify-content: flex-end; }
  .thumb { width: 48px; height: 48px; }
  .btn__label { display: inline; }
  .bd-row { grid-template-columns: 1fr auto; }
  .bd-row__bar { display: none; }
}

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