/* Merchant area: the /auth/ login card and the /admin/ panel.
   Tokens, buttons and utilities come from base.css. */

/* Component display rules (e.g. .btn) would otherwise defeat the hidden attribute. */
[hidden] { display: none !important; }

/* ---------- Form controls (shared by login, toolbar and the product form) ---------- */

.field { display: grid; gap: 8px; }

.field__label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem; /* 16px keeps iOS from zooming on focus */
  line-height: 1.4;
  transition: border-color var(--dur-fast) ease;
}

.input::placeholder { color: var(--muted); opacity: 1; }
.input:hover { border-color: var(--border-strong); }
.input:focus-visible { border-color: var(--text); outline-offset: 2px; }
.input[aria-invalid='true'] { border-color: var(--danger); }
.input[type='search'] { appearance: none; -webkit-appearance: none; }

/* Password field with a "show password" button sitting inside its right edge. */
.input-reveal { position: relative; }
.input--reveal { padding-right: 48px; }
.input-reveal__btn {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 44px;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-fast) ease;
}
.input-reveal__btn:hover { color: var(--text); }
.input-reveal__btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.input-reveal__icon { width: 20px; height: 20px; fill: currentColor; }
.input-reveal__icon--hide { display: none; }
.input-reveal__btn[aria-pressed='true'] .input-reveal__icon--show { display: none; }
.input-reveal__btn[aria-pressed='true'] .input-reveal__icon--hide { display: block; }

.input--select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%238a8a93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}

.form-error {
  min-height: 1.5em;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--danger);
}

.btn--danger { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.btn--danger:hover { background: #f68e90; border-color: #f68e90; }

/* ---------- /auth/ ---------- */

.auth-page {
  background: radial-gradient(70% 55% at 50% 0%, rgba(255, 255, 255, 0.08), transparent 70%), var(--bg);
  background-repeat: no-repeat;
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px var(--gutter);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.auth-card__title { margin-top: 8px; font-size: clamp(1.25rem, 5.6vw, 1.75rem); }
.auth-card .rule { margin-inline: 0; } /* hr centers itself by default */
.auth-form { display: grid; gap: 20px; margin-top: 28px; }

/* The error line keeps its height (nothing jumps when it appears) but borrows
   space from the gaps around it. */
.auth-form .form-error { margin-block: -6px; }

.auth-card__back {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
  transition: color var(--dur-fast) ease;
}

.auth-card__back:hover { color: var(--text); }

/* ---------- /admin/ shell ---------- */

/* Hidden until requireAdmin() confirms an admin session, so a visitor never
   sees the panel flash before the redirect. */
.is-guarding { visibility: hidden; }

/* The panel code failed to load (e.g. the supabase-js CDN is unreachable): the
   module script's onerror drops .is-guarding, adds .boot-failed and unhides
   #boot-error. Controls that cannot work without it are hidden. */
.boot-error {
  margin-top: 24px;
  margin-bottom: 0;
  font-size: 0.9375rem;
  color: var(--danger);
}

.boot-failed .auth-form,
.boot-failed .admin-main,
.boot-failed #admin-logout { display: none; }

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.admin-topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-h);
  padding-block: 10px;
}

.admin-topbar__brand { flex: 0 0 auto; white-space: nowrap; }
.admin-topbar__brand .eyebrow { font-size: 0.6875rem; line-height: 1.2; }
.admin-topbar__title { font-size: 1.25rem; }
.admin-topbar__actions { display: flex; gap: 8px; }
.admin-topbar__actions .btn { padding-inline: 14px; white-space: nowrap; }
.admin-main { padding-block: 24px 96px; }

/* ---------- Toolbar ---------- */

.admin-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.admin-toolbar__search { grid-column: 1 / -1; }
.admin-count { margin: 20px 0 12px; min-height: 1.2em; }

.admin-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

/* ---------- Product rows (stacked on phones) ---------- */

.admin-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

.admin-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  grid-template-areas:
    'thumb info'
    'thumb price'
    'toggles toggles'
    'actions actions';
  column-gap: 12px;
  row-gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur-fast) ease, opacity var(--dur-fast) ease;
}

.admin-row:hover { border-color: var(--border-strong); }
.admin-row.is-busy { opacity: 0.5; }

.admin-row__thumb {
  grid-area: thumb;
  align-self: start;
  width: 48px;
  height: 64px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.admin-row__thumb img { width: 100%; height: 100%; object-fit: cover; }

.admin-row__placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-indent: 0.1em; /* balances the trailing letter-spacing */
}

.admin-row__info { grid-area: info; min-width: 0; }

.admin-row__name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text);
}

.admin-row__category {
  margin-top: 2px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.admin-row__price {
  grid-area: price;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.admin-row__toggles { grid-area: toggles; display: flex; flex-wrap: wrap; gap: 4px 24px; }
.admin-row__actions { grid-area: actions; display: flex; gap: 8px; }
.admin-row__actions .btn { flex: 1 1 0; }
.admin-row__delete:hover { border-color: var(--danger); color: var(--danger); }
.admin-row__share:hover { border-color: var(--text); color: var(--text); }

/* ---------- Switch (a styled native checkbox) ---------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
  margin: 0;
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform var(--dur-fast) ease, background-color var(--dur-fast) ease;
}

.switch input:checked { background: var(--text); border-color: var(--text); }
.switch input:checked::after { background: var(--bg); transform: translateX(18px); }
.switch input:disabled { cursor: progress; opacity: 0.5; }

.switch__text {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  transition: color var(--dur-fast) ease;
}

.switch:has(input:checked) .switch__text { color: var(--text); }

/* ---------- Status toast ---------- */

.admin-status {
  position: fixed;
  left: 50%;
  /* Top of the screen, just under the sticky topbar. */
  top: calc(var(--header-h) + 12px);
  z-index: 30;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 12px 20px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  text-align: center;
  opacity: 1;
  transform: translate(-50%, 0);
  transition: opacity var(--dur-base) ease, transform var(--dur-base) ease;
}

.admin-status:empty { opacity: 0; pointer-events: none; transform: translate(-50%, -8px); }
.admin-status[data-tone='ok'] { border-color: var(--success); }
.admin-status[data-tone='error'] { border-color: var(--danger); color: var(--danger); }

/* ---------- Confirm dialog ---------- */

.confirm {
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  padding: 0;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
}

.confirm[open] { animation: fade-up var(--dur-base) ease-out both; }

.confirm::backdrop {
  background: var(--scrim);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.confirm__body { display: grid; gap: 12px; padding: 24px; }
.confirm__title { font-size: 1.125rem; }
.confirm__name { font-weight: 500; overflow-wrap: anywhere; color: var(--text); }
.confirm__name:empty { display: none; }
.confirm__text { font-size: 0.875rem; color: var(--muted); }
.confirm__actions { display: flex; gap: 12px; margin-top: 12px; }
.confirm__actions .btn { flex: 1 1 0; }

/* ---------- Breakpoints ---------- */

/* The narrowest phones give the room to the buttons; the title alone is enough. */
@media (max-width: 359px) {
  .admin-topbar__brand .eyebrow { display: none; }
}

@media (min-width: 480px) {
  .auth-card { padding: 40px; }
}

/* Large phones and small tablets: two lines per product, actions on the right. */
@media (min-width: 640px) {
  .admin-row {
    grid-template-columns: 48px minmax(0, 1fr) auto auto;
    grid-template-areas:
      'thumb info price actions'
      'thumb toggles toggles actions';
    align-items: center;
    column-gap: 16px;
    padding: 12px 16px;
  }

  .admin-row__thumb { align-self: center; }
  .admin-row__price { text-align: right; }
  .admin-row .switch { min-height: 32px; }
  .admin-row__actions .btn { flex: 0 0 auto; }
}

@media (min-width: 768px) {
  .admin-toolbar { grid-template-columns: minmax(0, 1fr) 220px auto; }
  .admin-toolbar__search { grid-column: auto; }
  .admin-topbar__actions .btn { padding-inline: 20px; }
  .confirm__actions { justify-content: flex-end; }
  .confirm__actions .btn { flex: 0 0 auto; }
}

/* Desktop: one dense line per product. */
@media (min-width: 960px) {
  .admin-row {
    grid-template-columns: 48px minmax(0, 1fr) 112px 148px auto;
    grid-template-areas: 'thumb info price toggles actions';
  }

  .admin-row__toggles { flex-direction: column; flex-wrap: nowrap; gap: 0; }
  .admin-row .switch { min-height: 30px; }
}
