/* ---------- Admin shell ---------- */
body.admin-body {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  opacity: 1;
}

.admin-sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--text);
  color: var(--on-hero);
  display: flex;
  flex-direction: column;
  padding: 26px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.admin-sidebar .logo { color: var(--on-hero); font-size: 18px; margin-bottom: 4px; }
.admin-sidebar .logo span { opacity: 0.6; }
.admin-eyebrow { font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase; color: rgba(251, 243, 228, 0.55); margin-bottom: 30px; }

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(251, 243, 228, 0.35) transparent;
}
.admin-nav::-webkit-scrollbar { width: 6px; }
.admin-nav::-webkit-scrollbar-track { background: transparent; }
.admin-nav::-webkit-scrollbar-thumb { background: rgba(251, 243, 228, 0.35); border-radius: 6px; border: none; }
.admin-nav::-webkit-scrollbar-thumb:hover { background: rgba(251, 243, 228, 0.55); }
.admin-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: rgba(251, 243, 228, 0.75);
  transition: background 0.2s, color 0.2s;
}
.admin-nav a:hover { background: rgba(251, 243, 228, 0.08); color: var(--on-hero); }
.admin-nav a.active { background: rgba(251, 243, 228, 0.14); color: var(--on-hero); font-weight: 500; }
.admin-nav svg { flex-shrink: 0; width: 17px; height: 17px; }

.admin-user { border-top: 1px solid rgba(251, 243, 228, 0.15); padding-top: 16px; margin-top: 16px; }
.admin-user-email { font-size: 11.5px; color: rgba(251, 243, 228, 0.6); margin-bottom: 10px; word-break: break-all; }
.admin-logout {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(251, 243, 228, 0.3);
  color: var(--on-hero);
  padding: 9px;
  border-radius: 8px;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: all 0.2s;
}
.admin-logout:hover { background: rgba(251, 243, 228, 0.12); }

.admin-back-link {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  letter-spacing: 0.2px;
  color: rgba(251, 243, 228, 0.75);
  padding: 8px 2px;
  margin-bottom: 8px;
  transition: color 0.2s;
}
.admin-back-link:hover { color: var(--on-hero); }
.admin-back-link svg { flex-shrink: 0; width: 15px; height: 15px; }

.admin-main { flex: 1; min-width: 0; padding: 36px 44px 60px; }
.admin-topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 30px; flex-wrap: wrap; }
.admin-topbar h1 { font-weight: 400; font-size: 26px; }
.admin-topbar p { color: var(--text-muted); font-size: 13.5px; margin-top: 6px; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; margin-bottom: 36px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 22px 24px; }
.stat-card span { display: block; font-size: 11px; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.stat-card strong { font-family: var(--font-head); font-weight: 400; font-size: 30px; color: var(--text); }
.stat-card small { display: block; margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.stat-card.warn strong { color: #8a3b2b; }

/* ---------- Dashboard layout ---------- */
.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 0 24px; align-items: start; }
.dash-side { display: flex; flex-direction: column; gap: 24px; }
.dash-side .admin-panel { margin-bottom: 0; }

.best-seller-card { display: flex; align-items: center; gap: 14px; }
.best-seller-card img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--bg-alt); }
.best-seller-card strong { display: block; font-size: 14px; font-weight: 500; }
.best-seller-card span { font-size: 12px; color: var(--text-muted); }

/* ---------- Bar chart (dependency-free) ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.bar-chart .bar { width: 100%; max-width: 34px; background: var(--ink); border-radius: 4px 4px 0 0; transition: height 0.3s ease; min-height: 2px; }
.bar-chart .bar-label { font-size: 9.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#chartRange .btn-admin.active { background: var(--btn); color: #fff; border-color: var(--btn); }

@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
}
.admin-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 28px; }
.admin-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.admin-panel-head h2 { font-weight: 400; font-size: 17px; }

/* ---------- Table ---------- */
.admin-table-wrap { overflow-x: auto; }

/* Foot of the orders table. Scrolling this into view loads the next page; the
   button is the fallback for when the observer never fires. */
.orders-more {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 14px 0 4px;
}
.orders-more-status { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Site messages ----------
   Full-width cards, not table rows. The message body needs room to wrap as a
   paragraph; inside a five-column table it collapsed to one word per line. */
.messages-list { display: flex; flex-direction: column; gap: 14px; }
.message-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  background: var(--surface, #fff);
}
.message-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.message-from { display: block; font-size: 14px; font-weight: 600; }
.message-email { font-size: 12.5px; color: var(--text-muted); text-decoration: underline; }
.message-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.message-subject {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
/* pre-wrap keeps the sender's own line breaks instead of running the whole
   message into one block. */
.message-body {
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-reply { display: inline-block; }
.message-actions { display: flex; flex-wrap: wrap; gap: 10px; }
/* Answered messages recede rather than disappear, so the list still reads as
   a history when the "Todas" filter is on. */
.message-card.is-handled { opacity: 0.62; }
.message-card.is-handled .message-subject { text-decoration: line-through; }

.admin-count { font-size: 12.5px; color: var(--text-muted); }

/* Count of messages still awaiting a reply, shown against the sidebar link. */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 8px;
  padding: 0 5px;
  border-radius: 9px;
  background: #8a3b2b;
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
}
#messageFilters .btn-admin.active { background: var(--ink); color: #fff; border-color: var(--ink); }

@media (max-width: 640px) {
  .message-card { padding: 15px 16px; }
  .message-card-head { gap: 6px; }
  .message-date { white-space: normal; }
}
table.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th, .admin-table td { text-align: left; padding: 14px 24px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table th { font-size: 10.5px; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-muted); font-weight: 500; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg-alt); }
.admin-table td.wrap { white-space: normal; }
.admin-table-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--bg-alt); flex-shrink: 0; }
.admin-empty { padding: 40px 24px; text-align: center; color: var(--text-muted); font-size: 13.5px; }

/* ---------- Badges / pills ---------- */
.pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 11px; letter-spacing: 0.3px; font-weight: 500; }
.pill-active { background: rgba(74, 124, 89, 0.14); color: #3d6b4c; }
.pill-inactive { background: rgba(138, 59, 43, 0.12); color: #8a3b2b; }
.pill-low { background: rgba(138, 59, 43, 0.12); color: #8a3b2b; }
.pill-pending { background: rgba(180, 140, 60, 0.16); color: #8a6a1f; }

.status-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
}
.status-pending { color: #96661f; }
.status-confirmed { color: #2e6b8a; }
.status-shipped { color: #3d6b4c; }
.status-cancelled { color: #8a3b2b; }

/* ---------- Buttons ---------- */
.btn-admin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  border: 1px solid var(--btn);
  background: var(--btn);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-admin:hover { opacity: 0.85; }
.btn-admin-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-admin-outline:hover { border-color: var(--text); opacity: 1; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: inline-flex;
  transition: all 0.2s;
}
.btn-icon:hover { color: var(--text); background: var(--bg-alt); }
.btn-icon.danger:hover { color: #8a3b2b; }
.row-actions { display: flex; gap: 4px; }

/* ---------- Forms / modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(38, 26, 15, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 30px 32px;
}
.modal h2 { font-weight: 400; font-size: 20px; margin-bottom: 22px; }
.modal-wide { max-width: 700px; }
.form-section { font-size: 11px; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-muted); margin: 24px 0 12px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-section:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.span-2 { grid-column: 1 / -1; }
.form-field label { font-size: 11.5px; letter-spacing: 0.4px; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: none; border-color: var(--ink); }
.form-field textarea { resize: vertical; min-height: 70px; }
.form-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.form-checkbox input { width: 16px; height: 16px; }
.form-checkbox label { color: var(--text); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Order detail ---------- */
.order-detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 4px; }
.order-detail-grid div { display: flex; flex-direction: column; gap: 4px; }
.order-detail-grid span { font-size: 10.5px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-muted); }
.order-detail-grid strong { font-size: 13.5px; font-weight: 500; }

.order-pipeline { display: flex; flex-wrap: wrap; gap: 8px; }
.pipeline-step {
  flex: 1;
  min-width: 100px;
  padding: 10px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.2s;
}
.pipeline-step.done { background: var(--bg-alt); color: var(--text); border-color: var(--border); }
.pipeline-step.current { background: var(--btn); color: #fff; border-color: var(--btn); }
.pipeline-step.terminal { border-color: #8a3b2b; color: #8a3b2b; background: rgba(138, 59, 43, 0.08); }

/* ---------- Alerts ---------- */
.admin-alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 18px; }
.admin-alert-error { background: rgba(138, 59, 43, 0.1); color: #8a3b2b; }
.admin-alert-success { background: rgba(74, 124, 89, 0.12); color: #3d6b4c; }

/* ---------- Login page ---------- */
.admin-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.admin-login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px 36px;
}
.admin-login-card .logo { display: block; text-align: center; margin-bottom: 6px; color: var(--text); }
.admin-login-card .admin-eyebrow { text-align: center; color: var(--text-muted); margin-bottom: 28px; }
.admin-login-card .form-field { margin-bottom: 16px; }
.admin-login-card button[type="submit"] { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- Responsive ---------- */
.admin-mobile-toggle { display: none; }

@media (max-width: 860px) {
  body.admin-body { flex-direction: column; }

  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 100vh;
    z-index: 60;
    padding: 14px 18px;
    overflow-y: auto;
  }
  .admin-sidebar-top { display: flex; align-items: center; justify-content: space-between; }
  .admin-sidebar .logo { margin-bottom: 0; font-size: 16px; }

  .admin-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid rgba(251, 243, 228, 0.3);
    border-radius: 8px;
    color: var(--on-hero);
    cursor: pointer;
  }

  .admin-eyebrow, .admin-nav, .admin-user { display: none; }
  .admin-sidebar.open .admin-eyebrow { display: block; margin-top: 14px; }
  .admin-sidebar.open .admin-nav { display: flex; flex-direction: column; max-height: 45vh; margin-top: 6px; }
  .admin-sidebar.open .admin-user { display: block; }

  .admin-main { padding: 78px 18px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .order-detail-grid { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   Order workflow — Início action list, Pedidos list, order detail
   ========================================================================== */

/* --- status pills: one colour per step of the payment cycle --- */
.st-waiting   { background: rgba(138, 122, 90, 0.16);  color: #7a6a3f; }
.st-review    { background: rgba(200, 130, 30, 0.18);  color: #8a5a10; }
.st-paid      { background: rgba(74, 124, 89, 0.16);   color: #3d6b4c; }
.st-packing   { background: rgba(80, 110, 160, 0.16);  color: #3f5c85; }
.st-shipped   { background: rgba(100, 90, 160, 0.16);  color: #524a8a; }
.st-done      { background: rgba(74, 124, 89, 0.26);   color: #2f5a3c; }
.st-cancelled { background: rgba(138, 59, 43, 0.14);   color: #8a3b2b; }

/* --- Início: the action list comes before any figures --- */
.action-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 30px; }
.action-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface, #fff);
  transition: border-color 0.18s ease, transform 0.18s ease;
}
.action-row:hover { border-color: var(--ink); transform: translateX(2px); }
.action-row.has-work { border-left: 3px solid var(--ink); }
.action-count {
  flex: 0 0 auto;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  background: var(--bg-alt, #efe1c6);
  color: var(--text);
}
.action-count.urgent { background: #8a3b2b; color: #fff; }
.action-count.zero { background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-weight: 400; }
.action-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.action-text strong { font-size: 14.5px; font-weight: 600; }
.action-text span { font-size: 12.5px; color: var(--text-muted); }
.action-go { flex: 0 0 auto; color: var(--text-muted); font-size: 18px; }
/* Four figures that WRAP rather than being forced onto one row. Forcing
   repeat(4, 1fr) meant the fourth card — which holds a product name, not a
   number — pushed the grid wider than its panel, and .admin-panel clips its
   overflow, so the row was cut off with no way to scroll to it.
   min-width:0 is what actually lets a grid item shrink below its content. */
.stat-grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 0;
  padding: 20px 24px;
}
.stat-grid-4 .stat-card { min-width: 0; }
.stat-grid-4 .stat-card strong { display: block; overflow-wrap: anywhere; }
/* A perfume name at the 30px figure size is what overflowed in the first
   place; text values get their own scale and are allowed to wrap. */
.stat-card.stat-text strong { font-size: 17px; line-height: 1.35; }

/* --- Pedidos: filter bar and pagination --- */
.admin-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.filter-field { display: flex; flex-direction: column; gap: 5px; }
.filter-field.filter-grow { flex: 1 1 220px; }
.filter-field label { font-size: 11px; letter-spacing: 0.4px; color: var(--text-muted); }
.filter-field input, .filter-field select {
  font-family: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.filter-field input:focus, .filter-field select:focus { outline: none; border-color: var(--ink); }
.filter-actions { display: flex; gap: 8px; }
.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}
.pagination-info, .pagination-page { font-size: 12.5px; color: var(--text-muted); }
.pagination-controls { display: flex; align-items: center; gap: 10px; }
.pagination-controls button[disabled] { opacity: 0.4; cursor: not-allowed; }
.order-link { font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* --- Order detail --- */
.admin-back-inline { display: inline-block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.admin-back-inline:hover { color: var(--text); }
.order-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.order-col-main, .order-col-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* The decision bar: the two buttons this whole dashboard exists for. */
.decision-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 18px 24px;
  margin-bottom: 20px;
  border: 1px solid #d8a44a;
  border-left: 4px solid #c8821e;
  border-radius: 12px;
  background: rgba(200, 130, 30, 0.07);
}
.decision-copy { display: flex; flex-direction: column; gap: 3px; }
.decision-copy strong { font-size: 15px; }
.decision-copy span { font-size: 12.5px; color: var(--text-muted); }
.decision-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-admin-strong { background: #3d6b4c; border-color: #3d6b4c; color: #fff; }
.btn-admin-strong:hover { background: #335c40; }
.btn-admin-danger { background: transparent; border-color: #8a3b2b; color: #8a3b2b; }
.btn-admin-danger:hover { background: #8a3b2b; color: #fff; }

/* Comprovativo, shown without downloading. */
.receipt-view { padding: 20px 24px; }
.receipt-img-btn { display: block; width: 100%; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg-alt, #efe1c6); cursor: zoom-in; }
.receipt-img-btn img { display: block; width: 100%; max-height: 420px; object-fit: contain; }
.receipt-pdf { width: 100%; height: 460px; border: 1px solid var(--border); border-radius: 10px; }
.receipt-actions { margin-top: 12px; display: flex; align-items: center; gap: 12px; }
.receipt-zoom .modal { max-width: 900px; }
.receipt-zoom-img { width: 100%; height: auto; border-radius: 8px; }

/* Ordered products */
.order-items { padding: 8px 24px 0; }
.order-item { display: grid; grid-template-columns: 46px 1fr auto auto auto; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.order-item:last-child { border-bottom: none; }
.order-item-thumb { width: 46px; height: 56px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg-alt, #efe1c6); display: flex; align-items: center; justify-content: center; }
.order-item-thumb img { width: 100%; height: 100%; object-fit: contain; }
.order-item-name { min-width: 0; overflow-wrap: anywhere; }
.order-item-qty, .order-item-price { color: var(--text-muted); white-space: nowrap; }
.order-item-line { font-weight: 600; white-space: nowrap; }
.order-totals { padding: 14px 24px 20px; border-top: 1px solid var(--border); margin-top: 8px; }
.total-row { display: flex; justify-content: space-between; gap: 16px; font-size: 13.5px; padding: 5px 0; color: var(--text-muted); }
.total-row.total-final { font-size: 16px; font-weight: 600; color: var(--text); border-top: 1px solid var(--border); margin-top: 8px; padding-top: 12px; }

/* Status controls, notes, history */
.status-block { padding: 18px 24px; display: flex; flex-direction: column; gap: 12px; }
.status-block label { font-size: 11.5px; letter-spacing: 0.4px; color: var(--text-muted); }
.status-block select, .status-block textarea {
  font-family: inherit; font-size: 13.5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
.status-current { margin-bottom: 4px; }
.order-client { padding: 18px 24px; }
.order-client div { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.order-client span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); }
.order-client strong { font-weight: 500; overflow-wrap: anywhere; }
.panel-hint { padding: 0 24px; font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }
#adminNotes, .order-col-side .form-grid { margin: 0 24px 12px; width: calc(100% - 48px); }
#adminNotes { font-family: inherit; font-size: 13.5px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; resize: vertical; }
.order-col-side .btn-admin { margin: 0 24px 20px; }
.order-history { list-style: none; margin: 0; padding: 8px 24px 20px; display: flex; flex-direction: column; gap: 12px; }
.history-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; font-size: 13px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.history-row:last-child { border-bottom: none; }
.history-when { color: var(--text-muted); font-size: 12px; }
.history-what em { display: block; font-style: normal; color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }
.history-who { color: var(--text-muted); font-size: 11.5px; text-align: right; }

/* Payments get confirmed away from a desk, so the detail page has to work
   one-handed: single column, decision buttons full width. */
@media (max-width: 900px) {
  .order-layout { grid-template-columns: 1fr; }
  /* No column override for .stat-grid-4 here: auto-fit already wraps it, and a
     hard column count is exactly what overflowed the panel before. */
}
@media (max-width: 640px) {
  .decision-bar { flex-direction: column; align-items: stretch; }
  .decision-actions { flex-direction: column; }
  .decision-actions .btn-admin { width: 100%; justify-content: center; }
  .action-row { padding: 14px 16px; gap: 12px; }
  .action-count { min-width: 34px; height: 34px; font-size: 15px; }
  .admin-filters { padding: 14px 16px; }
  .filter-field, .filter-actions { flex: 1 1 100%; }
  .filter-field input, .filter-field select { width: 100%; }
  .order-item { grid-template-columns: 40px 1fr auto; row-gap: 4px; }
  .order-item-price { display: none; }
  .history-row { grid-template-columns: 1fr; gap: 3px; }
  .history-who { text-align: left; }
  .admin-pagination { padding: 12px 16px; }
  .receipt-view, .order-items, .order-totals, .status-block, .order-client, .order-history { padding-left: 16px; padding-right: 16px; }
  #adminNotes, .order-col-side .form-grid { margin-left: 16px; margin-right: 16px; width: calc(100% - 32px); }
  .order-col-side .btn-admin { margin-left: 16px; margin-right: 16px; }
}

/* .admin-panel clips its overflow (it has to, for the rounded corners over
   tables), so anything inside a panel grid has to be able to shrink. Without
   min-width:0 a grid item refuses to go narrower than its longest word and
   pushes the row out of the panel, where it is silently cut off. */
.history-what, .history-when, .history-who { min-width: 0; overflow-wrap: anywhere; }
.order-item-line, .order-item-qty { min-width: 0; }
.decision-copy { min-width: 0; }
.decision-copy strong, .decision-copy span { overflow-wrap: anywhere; }

/* ==========================================================================
   Fields must fit their container
   ==========================================================================
   Admin pages also load the storefront stylesheet, whose "font-size: 16px
   !important" on every input (the iOS focus-zoom fix) applies here too. That
   makes admin fields wider than this sheet assumes, and a flex/grid item will
   not shrink below its content without min-width:0 — so date pickers pushed
   off the screen and the two-column product form overflowed its modal, which
   could then be panned sideways. These rules make every field shrink to fit. */

.filter-field { min-width: 0; flex: 1 1 150px; }
.filter-field input,
.filter-field select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
/* Native date pickers carry an intrinsic width; this stops it winning. */
.filter-field input[type="date"] { -webkit-appearance: none; appearance: none; }

.form-field { min-width: 0; }
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* The modal scrolls vertically by design; horizontally it must not, or the
   contents can be dragged around under the finger. */
.modal { overflow-x: hidden; }
.modal .form-grid { min-width: 0; }

/* Definições: forms sit directly in the panel, so they carry the padding. */
.settings-form { padding: 20px 24px 24px; }
.settings-form .form-grid { margin-bottom: 16px; }
.field-check label { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text); letter-spacing: 0; }
.field-check input[type="checkbox"] { width: auto; min-width: 0; margin: 0; }
@media (max-width: 640px) {
  .settings-form { padding: 16px; }
  .panel-hint { padding-left: 16px; padding-right: 16px; }
}

/* De + Até behave as one control. Grouping them means the pair shares a row at
   every width instead of each date claiming a full row on a phone. */
.filter-range { display: flex; gap: 10px; min-width: 0; flex: 1 1 300px; }
.filter-range .filter-field { flex: 1 1 0; min-width: 0; }

/* Definições panels: title, one line of context, fields, then the save button
   on its own footer row — the same rhythm in every panel. */
.panel-head-stack { align-items: flex-start; }
.panel-sub { font-size: 12.5px; color: var(--text-muted); margin: 5px 0 0; line-height: 1.5; }
.modal-sub { font-size: 12.5px; color: var(--text-muted); margin: 6px 0 16px; line-height: 1.55; }
.settings-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  /* The pair keeps its own row rather than being broken apart by the
     "one field per row" rule below it. */
  .filter-range { flex: 1 1 100%; }
  .settings-actions { justify-content: stretch; }
  .settings-actions .btn-admin { width: 100%; justify-content: center; }
}

/* Settings rows: the phrase on the left, its control on the right, one per
   line. Laid out two-per-row in a grid these phrases wrapped mid-sentence and
   the controls landed in the middle of the text. */
.toggle-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0;
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row:hover { background: var(--bg-alt); }
.toggle-row span { min-width: 0; overflow-wrap: anywhere; }
/* width:auto resists the "fields fill their container" rule above. */
.toggle-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-width: 0;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

/* The width:100% above is for text fields. Checkboxes and radios must keep
   their own size — without this they stretch across the whole row, because
   ".form-field input" and ".form-checkbox input" have equal specificity and
   the later rule wins. */
.form-field input[type="checkbox"],
.form-field input[type="radio"],
.form-checkbox input {
  width: 16px;
  height: 16px;
  min-width: 0;
  flex: 0 0 auto;
  accent-color: var(--ink);
}

/* ---------- Loading skeletons ----------
   Shown while a list is in flight, so the panel has shape instead of being
   blank. Purely visual: nothing here gates the data. */
.skel-row td { padding: 14px 12px; }
.skel-bar {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(100deg, var(--bg-alt) 28%, var(--surface) 48%, var(--bg-alt) 68%);
  background-size: 300% 100%;
  animation: admin-skeleton 1.25s ease-in-out infinite;
}
.skel-bar.w-40 { width: 40%; }
.skel-bar.w-60 { width: 60%; }
.skel-bar.w-80 { width: 80%; }
@keyframes admin-skeleton {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skel-bar { animation: none; }
}

/* ---------- Sizes and prices in the product form ---------- */
.form-hint { font-size: 12px; line-height: 1.55; color: var(--text-muted); margin: 0 0 12px; }
.form-field .form-hint { margin: 5px 0 0; }
.variant-table th, .variant-table td { vertical-align: middle; }
.variant-table input { width: 100%; }
.variant-pct { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.variant-derived { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; }
/* Read-only because a database trigger owns it: it is the sum of the sizes. */
#stock[readonly] { background: var(--bg-alt, #f3efe6); color: var(--text-muted); cursor: not-allowed; }
#sizesTable input[type="text"], #sizesTable input[type="number"] { width: 100%; }
.order-item-size {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 10px; color: var(--text-muted); vertical-align: middle;
}

/* ---------- Amostra credit on the order ---------- */
#creditList { padding: 0 24px 20px; display: flex; flex-direction: column; gap: 10px; }
.credit-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
}
.credit-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px; letter-spacing: .04em; font-weight: 600;
  padding: 5px 10px; border-radius: 6px;
  background: var(--bg-alt, #f3efe6); color: var(--text);
  user-select: all;
}
.credit-meta { flex: 1 1 200px; min-width: 0; font-size: 12.5px; color: var(--text-muted); }
@media (max-width: 640px) { #creditList { padding: 0 16px 16px; } }

/* ---------- Campanhas ---------- */
.check-row { display: flex; flex-wrap: wrap; gap: 16px; }
.check-row label {
  display: flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: var(--text); letter-spacing: 0; cursor: pointer;
}
.check-row input[type="checkbox"] { width: auto; min-width: 0; margin: 0; }

/* Greyed rather than hidden when "todos os produtos" is ticked: the options
   should still be visible, just clearly not doing anything. */
.is-disabled { opacity: .4; pointer-events: none; }

.picker-list {
  max-height: 210px; overflow-y: auto; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 8px;
}
.picker-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  font-size: 13.5px; letter-spacing: 0; cursor: pointer;
}
.picker-item:last-child { border-bottom: 0; }
.picker-item input[type="checkbox"] { width: auto; min-width: 0; margin: 0; }
.picker-item span:nth-of-type(1) { flex: 1 1 auto; min-width: 0; }
.picker-meta { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.preview-box { border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.preview-head { font-size: 14px; margin-bottom: 10px; color: var(--text); }
.preview-head strong { font-size: 18px; font-family: var(--font-head); }
.preview-table { margin-top: 4px; }
.preview-table td, .preview-table th { padding: 7px 10px; font-size: 13px; }
/* The whole point of the preview: a price that would go up must be impossible
   to skim past. */
.preview-worse td { color: #8a3b2b; font-weight: 500; }

@media (max-width: 640px) {
  .picker-meta { display: none; }
  .preview-box { padding: 10px; }
}

/* ---------- Barra superior ---------- */
/* Radio buttons over one column: the three states are mutually exclusive by
   construction, so there is no way to end up with two bars. */
.topbar-modes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.topbar-mode {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; letter-spacing: 0;
  transition: border-color .18s ease, background-color .18s ease;
}
.topbar-mode input { width: auto; min-width: 0; margin: 2px 0 0; flex: 0 0 auto; }
.topbar-mode-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar-mode-body strong { font-size: 13.5px; color: var(--text); font-weight: 500; }
.topbar-mode-body span { font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.topbar-mode:has(input:checked) { border-color: var(--ink); background: var(--bg-alt, #f3efe6); }

.topbar-preview { margin: 6px 0 4px; }
.topbar-preview-empty {
  margin: 0; padding: 14px; text-align: center;
  border: 1px dashed var(--border); border-radius: 10px;
  font-size: 12.5px; color: var(--text-muted);
}
/* The real thing, at the real proportions, so what is saved is what was seen. */
.topbar-preview-bar {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  gap: 14px; flex-wrap: wrap;
  padding: 10px 44px;
  border-radius: 10px;
  background: var(--ink, #6B4226); color: #FBF3E4;
  text-align: center;
}
.topbar-preview-text, .topbar-preview-cta {
  font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; line-height: 1.4;
}
.topbar-preview-cta { text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.topbar-preview-close { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); opacity: .7; font-size: 18px; }

@media (max-width: 640px) {
  .topbar-preview-text, .topbar-preview-cta { font-size: 10.5px; letter-spacing: 1px; }
  .topbar-preview-bar { padding: 9px 36px; }
}
