:root {
  --wine:      #4a1124;
  --wine-dark: #2e0a16;
  --wine-mid:  #6b1e36;
  --cream:     #faf7f2;
  --gold:      #c9a96e;
  --gold-light:#e8d5a3;
  --text:      #1a1a1a;
  --muted:     #777;
  --border:    #e5e5e5;
  --danger:    #b91c1c;
  --success:   #15803d;
  --radius:    8px;
  --font:      'Montserrat', system-ui, sans-serif;
  --shadow-sm: 0 1px 4px rgba(74,17,36,.08);
  --shadow:    0 4px 16px rgba(74,17,36,.10);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--cream);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* Toque: menos atraso em botões (mobile) */
.admin-body .btn,
.admin-body .admin-tab,
.admin-body .link-btn,
.admin-body .admin-topbar__menu {
  touch-action: manipulation;
}

/* ───────────────────────────────────────────
   LOGIN
──────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(2rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  background: linear-gradient(180deg, #fff 0%, var(--cream) 45%, #f0ebe3 100%);
}
.login-layout {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}
.login-layout--single {
  width: min(420px, 100%);
  grid-template-columns: 1fr;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem;
  border: 1px solid rgba(74,17,36,.08);
  box-shadow: 0 12px 40px rgba(74,17,36,.12);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand__logo {
  display: block;
  height: 48px;
  width: auto;
  max-width: 220px;
  margin: 0 auto 1rem;
  object-fit: contain;
}
.login-brand h1 { margin: .5rem 0 0; font-size: 1.25rem; font-weight: 700; }
.login-brand p  { margin: .35rem 0 0; font-size: .85rem; color: var(--muted); }

.login-form label { display: block; margin-bottom: 1rem; }
.login-form label span {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .35rem;
  color: var(--muted);
}
.login-form input {
  width: 100%;
  padding: .75rem .85rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: inherit;
  font-size: 16px; /* evita zoom automático no iOS */
  transition: border-color .2s;
}
.login-form .btn--primary {
  min-height: 48px;
  font-size: 0.95rem;
}
.login-form input:focus { outline: none; border-color: var(--wine); }

.login-error {
  color: var(--danger);
  font-size: .85rem;
  margin: 0 0 .75rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 12rem;
  overflow-y: auto;
}
.login-back {
  display: block;
  text-align: center;
  margin-top: 1.25rem;
  font-size: .85rem;
  color: var(--muted);
  text-decoration: none;
}
.login-back:hover { color: var(--wine); }
.analytics-card {
  width: 100%;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid rgba(74,17,36,.08);
  box-shadow: 0 12px 40px rgba(74,17,36,.08);
  padding: 1rem;
  min-height: 560px;
  display: flex;
  flex-direction: column;
}
.analytics-card[hidden] { display: none !important; }
.analytics-card__head h2 {
  margin: 0;
  font-size: 1.02rem;
  color: var(--wine-dark);
}
.analytics-card__head p {
  margin: .35rem 0 0;
  color: var(--muted);
  font-size: .85rem;
}
.analytics-card__frame {
  width: 100%;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: .85rem;
  background: #fff;
}
.analytics-card--hint {
  min-height: auto;
  justify-content: center;
}
.analytics-card__text {
  margin: .8rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

/* ───────────────────────────────────────────
   LAYOUT — sidebar + conteúdo
──────────────────────────────────────────── */
.admin-body { min-height: 100vh; margin: 0; }

.admin-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

/* Sidebar — no desktop fica no fluxo flex (sempre visível, sem depender só de margin-left) */
.admin-sidebar {
  flex: 0 0 260px;
  width: 260px;
  max-width: 260px;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--wine) 0%, var(--wine-dark) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20;
  box-shadow: 4px 0 24px rgba(0,0,0,.1);
}

.admin-sidebar__brand {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.12);
  text-align: center;
}
.admin-sidebar__logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  padding: .65rem 1rem;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.admin-sidebar__logo {
  height: auto;
  max-height: 52px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.admin-sidebar__tag {
  display: block;
  margin-top: .65rem;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  opacity: .65;
}

.admin-sidebar__nav {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  overflow-y: auto;
}

.admin-sidebar .admin-tab {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem 1rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255,255,255,.82);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.admin-sidebar .admin-tab i {
  width: 1.25rem;
  text-align: center;
  opacity: .9;
}
.admin-sidebar .admin-tab:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.admin-sidebar .admin-tab.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--gold);
}

.admin-sidebar__footer {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.admin-sidebar__user {
  margin: 0;
  font-size: .78rem;
  color: rgba(255,255,255,.75);
  line-height: 1.4;
  word-break: break-word;
}
.admin-sidebar__link-site {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .75rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.28);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s;
}
.admin-sidebar__link-site:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.admin-sidebar__logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  padding: .65rem 1rem;
  border: none;
  border-radius: 6px;
  background: #fff;
  color: var(--wine);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.admin-sidebar__logout:hover {
  background: var(--gold-light);
  color: var(--wine-dark);
}
.admin-sidebar__logout:active { transform: scale(0.98); }

/* Área principal — sem margin-left: a sidebar já ocupa 260px no flex (margin duplicada criava um vão enorme) */
.admin-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #f3f0ea;
}

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0 max(0.75rem, env(safe-area-inset-right)) 0 max(0.75rem, env(safe-area-inset-left));
  padding-top: env(safe-area-inset-top);
  min-height: calc(56px + env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(74, 17, 36, 0.04);
}
.admin-topbar__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--wine);
  letter-spacing: 0.02em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-topbar__menu {
  display: none;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--cream);
  color: var(--wine);
  font-size: 1.15rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.admin-topbar__menu:hover { background: #f0ebe3; }

/* Sair — sempre visível no canto superior direito (mobile e desktop) */
.admin-topbar__logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.85rem;
  border: 1px solid rgba(74, 17, 36, 0.35);
  border-radius: 8px;
  background: #fff;
  color: var(--wine);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 2;
}
.admin-topbar__logout:hover {
  background: rgba(74, 17, 36, 0.06);
  border-color: var(--wine);
}
.admin-topbar__logout i { font-size: 0.95rem; }

/* Conteúdo colado à sidebar: sem margin auto (que centralizava e abria espaço à esquerda em telas largas) */
.admin-main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0;
  padding: 1.5rem 1.5rem 4rem;
  box-sizing: border-box;
}
.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* Mobile: sidebar em cima do conteúdo (drawer) */
.admin-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  /* Entre o conteúdo e a sidebar aberta — precisa receber toque para fechar */
  z-index: 430;
  backdrop-filter: blur(2px);
}
.admin-sidebar-backdrop[hidden] { display: none !important; }

@media (max-width: 900px) {
  .admin-shell { position: relative; }
  /*
   * A sidebar fixa tinha z-index 300 e o conteúdo não tinha — a camada da sidebar
   * ficava por cima de toda a área principal em alguns browsers, bloqueando o botão Sair.
   * Conteúdo (400) > sidebar fechada (300); sidebar aberta (500) > backdrop (430) > conteúdo.
   */
  .admin-content {
    position: relative;
    z-index: 400;
  }
  .admin-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    width: min(300px, 88vw);
    max-width: min(300px, 88vw);
  }
  /* Fechada: não intercepta toques na área principal (topbar / Sair) */
  .admin-sidebar:not(.is-open) {
    pointer-events: none;
  }
  .admin-sidebar.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.2);
    z-index: 500;
    pointer-events: auto;
  }
  .admin-topbar__menu {
    display: flex;
  }
  .admin-sidebar .admin-tab {
    min-height: 48px;
    padding: 0.85rem 1rem;
  }
}

@media (min-width: 901px) {
  .admin-sidebar.is-open {
    transform: none;
    box-shadow: 4px 0 24px rgba(0,0,0,.1);
  }
}

/* ───────────────────────────────────────────
   DASHBOARD
──────────────────────────────────────────── */
.dashboard-welcome {
  margin-bottom: 1.75rem;
}
.dashboard-welcome h2 {
  margin: 0 0 .35rem;
  font-size: 1.5rem;
  color: var(--wine);
}
.dashboard-welcome p { margin: 0; color: var(--muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-card__icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}
.stat-card__icon--wine { background: rgba(74,17,36,.1); color: var(--wine); }
.stat-card__icon--gold { background: rgba(201,169,110,.15); color: #a0742a; }
.stat-card__icon--dark { background: rgba(0,0,0,.06); color: #333; }
.stat-card__body { flex: 1; }
.stat-card__value { display: block; font-size: 2rem; font-weight: 700; color: var(--wine); line-height: 1; }
.stat-card__label { display: block; font-size: .78rem; color: var(--muted); margin-top: .25rem; text-transform: uppercase; letter-spacing: .06em; }
.stat-card__action { align-self: flex-start; gap: .35rem; }

.dashboard-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.dashboard-charts[hidden] { display: none !important; }
.chart-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.1rem 1rem 1rem;
  box-shadow: var(--shadow-sm);
}
.chart-card h3 {
  margin: 0 0 .25rem;
  font-size: .95rem;
  font-weight: 700;
  color: var(--wine);
  display: flex;
  align-items: center;
  gap: .45rem;
}
.chart-card__hint {
  margin: 0 0 .75rem;
  font-size: .72rem;
  color: var(--muted);
  line-height: 1.35;
}
.chart-wrap {
  position: relative;
  height: 220px;
  max-width: 100%;
}
.dashboard-charts-empty {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: .88rem;
  text-align: center;
}
.dashboard-charts-empty[hidden] { display: none !important; }

.dashboard-quick h3 { margin: 0 0 .85rem; font-size: 1rem; color: var(--text); }
.dashboard-quick__btns { display: flex; gap: .75rem; flex-wrap: wrap; }
.analytics-overview {
  margin: 1.25rem 0 1.5rem;
}
.analytics-overview__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
}
.analytics-overview__head h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--wine);
}
.analytics-overview__filters {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.analytics-overview__status {
  margin: .35rem 0 .9rem;
  padding: .65rem .8rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: .85rem;
}
.analytics-overview__status--err {
  color: #991b1b;
  border-color: #fca5a5;
  background: #fff1f2;
}
.analytics-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.analytics-kpi {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .8rem .9rem;
}
.analytics-kpi__label {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.analytics-kpi__value {
  display: block;
  margin-top: .25rem;
  color: var(--wine);
  font-size: 1.35rem;
  line-height: 1.2;
}
.analytics-panels,
.analytics-tables {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.analytics-table {
  overflow-x: auto;
}
.data-table--compact th,
.data-table--compact td {
  padding: .45rem .55rem;
  font-size: .8rem;
}
.dashboard-analytics {
  margin-top: 1.25rem;
}
.dashboard-analytics .analytics-card {
  min-height: auto;
}
.dashboard-analytics .analytics-card__frame {
  min-height: 520px;
}

/* Código produto + hints no modal */
.th-code,
.td-code {
  width: 3.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--wine);
}
.form-hint--code {
  margin: 0 0 1rem;
  padding: .65rem .85rem;
  background: #f8f6f3;
  border-radius: 8px;
  font-size: .85rem;
  color: var(--text);
  border: 1px solid var(--border);
}
.form-hint--code .form-hint__sub {
  display: block;
  margin-top: .25rem;
  font-size: .72rem;
  color: var(--muted);
  font-weight: 500;
}
.form-hint--muted {
  margin: 0 0 1rem;
  padding: .6rem .85rem;
  background: rgba(74, 17, 36, 0.06);
  border-radius: 8px;
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.45;
}
.form-hint--muted strong { color: var(--wine); }

/* ───────────────────────────────────────────
   PANEL HEAD
──────────────────────────────────────────── */
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.panel-head h2 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--wine);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.panel-head__actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.panel-hint { margin: -.75rem 0 1rem; font-size: .82rem; color: var(--muted); }

/* Search */
.search-wrap { position: relative; }
.search-icon {
  position: absolute;
  left: .65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: .8rem;
  pointer-events: none;
}
.search-input {
  padding: .5rem .75rem .5rem 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: .82rem;
  width: 220px;
  transition: border-color .2s;
}
.search-input:focus { outline: none; border-color: var(--wine); }

/* ───────────────────────────────────────────
   BUTTONS
──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: none;
  border-radius: 6px;
  padding: .55rem 1.1rem;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s, color .2s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--wine); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--wine-dark); }
.btn--ghost { background: transparent; color: var(--wine); border: 1px solid rgba(74,17,36,.3); }
.btn--ghost:hover:not(:disabled) { background: rgba(74,17,36,.06); }
.btn--sm { padding: .35rem .7rem; font-size: .75rem; }
.btn--block { width: 100%; }

/* ───────────────────────────────────────────
   TABLES
──────────────────────────────────────────── */
.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
/* Mobile: tabelas genéricas — scroll horizontal (exceto .table-wrap--stack-mobile) */
@media (max-width: 900px) {
  .table-wrap:not(.table-wrap--stack-mobile) {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .table-wrap:not(.table-wrap--stack-mobile) .data-table {
    min-width: 720px;
  }
  .row-actions {
    white-space: normal;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
  }
  .row-actions .link-btn {
    margin-left: 0;
  }
}

/* Mobile: produtos/coleções — cartões empilhados, sem scroll lateral; ações logo após o nome */
@media (max-width: 900px) {
  .table-wrap--stack-mobile {
    overflow-x: visible;
  }
  .table-wrap--stack-mobile .data-table {
    min-width: 0 !important;
    width: 100%;
  }
  .table-wrap--stack-mobile thead {
    display: none;
  }
  .table-wrap--stack-mobile tbody tr {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 1rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
  }
  .table-wrap--stack-mobile tbody td {
    display: block;
    width: 100% !important;
    padding: 0.45rem 0;
    border: none;
    text-align: left !important;
    vertical-align: top;
  }
  .table-wrap--stack-mobile tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.2rem;
  }
  .table-wrap--stack-mobile tbody td.td-thumb-cell::before,
  .table-wrap--stack-mobile tbody td.td-actions-cell::before {
    display: none;
  }
  .table-wrap--stack-mobile tbody td.td-thumb-cell {
    align-self: flex-start;
  }
  .table-wrap--stack-mobile tbody td.td-name {
    padding-bottom: 0.65rem;
    margin-bottom: 0.35rem;
    border-bottom: 1px solid #f0ede8;
  }
  .table-wrap--stack-mobile .row-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    align-self: stretch;
    gap: 0.5rem;
    margin-top: 0.35rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
  }
  .table-wrap--stack-mobile .row-actions .link-btn {
    margin-left: 0;
  }
  /* Ordem: miniatura → nome → Editar/Excluir → código → demais campos */
  .table-wrap--stack-mobile #tableProducts .td-thumb-cell { order: 1; }
  .table-wrap--stack-mobile #tableProducts .td-name { order: 2; }
  .table-wrap--stack-mobile #tableProducts .td-actions-cell { order: 3; }
  .table-wrap--stack-mobile #tableProducts .td-code { order: 4; }
  .table-wrap--stack-mobile #tableProducts tbody td:nth-child(4) { order: 5; }
  .table-wrap--stack-mobile #tableProducts tbody td:nth-child(5) { order: 6; }
  .table-wrap--stack-mobile #tableProducts tbody td:nth-child(6) { order: 7; }
  .table-wrap--stack-mobile #tableProducts tbody td:nth-child(7) { order: 8; }
  .table-wrap--stack-mobile #tableWrapCollections .td-thumb-cell { order: 1; }
  .table-wrap--stack-mobile #tableWrapCollections tbody td:nth-child(2) { order: 2; }
  .table-wrap--stack-mobile #tableWrapCollections .td-actions-cell { order: 3; }
  .table-wrap--stack-mobile #tableWrapCollections tbody td:nth-child(3) { order: 4; }
  .table-wrap--stack-mobile #tableWrapCollections tbody td:nth-child(4) { order: 5; }

  .admin-sidebar__logout {
    display: none;
  }
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.data-table th,
.data-table td {
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #f0ede8;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table th {
  background: #f8f6f3;
  font-weight: 600;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.data-table tbody tr:hover { background: #fdf9f5; }
.data-table code {
  font-size: .75rem;
  background: #f0f0f0;
  padding: .15rem .4rem;
  border-radius: 4px;
}
.th-thumb { width: 56px; }
.th-actions { width: 140px; }
.td-name small { color: var(--muted); font-size: .75rem; }
.muted { color: var(--muted); }
.row-actions { white-space: nowrap; text-align: right; }
.link-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: .5rem;
  color: var(--wine);
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .4rem .5rem;
  min-height: 40px;
  border-radius: 4px;
  transition: background .15s;
}
.link-btn:hover { background: rgba(74,17,36,.07); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: #fee2e2; }

/* ───────────────────────────────────────────
   THUMBNAILS
──────────────────────────────────────────── */
.table-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  border: 1px solid var(--border);
}
.table-thumb--empty {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #f0ede8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-size: 1rem;
  border: 1px solid var(--border);
}

/* ───────────────────────────────────────────
   BADGES
──────────────────────────────────────────── */
.badge-chip {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge--new   { background: #dcfce7; color: #166534; }
.badge--feat  { background: rgba(201,169,110,.2); color: #7a5c18; }
.badge--promo { background: #fee2e2; color: #991b1b; }
.badge--excl  { background: rgba(74,17,36,.12); color: var(--wine-dark); }

/* ───────────────────────────────────────────
   ROLE CHIPS
──────────────────────────────────────────── */
.role-chip {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-chip--root  { background: rgba(74,17,36,.12); color: var(--wine); }
.role-chip--admin { background: #f0f0f0; color: #444; }
.role-chip--operador { background: #e8eef5; color: #3d4f5f; }

/* Operador: esconde ações de edição (classe .editor-only no HTML) */
.admin--operador .editor-only {
  display: none !important;
}

/* ───────────────────────────────────────────
   EMPTY STATE
──────────────────────────────────────────── */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
}
.empty-state__icon { font-size: 2.5rem; opacity: .25; margin-bottom: .75rem; display: block; }
.empty-state p { margin: 0 0 1.25rem; font-size: .95rem; }

/* ───────────────────────────────────────────
   CARD / FORM
──────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card--form h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--wine);
  display: flex;
  align-items: center;
  gap: .45rem;
}
.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: end;
}
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } }
.grid-form label { display: flex; flex-direction: column; gap: .3rem; }
.grid-form label span { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.grid-form input {
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: .85rem;
  transition: border-color .2s;
}
.grid-form input:focus { outline: none; border-color: var(--wine); }
.form-actions { grid-column: 1 / -1; }

/* ───────────────────────────────────────────
   MODAIS
──────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal--open { display: flex; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
}
.modal__box {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: var(--radius);
  padding: 0;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
}
.modal__box--wide { max-width: 820px; }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal__header h3 { margin: 0; font-size: 1.1rem; color: var(--wine); }
.modal__close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.modal__close:hover { background: #f0ede8; color: var(--wine); }

.modal__cols {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 0;
  flex: 1;
}
.modal__col { padding: 1.5rem; }
.modal__col--main { border-right: 1px solid var(--border); }
.modal__col--media { display: flex; flex-direction: column; gap: .85rem; }

@media (max-width: 680px) {
  .modal__cols { grid-template-columns: 1fr; }
  .modal__col--main { border-right: none; border-bottom: 1px solid var(--border); }
  .modal__box {
    max-height: min(92vh, 100dvh);
    margin: auto 0 0;
    border-radius: 12px 12px 0 0;
  }
  .modal__box--wide {
    width: 100%;
    max-width: 100%;
  }
  .modal {
    align-items: flex-end;
    padding: 0;
  }
  .modal__header {
    padding: 1rem 1.1rem;
  }
  .modal__col {
    padding: 1rem 1.1rem;
  }
}

.modal__box label {
  display: block;
  margin-bottom: .85rem;
}
.modal__box label span {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .3rem;
}
.modal__box input,
.modal__box textarea,
.modal__box select {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: .85rem;
  transition: border-color .2s;
  background: #fff;
}
.modal__box input:focus,
.modal__box textarea:focus,
.modal__box select:focus { outline: none; border-color: var(--wine); }
.modal__box textarea { resize: vertical; }
.select-field { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23777' d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .65rem center; background-size: 12px; padding-right: 2rem; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 560px) {
  .form-row-2 { grid-template-columns: 1fr; }
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.5rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #faf7f2;
  position: sticky;
  bottom: 0;
}
@media (max-width: 560px) {
  .modal__actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .modal__actions .btn {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }
}

/* ───────────────────────────────────────────
   FIELDSET COLEÇÕES
──────────────────────────────────────────── */
.fieldset-cols {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .75rem 1rem 1rem;
  margin: 0 0 .75rem;
}
.fieldset-cols legend {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 0 .35rem;
}
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 130px;
  overflow-y: auto;
}
@media (max-width: 680px) {
  .checkbox-list {
    max-height: min(240px, 40vh);
  }
}
.chk { display: flex; align-items: center; gap: .5rem; font-size: .85rem; cursor: pointer; }

/* ───────────────────────────────────────────
   IMAGE PREVIEW
──────────────────────────────────────────── */
.image-preview-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8f6f3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  color: #ccc;
  font-size: .78rem;
}
.image-preview-placeholder i { font-size: 2rem; }

.modal__hint {
  font-size: .78rem;
  color: var(--muted);
  margin: 0 0 .75rem;
  line-height: 1.45;
}
.product-gallery-count {
  font-size: .8rem;
  font-weight: 600;
  color: var(--wine);
  margin: 0 0 .65rem;
}
/* Galeria produto: input por cima do “botão” — Safari iOS ignora toques em input opacity:0 fora do fluxo */
.upload-row--gallery {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: stretch;
}
.product-file-picker {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 52px;
}
.product-file-picker__input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  min-height: 52px;
  opacity: 0.02;
  cursor: pointer;
  z-index: 3;
  font-size: 8rem;
  line-height: 1;
}
.product-file-picker__face {
  position: relative;
  z-index: 1;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  padding: .75rem 1rem;
  text-align: center;
}
.product-file-picker__title {
  font-weight: 600;
  font-size: .85rem;
}
.product-file-picker__sub {
  font-size: .68rem;
  color: var(--muted);
  font-weight: 500;
}
.product-gallery-editor {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-height: min(320px, 45vh);
  overflow-y: auto;
}
.product-gallery-editor__empty {
  padding: 1rem;
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.product-gallery-editor__item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.product-gallery-editor__idx {
  font-size: .65rem;
  font-weight: 700;
  color: var(--muted);
  width: 1.25rem;
  text-align: center;
}
.product-gallery-editor__item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.product-gallery-editor__actions {
  margin-left: auto;
  display: flex;
  gap: .2rem;
  flex-wrap: wrap;
}
.product-gallery-editor__actions .btn--icon {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
}
.product-gallery-editor__add {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: .75rem;
}
.product-gallery-editor__add label span {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  display: block;
  margin-bottom: .25rem;
}
.product-gallery-editor__add input[type='text'],
.product-gallery-editor__add input[type='url'] {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
}

/* ───────────────────────────────────────────
   UPLOAD
──────────────────────────────────────────── */
.upload-row { margin-bottom: 0; }
.upload-label input[type='file'] {
  font-size: .78rem;
  margin-top: .3rem;
  width: 100%;
}
.upload-status {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-top: .25rem;
  min-height: 1.2em;
}

/* ───────────────────────────────────────────
   TOAST
──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  padding: .7rem 1.35rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  max-width: min(90vw, 420px);
  text-align: center;
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity:0; transform: translateX(-50%) translateY(12px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }
@keyframes toastInMobile {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast--ok  { background: var(--wine); color: #fff; }
.toast--err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ───────────────────────────────────────────
   MISC
──────────────────────────────────────────── */
.muted { color: var(--muted); font-size: .85rem; }

@media (max-width: 768px) {
  .login-layout {
    grid-template-columns: 1fr;
  }
  .login-card {
    max-width: 100%;
    padding: 1.35rem 1rem;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(74,17,36,.10);
  }
  .analytics-card {
    min-height: auto;
    padding: .9rem;
  }
  .analytics-card__frame {
    min-height: 380px;
  }
  .grid-form input,
  .grid-form select,
  .modal__box input,
  .modal__box textarea,
  .modal__box select {
    font-size: 16px;
  }
  .modal__close {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
  .admin-main {
    padding: 1rem max(0.75rem, env(safe-area-inset-left)) max(2.5rem, env(safe-area-inset-bottom))
      max(0.75rem, env(safe-area-inset-right));
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .search-input {
    width: 100%;
    max-width: none;
    flex: 1;
    min-width: 0;
    font-size: 16px;
    padding: 0.55rem 0.75rem 0.55rem 2rem;
  }
  .panel-head { flex-direction: column; align-items: stretch; gap: 0.85rem; }
  .panel-head__actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .panel-head__actions .btn {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }
  .search-wrap {
    width: 100%;
  }
  .chart-wrap {
    height: 200px;
  }
  .dashboard-charts {
    grid-template-columns: 1fr;
  }
  .dashboard-quick__btns {
    flex-direction: column;
  }
  .dashboard-quick__btns .btn {
    width: 100%;
    min-height: 48px;
    justify-content: center;
  }
  .analytics-overview__head {
    flex-direction: column;
    align-items: flex-start;
  }
  .analytics-overview__filters {
    width: 100%;
  }
  .analytics-overview__filters .btn {
    flex: 1;
    min-width: 88px;
  }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .admin-sidebar .admin-tab { padding: .75rem 1rem; font-size: .82rem; }
  .modal__box { max-height: min(95vh, 100dvh); }
  .stat-card__value { font-size: 1.65rem; }
  .toast {
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    transform: none;
    max-width: none;
    width: auto;
    bottom: max(1rem, env(safe-area-inset-bottom));
    animation-name: toastInMobile;
  }
}
