:root {
  --bg: #ffffff;
  --bg-app: #f4f7f8;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #0f766e;
  --primary-hover: #0d665f;
  --on-primary: #ffffff;
  --teal: #13b7a2;
  --teal-ink: #0f766e;
  --teal-soft: #e8faf7;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --ok: #0f766e;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.12);
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme='dark'] {
  --bg: #0b1116;
  --bg-app: #0f171e;
  --surface: #141e27;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #23303d;
  --line-strong: #334354;
  --primary: #0f9d8c;
  --primary-hover: #13b7a2;
  --on-primary: #06211e;
  --teal: #00b392;
  --teal-ink: #00b392;
  --teal-soft: rgba(19, 183, 162, 0.14);
  --danger: #f87171;
  --danger-bg: rgba(185, 28, 28, 0.16);
  --ok: #2dd4bf;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.45;
  overflow-x: clip;
}
[hidden] { display: none !important; }

.muted { color: var(--muted); margin: 0; }
.text-xs { font-size: 0.8rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-4 { margin-top: 1rem; }
.w-full { width: 100%; }
@media (max-width: 639px) { .w-mobile-full { width: 100%; } }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.35rem; }
.row-gap { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.align-center { align-items: center; }
.grid-2 { display: grid; gap: 0.85rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ── Login (MeperSoft ecosystem standard) ── */
.login-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.login-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
}
@media (min-width: 640px) { .login-header { padding: 1.75rem 2.5rem 0; } }

.eco-brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.eco-icon { width: 32px; height: 32px; border-radius: 8px; object-fit: contain; }
.eco-name { font-size: 0.92rem; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.eco-accent { color: var(--teal-ink); }

.theme-btn {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.theme-btn svg { width: 17px; height: 17px; }
.theme-btn .icon-sun { display: none; }
[data-theme='dark'] .theme-btn .icon-sun { display: block; }
[data-theme='dark'] .theme-btn .icon-moon { display: none; }

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem 2.5rem;
}
.login-box { width: 100%; max-width: 25rem; }

.login-emblem {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 1.75rem;
}
.emblem-img {
  width: 104px;
  height: 104px;
  border-radius: 22px;
  object-fit: contain;
  margin-bottom: 0.9rem;
}
@media (min-width: 640px) { .emblem-img { width: 118px; height: 118px; } }
.emblem-wordmark {
  font-size: 2.15rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.025em;
  color: var(--ink);
}
.emblem-bar {
  margin-top: 0.7rem;
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: var(--teal);
}

.login-heading { margin-bottom: 1.25rem; }
.login-heading h1 { margin: 0 0 0.3rem; font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
.login-heading .muted { font-size: 0.9rem; }

.req { color: var(--danger); }
.input-wrap { position: relative; display: flex; align-items: center; }
.field .input-wrap input { width: 100%; padding-left: 2.65rem; font-weight: 400; }
.field .input-wrap input#login-password { padding-right: 2.8rem; }
.input-icon {
  position: absolute;
  left: 0.8rem;
  width: 17px;
  height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.input-eye {
  position: absolute;
  right: 0.35rem;
  width: 36px;
  height: 36px;
  border: 0;
  background: none;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
}
.input-eye svg { width: 17px; height: 17px; }
.input-eye .eye-closed { display: none; }
.input-eye[aria-pressed='true'] .eye-open { display: none; }
.input-eye[aria-pressed='true'] .eye-closed { display: block; }

.alert-error {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(185, 28, 28, 0.3);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 500;
}

.btn-brand { background: var(--primary); color: var(--on-primary); }
.btn-brand:hover { background: var(--primary-hover); }
.btn-arrow { width: 17px; height: 17px; }

.login-help {
  margin-top: 1.35rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.84rem;
}
.help-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--teal-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.login-footer {
  border-top: 1px solid var(--line);
  padding: 1rem max(1.25rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
}
@media (min-width: 640px) { .login-footer { padding: 1.1rem 2.5rem; } }
.footer-link { color: var(--teal-ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

#app-view { min-height: 100dvh; background: var(--bg-app); }

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}
.topbar-brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.topbar-biz-logo { height: 32px; width: auto; max-width: 120px; border-radius: 6px; flex-shrink: 0; object-fit: contain; }
.topbar-titles { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.topbar-titles strong { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 0.45rem; flex-shrink: 0; }

/* Desktop tabs */
.tabs-desktop {
  display: none;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1rem;
  gap: 0.25rem;
}
@media (min-width: 640px) { .tabs-desktop { display: flex; } }
.tab-btn {
  min-height: 44px;
  padding: 0.5rem 0.95rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn[aria-selected='true'] { color: var(--primary); border-bottom-color: var(--teal); }

/* Mobile bottom nav */
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 0.3rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .bottom-nav { display: none; } }
.bottom-tab {
  min-height: 50px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border-radius: 10px;
  cursor: pointer;
}
.bottom-tab svg { width: 21px; height: 21px; }
.bottom-tab[aria-selected='true'] { color: var(--primary); background: var(--teal-soft); }

/* ── Main container ── */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1rem 1rem calc(5.5rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .container { padding: 1.35rem 1rem 4rem; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0; font-size: 1.15rem; }
.card h3 { margin: 0; font-size: 0.98rem; }

/* ── Catalog toolbar & chips ── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
}
@media (min-width: 640px) {
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
}
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.search-input:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.toolbar-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
@media (min-width: 640px) { .toolbar-btns { display: flex; flex-shrink: 0; } }

.chips {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.35rem;
  margin-bottom: 0.9rem;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  min-height: 38px;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed='true'] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ── Product cards ── */
.products-grid { display: grid; gap: 0.8rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .products-grid { grid-template-columns: repeat(2, 1fr); } }

.prod-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: var(--shadow-sm);
}
.prod-card.is-soldout { opacity: 0.72; }
.prod-top { display: flex; gap: 0.75rem; align-items: flex-start; }
.prod-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--line);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  color: var(--muted);
}
.prod-info { flex: 1; min-width: 0; }
.prod-title { font-weight: 600; font-size: 0.96rem; margin: 0; line-height: 1.3; }
.prod-meta { font-size: 0.8rem; color: var(--muted); margin: 0.2rem 0 0; }
.prod-prices-view { display: flex; flex-wrap: wrap; gap: 0.45rem 1.2rem; font-size: 0.92rem; }
.price-pill { display: inline-flex; align-items: baseline; gap: 0.35rem; }
.price-pill span { font-size: 0.76rem; color: var(--muted); }
.price-pill strong { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.prod-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

/* ── Forms & Buttons ── */
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.field-label { font-size: 0.86rem; font-weight: 600; display: block; margin-bottom: 0.3rem; }
.field input, .field select, .field textarea, .select-sm {
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* Prevents iOS auto-zoom on focus */
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: var(--teal);
}
.field textarea { min-height: 76px; resize: vertical; }
.select-sm { min-height: 36px; padding: 0.25rem 0.55rem; font-size: 0.85rem; max-width: 140px; }

.checkbox-row { display: inline-flex; align-items: center; gap: 0.45rem; min-height: 40px; font-size: 0.9rem; cursor: pointer; }
.checkbox-row input { width: 19px; height: 19px; accent-color: var(--primary); }

.btn {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: transform 80ms ease, background-color 120ms ease;
}
.btn:active { transform: scale(0.98); }
.btn-sm { min-height: 38px; padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--teal-soft); color: var(--teal-ink); border-color: rgba(19, 183, 162, 0.35); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  flex-shrink: 0;
}
.badge-ok { color: var(--ok); border-color: #99f6e4; background: #f0fdfa; }
.badge-warn { color: var(--danger); border-color: #fecaca; background: #fef2f2; }

/* ── Media previews ── */
.media-row { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .media-row { grid-template-columns: 1fr 1fr; } }
.media-box { display: flex; flex-direction: column; gap: 0.5rem; }
.preview-frame {
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--bg);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  padding: 0.4rem;
}
.preview-logo { height: 78px; }
.preview-hero { height: 144px; }
.preview-thumb { width: 84px; height: 84px; flex-shrink: 0; }
.preview-frame img { max-width: 100%; max-height: 100%; object-fit: cover; border-radius: 8px; }
.preview-logo img { object-fit: contain; }

.divider { border: 0; border-top: 1px solid var(--line); margin: 0.25rem 0; }
.form-footer { display: flex; justify-content: flex-end; }
.error-msg { color: var(--danger); font-size: 0.88rem; margin: 0; }

/* ── Bottom-sheet modal on mobile, centered dialog on desktop ── */
.modal {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
@media (min-width: 640px) {
  .modal {
    width: min(560px, calc(100% - 2rem));
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    max-height: 88dvh;
  }
}
.modal::backdrop { background: rgba(12, 31, 43, 0.5); backdrop-filter: blur(2px); }
.modal-form { display: flex; flex-direction: column; max-height: 92dvh; }
@media (min-width: 640px) { .modal-form { max-height: 88dvh; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.15rem calc(0.85rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(4.8rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--primary);
  color: var(--on-primary);
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(12, 63, 96, 0.25);
  max-width: calc(100vw - 2rem);
  text-align: center;
}
@media (min-width: 640px) { .toast { bottom: 1.5rem; } }
