:root {
  --bg: #f3efe6;
  --bg-accent: #e7dfd0;
  --ink: #1c1915;
  --muted: #5c5348;
  --panel: #fffaf2;
  --line: #d5cbb8;
  --brand: #0f5c4c;
  --brand-dark: #0a4036;
  --danger: #9b2c2c;
  --ok: #1f6b3a;
  --shadow: 0 10px 30px rgba(28, 25, 21, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "Tahoma", "Arial", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #fff8ea 0, transparent 40%),
    linear-gradient(160deg, var(--bg), var(--bg-accent));
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(255, 250, 242, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.topbar-end {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
}

.lang-switch {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}
.lang-switch a {
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.lang-switch a.active,
.lang-switch a:hover {
  background: var(--brand);
  color: #fff;
}

.brand a {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-dark);
  text-decoration: none;
}
.brand-sub {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.nav a {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
}
.nav a.active,
.nav a:hover {
  background: var(--brand);
  color: #fff;
}

.container {
  width: min(1100px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  padding: 1rem;
  font-size: 0.85rem;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.page-head h1, .hero-panel h1, .panel h2 { margin-top: 0; }

.hero-panel {
  padding: 1.5rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0f5c4c, #1a7a65);
  color: #fff;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.hero-panel p { margin-bottom: 0; opacity: 0.92; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.stat strong {
  display: block;
  font-size: 1.75rem;
  color: var(--brand-dark);
}
.stat span { color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 1rem;
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.form label {
  display: block;
  margin-bottom: 0.85rem;
  font-weight: 600;
}
.form input,
.form select,
.filters input,
.filters select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
}
.form small, .hint { color: var(--muted); font-weight: 400; }
.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}
.checkbox input { width: auto; margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: #5c5348; }
.btn-secondary:hover { background: #3f3a33; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0; }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: right;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 700; font-size: 0.9rem; }
code {
  font-family: ui-monospace, Consolas, monospace;
  background: #efe7d8;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}
/* Avoid display:flex on the <td> itself — it breaks table row border alignment. */
.row-actions {
  white-space: nowrap;
  vertical-align: middle;
}
.row-actions a,
.row-actions .link-danger {
  display: inline-flex;
  align-items: center;
  margin-inline-end: 0.5rem;
}
.row-actions form {
  display: inline;
  margin: 0;
  margin-inline-end: 0.5rem;
  vertical-align: middle;
}
.link-danger {
  background: none;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.empty { color: var(--muted); text-align: center; }

.flash {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
}
.flash-success { background: #e5f6ea; color: var(--ok); border: 1px solid #b7dfc2; }
.flash-error { background: #fde8e8; color: var(--danger); border: 1px solid #f0bcbc; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  align-items: end;
}
.filters .form-actions { grid-column: 1 / -1; }

.readonly-id {
  background: #efe7d8;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.readonly-id code { font-size: 1.1rem; }
.readonly-id small { display: block; color: var(--muted); margin-top: 0.25rem; }

.store-card {
  max-width: 420px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.store-card-brand {
  font-weight: 800;
  color: var(--brand);
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.store-card-name { margin: 0.25rem 0; }
.store-card-id { margin: 0.5rem 0 1rem; }
.qrcode {
  display: inline-flex;
  justify-content: center;
  margin: 0 auto 1rem;
  padding: 0.75rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.qrcode-print,
.print-only {
  display: none;
}
.print-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.store-meta {
  text-align: right;
  margin: 0;
}
.store-meta > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--line);
}
.store-meta dt { color: var(--muted); }
.store-meta dd { margin: 0; font-weight: 600; }

.help {
  background: rgba(255,250,242,0.7);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.warnings { max-height: 280px; overflow: auto; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.85rem;
}
.user-chip a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}
.user-chip a:hover { text-decoration: underline; }

.phone-contact {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.phone-tel {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}
.whatsapp-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: #25d366;
  color: #fff !important;
  text-decoration: none !important;
  flex: 0 0 auto;
}
.whatsapp-link:hover {
  background: #1ebe57;
  text-decoration: none !important;
}
.whatsapp-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.nav-toggle {
  display: none;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.55rem;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  gap: 0.28rem;
}
.nav-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--brand-dark);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
body.nav-open .nav-toggle span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
body.nav-open .nav-toggle span:nth-child(2) {
  opacity: 0;
}
body.nav-open .nav-toggle span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.table-panel {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}
.checkbox-row input { width: auto !important; }

.body-auth .container-auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1rem;
}
.login-wrap {
  width: min(420px, 100%);
}
.login-form h1 {
  margin: 0 0 0.35rem;
  color: var(--brand-dark);
}
.login-form .hint {
  margin: 0 0 1rem;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar {
    padding: 0.85rem 1rem;
    gap: 0.75rem;
  }
  .nav-toggle { display: inline-flex; }
  .topbar-end {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding-top: 0.35rem;
  }
  body.nav-open .topbar-end { display: flex; }
  .nav {
    flex-direction: column;
    gap: 0.25rem;
  }
  .nav a {
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--line);
  }
  .user-chip {
    width: 100%;
    justify-content: space-between;
    border-radius: 12px;
    flex-wrap: wrap;
  }
  .lang-switch { align-self: flex-start; }

  .container {
    width: min(1100px, calc(100% - 1.25rem));
    margin: 1rem auto 2.5rem;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
  }
  .page-head .btn,
  .card-actions .btn {
    width: 100%;
  }
  .card-actions {
    flex-direction: column;
  }

  .filters {
    grid-template-columns: 1fr;
  }
  .filters .form-actions .btn {
    flex: 1 1 auto;
  }

  .btn {
    min-height: 2.75rem;
    padding: 0.7rem 1rem;
  }

  th, td {
    padding: 0.75rem 0.5rem;
    font-size: 0.92rem;
  }
  .row-actions {
    gap: 0.65rem;
  }
  .row-actions a,
  .row-actions .link-danger {
    min-height: 2rem;
    display: inline-flex;
    align-items: center;
  }

  .store-card {
    max-width: none;
    padding: 1.15rem;
    border-radius: 16px;
  }
  .store-meta > div {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    padding: 0.55rem 0;
  }
  .store-meta dd {
    width: 100%;
  }
  .qrcode {
    width: 100%;
    justify-content: center;
  }
  .qrcode canvas,
  .qrcode img {
    max-width: 100%;
    height: auto !important;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .hero-panel {
    padding: 1.15rem;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr;
  }
  .brand a { font-size: 1.3rem; }
}

/* Stacked "label -> value" cards for data tables on phones. */
@media (max-width: 767px) {
  .table-panel {
    overflow-x: visible;
    padding: 0.35rem;
  }
  .table-panel table,
  .table-panel tbody,
  .table-panel tr,
  .table-panel td {
    display: block;
    width: 100%;
  }
  .table-panel thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .table-panel tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 0.15rem 0.9rem;
    margin-bottom: 0.85rem;
    box-shadow: 0 4px 14px rgba(28, 25, 21, 0.05);
  }
  .table-panel tr:last-child { margin-bottom: 0; }
  .table-panel td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    text-align: left;
    padding: 0.6rem 0;
    border: 0;
    border-bottom: 1px solid var(--line);
  }
  .table-panel td:last-child { border-bottom: 0; }
  .table-panel td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: right;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .table-panel td:not(.row-actions) {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .table-panel td.row-actions {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding-top: 0.85rem;
    white-space: normal;
  }
  .table-panel td.row-actions a,
  .table-panel td.row-actions .link-danger,
  .table-panel td.row-actions form {
    margin-inline-end: 0;
  }
  .table-panel td.row-actions::before {
    width: 100%;
    flex-basis: 100%;
    margin-bottom: 0.15rem;
  }
  .table-panel td.empty {
    justify-content: center;
    text-align: center;
    border-bottom: 0;
  }
  .table-panel td.empty::before { display: none; }
}

/* Exact stock size for 30×50 mm label printers (portrait). */
@page {
  size: 30mm 50mm;
  margin: 0;
}

@media print {
  .topbar, .footer, .no-print, .flash, .nav-toggle { display: none !important; }
  html, body {
    background: #fff;
    margin: 0 !important;
    padding: 0 !important;
    width: 30mm;
    height: 50mm;
    overflow: hidden;
  }
  .container {
    width: 30mm;
    max-width: 30mm;
    height: 50mm;
    margin: 0;
    padding: 0;
  }
  .whatsapp-link { display: none !important; }

  .store-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.2mm;
    box-sizing: border-box;
    width: 30mm;
    max-width: 30mm;
    height: 50mm;
    margin: 0;
    padding: 1.5mm;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
    overflow: hidden;
  }
  .store-card-brand {
    order: 1;
    margin: 0;
    font-size: 7pt;
    line-height: 1.1;
    letter-spacing: 0.02em;
  }
  .qrcode-print {
    order: 2;
    display: inline-flex !important;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
  }
  .qrcode-print canvas,
  .qrcode-print img {
    width: 22mm !important;
    height: 22mm !important;
  }
  .qrcode:not(.qrcode-print) {
    display: none !important;
  }
  .store-card-id {
    order: 3;
    margin: 0;
    font-size: 6pt;
    line-height: 1.15;
  }
  .store-card-id code {
    font-size: inherit;
    word-break: break-all;
  }
  .store-card-name {
    order: 4;
    margin: 0;
    max-width: 100%;
    font-size: 7pt;
    font-weight: 600;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .store-meta { display: none !important; }
}
