@import url('https://fonts.googleapis.com/css2?family=Titillium+Web:ital,wght@0,300;0,400;0,600;0,700;0,900;1,400&display=swap');

:root {
  --brand-300: #cd6c86;
  --brand-400: #b8425f;
  --brand-500: #a12e49;
  --brand-600: #86243c;
  --brand-700: #691c30;
  --brand-gradient: linear-gradient(135deg, #c1435f 0%, #7d1f35 100%);

  --bg: #f7f5f6;
  --surface: #ffffff;
  --surface-2: #fbf7f8;
  --border: #ece3e5;
  --text: #241318;
  --text-muted: #7d6b70;
  --text-faint: #a8969b;

  --success: #1e8a5f;
  --success-bg: #e7f6ef;
  --warning: #b5790f;
  --warning-bg: #fdf1dc;
  --danger: #c23b4c;
  --danger-bg: #fbe9ec;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 2px rgba(36, 19, 24, 0.06), 0 1px 1px rgba(36, 19, 24, 0.04);
  --shadow-md: 0 8px 24px -8px rgba(105, 28, 48, 0.18), 0 2px 8px rgba(36, 19, 24, 0.06);
  --shadow-lg: 0 20px 48px -12px rgba(105, 28, 48, 0.24), 0 4px 16px rgba(36, 19, 24, 0.08);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171012;
    --surface: #211619;
    --surface-2: #291a1e;
    --border: #3a262b;
    --text: #f5ecee;
    --text-muted: #b79ba1;
    --text-faint: #7d6469;
    --success-bg: rgba(30, 138, 95, 0.15);
    --warning-bg: rgba(181, 121, 15, 0.16);
    --danger-bg: rgba(194, 59, 76, 0.16);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, 0.55), 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Titillium Web', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; }
a { color: inherit; }

/* ---------- Layout helpers ---------- */
.screen { min-height: 100dvh; width: 100%; }
[hidden] { display: none !important; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- Logo ---------- */
.logo {
  display: inline-flex;
  align-items: center;
  user-select: none;
}
.logo img {
  display: block;
  width: 200px;
  height: auto;
}
.logo.logo-sm img { width: 96px; }

.page-logo-corner {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 5;
}
.page-logo-corner img { display: block; width: 96px; height: auto; }
@media (prefers-color-scheme: dark) {
  .page-logo-corner img { filter: brightness(1.15); }
}

.page-hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
  margin: 4px 0 20px;
  color: var(--text);
  max-width: 28ch;
}
@media (max-width: 640px) {
  .page-hero-title { font-size: 1.25rem; }
}

.logo-caption {
  margin: -4px 0 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.logo-caption-sm { font-size: 0.6rem; margin: -2px 0 18px; }

@media (prefers-color-scheme: dark) {
  .logo img { filter: brightness(1.15); }
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), opacity 0.15s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:not(:disabled):hover { box-shadow: var(--shadow-md); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:not(:disabled):hover { background: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:not(:disabled):hover { filter: brightness(0.97); }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 10px; border-radius: 999px; }

/* ---------- Code entry screen ---------- */
.screen-code {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(193, 67, 95, 0.10), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(125, 31, 53, 0.10), transparent 45%),
    var(--bg);
}
.code-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  text-align: center;
  animation: rise 0.5s var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.code-card .logo { margin-bottom: 22px; align-items: center; }
.code-card h1 { font-size: 1.3rem; margin: 0 0 8px; font-weight: 700; }
.code-card .subtitle { color: var(--text-muted); font-size: 0.92rem; margin: 0 0 26px; line-height: 1.5; }
.code-input-wrap { position: relative; margin-bottom: 14px; }
#input-code {
  width: 100%;
  padding: 16px 18px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
#input-code:focus { outline: none; border-color: var(--brand-400); background: var(--surface); }
.error-msg {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-top: 14px;
  font-weight: 600;
}
.shake { animation: shake 0.4s var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

/* ---------- Loading ---------- */
.screen-loading {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand-500);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Shop topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px; flex-wrap: wrap; row-gap: 10px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: stretch; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .budget-widget { flex: 1; min-width: 0; }
  .chip span:not(.dot) { white-space: nowrap; }
}
@media (max-width: 380px) {
  .chip #deadline-text { display: none; }
  .chip { padding: 9px; }
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  white-space: nowrap;
}
.chip svg { width: 14px; height: 14px; }
.link-quiet {
  font-size: 0.82rem; color: var(--text-muted); text-decoration: none;
  border-bottom: 1px dashed var(--text-faint); cursor: pointer;
}
.link-quiet:hover { color: var(--brand-500); border-color: var(--brand-500); }

.budget-widget { min-width: 190px; }
.budget-widget .budget-numbers {
  display: flex; justify-content: space-between; font-size: 0.78rem; font-weight: 700; margin-bottom: 5px;
}
.budget-widget .budget-numbers .left { color: var(--text); }
.budget-widget .budget-numbers .right { color: var(--text-muted); font-weight: 500; }
.budget-bar {
  height: 8px; border-radius: 999px; background: var(--border); overflow: hidden;
}
.budget-bar-fill {
  height: 100%; border-radius: 999px; background: var(--brand-gradient);
  transition: width 0.35s var(--ease), background 0.2s var(--ease);
}
.budget-bar-fill.near-limit { background: linear-gradient(135deg, #d99a1a, #b5790f); }
.budget-bar-fill.over { background: linear-gradient(135deg, #d94f5c, #b5303f); }

/* ---------- Locked banner ---------- */
.locked-banner {
  background: var(--warning-bg); color: var(--warning);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px; text-align: center; font-weight: 600; font-size: 0.88rem;
}

/* ---------- Shop layout ---------- */
.shop-layout {
  max-width: 1180px; margin: 0 auto; padding: 24px 20px 120px;
  display: grid; grid-template-columns: 1fr 360px; gap: 24px; align-items: start;
}
@media (max-width: 900px) {
  .shop-layout { grid-template-columns: 1fr; padding-bottom: 140px; }
}

.section-title {
  font-size: 1.05rem; font-weight: 700; margin: 4px 0 16px;
}

.products-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px;
}
.product-card {
  background: var(--surface); border-radius: var(--radius-md); overflow: hidden;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.product-media {
  aspect-ratio: 1 / 1; background: var(--surface-2); position: relative; overflow: hidden;
}
.product-media img { width: 100%; height: 100%; object-fit: cover; }
.product-media .placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
}
.qty-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--brand-gradient); color: #fff; font-weight: 800; font-size: 0.75rem;
  min-width: 22px; height: 22px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); padding: 0 5px;
}
.product-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product-name { font-weight: 700; font-size: 0.92rem; line-height: 1.3; }
.product-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; flex: 1; }
.product-price { font-weight: 800; color: var(--brand-500); font-size: 1rem; }
.product-actions { margin-top: auto; }

.stepper {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2);
}
.stepper button {
  border: none; background: transparent; cursor: pointer; width: 36px; height: 36px;
  font-size: 1.1rem; font-weight: 700; color: var(--brand-500);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s var(--ease);
}
.stepper button:hover:not(:disabled) { background: var(--border); }
.stepper button:disabled { opacity: 0.35; cursor: not-allowed; }
.stepper .qty-value { font-weight: 700; font-size: 0.92rem; min-width: 24px; text-align: center; }

.btn-add {
  width: 100%; padding: 10px; border-radius: var(--radius-sm); border: 1.5px solid var(--brand-500);
  background: transparent; color: var(--brand-500); font-weight: 700; cursor: pointer; font-size: 0.85rem;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.btn-add:hover:not(:disabled) { background: var(--brand-500); color: #fff; }
.btn-add:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Cart panel ---------- */
.cart-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 20px; position: sticky; top: 90px;
  display: flex; flex-direction: column; gap: 16px; max-height: calc(100dvh - 110px); overflow: auto;
}
.cart-items { display: flex; flex-direction: column; gap: 10px; }
.cart-empty { color: var(--text-faint); font-size: 0.85rem; text-align: center; padding: 24px 0; }
.cart-item { display: flex; align-items: center; gap: 10px; }
.cart-item .thumb {
  width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex-shrink: 0;
}
.cart-item .info { flex: 1; min-width: 0; }
.cart-item .info .name { font-size: 0.84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .info .sub { font-size: 0.76rem; color: var(--text-muted); }
.cart-item .remove {
  background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 6px;
  border-radius: 8px; transition: color 0.15s, background 0.15s;
}
.cart-item .remove:hover { color: var(--danger); background: var(--danger-bg); }

.divider { height: 1px; background: var(--border); border: none; margin: 2px 0; }

.delivery-dates { display: flex; flex-direction: column; gap: 8px; }
.delivery-option {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
  font-size: 0.86rem; font-weight: 600;
}
.delivery-option:hover { border-color: var(--brand-300); }
.delivery-option.selected { border-color: var(--brand-500); background: color-mix(in srgb, var(--brand-500) 8%, var(--surface)); }
.delivery-option input { accent-color: var(--brand-500); width: 16px; height: 16px; }

.summary-row { display: flex; justify-content: space-between; font-size: 0.88rem; }
.summary-row.total { font-weight: 800; font-size: 1.05rem; color: var(--text); }
.summary-row .muted { color: var(--text-muted); }
.remaining.negative { color: var(--danger); font-weight: 700; }

.save-status { font-size: 0.78rem; text-align: center; min-height: 16px; color: var(--text-muted); }
.save-status.ok { color: var(--success); }
.save-status.err { color: var(--danger); }

/* mobile bottom cart bar */
.mobile-cart-bar {
  display: none; position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 30;
  background: var(--brand-gradient); color: #fff; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 14px 18px; align-items: center; justify-content: space-between;
  cursor: pointer;
}
@media (max-width: 900px) {
  .mobile-cart-bar { display: flex; }
  .cart-panel { position: fixed; inset: auto 0 0 0; top: 8dvh; border-radius: 24px 24px 0 0; max-height: 92dvh; z-index: 40; transform: translateY(110%); transition: transform 0.32s var(--ease); }
  .cart-panel.open { transform: translateY(0); }
  .cart-backdrop { display: none; position: fixed; inset: 0; background: rgba(20, 10, 13, 0.4); z-index: 39; }
  .cart-backdrop.open { display: block; }
}
.mobile-cart-bar .mc-left { font-weight: 700; font-size: 0.92rem; }
.mobile-cart-bar .mc-right { font-weight: 800; }
.cart-panel-close { display: none; }
@media (max-width: 900px) {
  .cart-panel-close { display: flex; margin-left: auto; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--surface); padding: 12px 20px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 100;
  opacity: 0; pointer-events: none; transition: all 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= ADMIN ================= */
.admin-shell { display: flex; min-height: 100dvh; }
.admin-login {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(circle at 15% 20%, rgba(193, 67, 95, 0.10), transparent 45%), var(--bg);
}
.admin-sidebar {
  width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
}
.admin-sidebar .logo { padding: 0 10px 20px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.88rem; color: var(--text-muted); cursor: pointer; border: none; background: none;
  text-align: left; width: 100%; transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--brand-500) 10%, var(--surface)); color: var(--brand-500); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 999px; background: transparent; }
.nav-item.active .dot { background: var(--brand-500); }
.admin-main { flex: 1; padding: 28px 32px; max-width: 1000px; }
.admin-topline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.admin-topline h2 { margin: 0; font-size: 1.3rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); }
.field input, .field textarea, .field select {
  padding: 11px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 0.92rem;
  transition: border-color 0.15s var(--ease);
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--brand-400); }
.field textarea { resize: vertical; min-height: 70px; }
.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check input { width: 17px; height: 17px; accent-color: var(--brand-500); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 700; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-off { background: var(--surface-2); color: var(--text-faint); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.row-actions { display: flex; gap: 6px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 10, 13, 0.45); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; padding: 26px; max-height: 90dvh; overflow: auto;
  animation: rise 0.25s var(--ease);
}
.modal h3 { margin: 0 0 18px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

.upload-drop {
  border: 2px dashed var(--border); border-radius: var(--radius-md); padding: 18px;
  text-align: center; cursor: pointer; color: var(--text-muted); font-size: 0.84rem;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.upload-drop:hover { border-color: var(--brand-400); background: var(--surface-2); }
.upload-preview { width: 100%; aspect-ratio: 16/9; border-radius: var(--radius-sm); object-fit: cover; margin-bottom: 10px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-faint); }
.codes-toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.codes-toolbar input[type="text"] { flex: 1; min-width: 180px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; }
.stat-box .num { font-size: 1.4rem; font-weight: 800; color: var(--brand-500); }
.stat-box .lbl { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; margin-top: 2px; }

.demo-notice {
  background: var(--warning-bg); color: var(--warning); font-size: 0.78rem; font-weight: 600;
  padding: 10px 16px; text-align: center;
}
@media (max-width: 780px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 14px 12px; }
  .admin-sidebar .logo { display: none; }
  .admin-main { padding: 20px 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
