:root {
  --blue-deep: #04203f;
  --blue: #0c5ca8;
  --blue-bright: #1c7fd6;
  --blue-pale: #eaf3fb;
  --gold: #d99a2b;
  --paper: #f4f6fa;
  --card: #ffffff;
  --ink: #10182b;
  --ink-soft: #59617a;
  --line: #d8e1ee;
  --danger: #b3261e;
  --danger-bg: #fbeae9;
  --ok: #1f7a44;
  --heading: #04203f;
  --thead-hover: #dcebf8;
  --row-hover: #f7fafd;
  --font-display: "Kanit", "Anuphan", sans-serif;
  --font-body: "Anuphan", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #4f9eff;
    --blue-pale: #16233a;
    --paper: #0b1220;
    --card: #131d2e;
    --ink: #eef2f8;
    --ink-soft: #9aa7bd;
    --line: #263248;
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.16);
    --heading: #eef2f8;
    --thead-hover: #1c2c44;
    --row-hover: #101a29;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --blue: #4f9eff;
  --blue-pale: #16233a;
  --paper: #0b1220;
  --card: #131d2e;
  --ink: #eef2f8;
  --ink-soft: #9aa7bd;
  --line: #263248;
  --danger: #ff6b6b;
  --danger-bg: rgba(255, 107, 107, 0.16);
  --heading: #eef2f8;
  --thead-hover: #1c2c44;
  --row-hover: #101a29;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--ghost { background: var(--card); color: var(--blue); }
.btn--ghost:hover { background: var(--blue-pale); color: var(--heading); }

.link {
  background: none;
  border: none;
  color: var(--blue);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  border-radius: 5px;
}
.link:hover { background: var(--blue-pale); }
.link--danger { color: var(--danger); }
.link--danger:hover { background: var(--danger-bg); }

.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.82rem; }
.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }
.num { text-align: right; }

/* ---------- LOGIN ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--blue-deep), var(--blue));
}
.login__card {
  background: var(--card);
  border-radius: 16px;
  padding: 2.4rem 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 30px 60px -25px rgba(4, 32, 63, 0.6);
}
.login__logo {
  display: block;
  width: 116px;
  height: auto;
  border-radius: 6px;
  margin: 0 auto 0.7rem;
}
.login__company {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  margin: 0 0 1.4rem;
}
.login__card h1 {
  font-family: var(--font-display);
  color: var(--heading);
  margin: 0 0 0.3rem;
  font-size: 1.4rem;
  text-align: center;
}
.login__sub { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 1.6rem; text-align: center; }
.login__card label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.4rem; }
.login__card input {
  width: 100%;
  font: inherit;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--blue-pale);
  margin-bottom: 1.1rem;
}
.login__card input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(12, 92, 168, 0.15); }
.login__card .btn { width: 100%; }
.login__error { color: var(--danger); font-size: 0.83rem; margin: 0.9rem 0 0; min-height: 1em; }
.login__credit {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 1.4rem 0 0;
}

.admin-footer {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 1rem 1.25rem 1.6rem;
}

/* ---------- TOPBAR ---------- */

.topbar {
  background: var(--blue-deep);
  color: #fff;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.topbar__logo {
  height: 30px;
  width: auto;
  border-radius: 4px;
  display: block;
  flex: none;
}
.topbar__titles { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.topbar__title { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.topbar__company { font-size: 0.72rem; color: rgba(255, 255, 255, 0.75); }
.topbar__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- STATS ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  padding: 1.25rem 1.25rem 0;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat__label { font-size: 0.76rem; color: var(--ink-soft); font-weight: 600; }
.stat__value { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--heading); }

/* ---------- TOOLBAR ---------- */

.toolbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1.1rem 1.25rem 0.8rem;
}
.toolbar input[type="search"] {
  flex: 1 1 260px;
  font: inherit;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.toolbar select {
  font: inherit;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  max-width: 220px;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(12, 92, 168, 0.12); }
.toolbar__count { font-size: 0.82rem; color: var(--ink-soft); margin-left: auto; }

/* ---------- TABLE ---------- */

.tablewrap {
  margin: 0 1.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  background: var(--card);
}
.grid { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.grid th, .grid td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid thead th {
  position: sticky;
  top: 0;
  background: var(--blue-pale);
  color: var(--heading);
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.grid thead th:hover { background: var(--thead-hover); }
.grid tbody tr:hover { background: var(--row-hover); }
.grid tbody tr:last-child td { border-bottom: none; }
.grid td.empty { text-align: center; color: var(--ink-soft); padding: 2rem; }

.grid__check { width: 2.2rem; text-align: center !important; cursor: default !important; }
.grid__check:hover { background: var(--blue-pale) !important; }
.grid__check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }

.pager {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  justify-content: center;
  padding: 1.1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* ---------- MODAL ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 32, 63, 0.45);
  display: grid;
  place-items: center;
  padding: 1.25rem;
  z-index: 50;
}
.modal__box {
  background: var(--card);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal__head {
  padding: 1.1rem 1.3rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__head h2 { font-family: var(--font-display); font-size: 1.05rem; margin: 0; color: var(--heading); }
.modal__close { background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--ink-soft); }
.modal__body { padding: 1.3rem; overflow-y: auto; display: grid; gap: 0.9rem; }
.fld { display: grid; gap: 0.3rem; }
.fld > span { font-weight: 600; font-size: 0.83rem; }
.fld input, .fld textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--blue-pale);
  width: 100%;
}
.fld input:focus, .fld textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(12, 92, 168, 0.13); }
.fld--tools { margin-top: -0.2rem; }
.modal__meta { font-size: 0.8rem; color: var(--ink-soft); margin: 0.3rem 0 0; }
.modal__foot {
  padding: 1rem 1.3rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.modal__foot-btns { display: flex; gap: 0.5rem; }
.modal__error { color: var(--danger); font-size: 0.82rem; margin: 0; }

/* ---------- TOAST ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--blue-deep);
  color: #fff;
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-size: 0.86rem;
  z-index: 100;
  box-shadow: 0 12px 30px -10px rgba(4, 32, 63, 0.6);
}

/* ---------- PRODUCT CATALOG ---------- */

.modal__body code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  background: var(--blue-pale);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
}
.catalog-io {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.catalog-io .btn { flex: 1 1 auto; }

.catalog-list {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  max-height: 240px;
  overflow-y: auto;
}
.catalog-group { margin-bottom: 0.7rem; }
.catalog-group:last-child { margin-bottom: 0; }
.catalog-group__name {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--heading);
  margin-bottom: 0.2rem;
}
.catalog-sub {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0.3rem 0 0.1rem 0.4rem;
}
.catalog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.25rem 0 0.25rem 0.6rem;
  font-size: 0.85rem;
  border-bottom: 1px dashed var(--line);
}
.catalog-row:last-child { border-bottom: none; }

/* ---------- RECEIPT OVERLAY ---------- */

.receipt-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0b1a2b;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3.2rem 0.6rem 1.4rem;
}
.receipt-overlay__stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  width: 100%;
  max-width: 900px;
}
.receipt-overlay__img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.receipt-overlay__pdf {
  width: 100%;
  max-width: 900px;
  height: 90vh;
  border: 0;
  background: #fff;
  border-radius: 6px;
}
.receipt-overlay__close {
  position: fixed;
  top: 0.7rem;
  right: 0.9rem;
  z-index: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(4, 32, 63, 0.8);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .toolbar__count { margin-left: 0; }
}

/* ---------- UPDATE BANNER ---------- */
/* Shown when this admin session has been open across a new deploy. */

.update-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background: var(--blue-deep);
  color: #fff;
  padding: 0.9rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  font-size: 0.85rem;
  text-align: center;
  box-shadow: 0 -10px 24px -12px rgba(4, 32, 63, 0.5);
}

.update-banner button {
  background: #fff;
  color: var(--blue-deep);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  flex: none;
}

/* ---------- THEME TOGGLE ---------- */

.theme-toggle {
  position: fixed;
  top: 0.9rem;
  right: 0.9rem;
  z-index: 600;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px -10px rgba(4, 32, 63, 0.45);
}
.theme-toggle:active { transform: scale(0.94); }

/* ---------- Homepro campaign additions ---------- */

.admin-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.2rem 0.9rem; }
.admin-footer__ver { font-weight: 400; }
.admin-footer__ver a { color: var(--blue); text-decoration: none; }
.admin-footer__ver a:hover { text-decoration: underline; }

.modal__box--wide { max-width: 860px; }
.modal__sub { margin: 0.6rem 0 0; font-size: 0.95rem; color: var(--heading); }
.fld--check { grid-template-columns: auto 1fr; align-items: center; gap: 0.5rem; }
.fld--check input { width: 18px; height: 18px; accent-color: var(--blue); }

.quota-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.quota-table th, .quota-table td { padding: 0.4rem 0.35rem; text-align: left; border-bottom: 1px solid var(--line); }
.quota-table input { width: 5.5rem; padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; }
.quota-table .qleft--out { color: var(--danger); font-weight: 700; }

.store-current {
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: var(--blue-pale);
  color: var(--ink);
  font-size: 0.88rem;
}
.catalog-io input[type="search"], .catalog-io select {
  flex: 1 1 12rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
.store-list { border: 1px solid var(--line); border-radius: 10px; max-height: 340px; overflow: auto; }
.store-list table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.store-list th, .store-list td { padding: 0.35rem 0.5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.store-list th { position: sticky; top: 0; background: var(--blue-pale); color: var(--heading); }
.store-list tr.is-active td { background: var(--blue-pale); font-weight: 700; }
.store-edit { display: grid; gap: 0.5rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 10px; }
.store-edit__btns { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ---------- roles + remaining stock ---------- */
.role-badge {
  align-self: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--blue-pale);
  color: var(--heading);
  font-size: 0.75rem;
  font-weight: 700;
}
.role-badge--viewer { background: #fff3cd; color: #6b4e00; }

.stock-panel { padding: 0 1.25rem; margin: 1rem 0 0; }
.stock-panel:empty { display: none; }
.stock-panel__title { margin: 0 0 0.5rem; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; color: var(--heading); }
.stock-panel__items { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.75rem; }
.stock-card {
  display: grid; gap: 0.15rem; padding: 0.8rem 1rem; border-radius: 14px;
  border: 2px solid var(--gold);
  background: linear-gradient(180deg, rgba(217,154,43,0.22), rgba(217,154,43,0.07));
}
.stock-card__name { font-weight: 700; font-size: 0.9rem; color: var(--heading); }
.stock-card__left { font-family: var(--font-display); font-weight: 800; font-size: 2.6rem; line-height: 1.05; color: var(--gold); }
.stock-card__sub { font-size: 0.78rem; color: var(--ink-soft); font-weight: 600; }
.stock-card--low { border-color: #e8590c; background: rgba(232,89,12,0.14); }
.stock-card--low .stock-card__left { color: #e8590c; }
.stock-card--out { border-color: var(--danger); background: var(--danger-bg); }
.stock-card--out .stock-card__left, .stock-card--out .stock-card__sub { color: var(--danger); }
