/* =========================================================
   SorryShop UI Foundation V2
   Shared design tokens + accessible primitives
   ========================================================= */
:root {
  /* Canonical light theme: one palette for storefront, modal, and admin. */
  --canvas: #f5f5f7;
  --canvas-rgb: 245, 245, 247;
  --surface-1: #ffffff;
  --surface-1-rgb: 255, 255, 255;
  --surface-2: #fafafc;
  --surface-2-rgb: 250, 250, 252;
  --surface-3: #f2f2f4;
  --surface-3-rgb: 242, 242, 244;
  --border: #d2d2d7;
  --border-rgb: 210, 210, 215;
  --border-soft: #e5e5ea;
  --border-soft-rgb: 229, 229, 234;
  --text-primary: #1d1d1f;
  --text-primary-rgb: 29, 29, 31;
  --text-secondary: #424245;
  --text-secondary-rgb: 66, 66, 69;
  --text-muted: #6e6e73;
  --text-muted-rgb: 110, 110, 115;
  --action-500: #0071e3;
  --action-500-rgb: 0, 113, 227;
  --success-500: #148a55;
  --success-500-rgb: 20, 138, 85;
  --warning-500: #a16207;
  --warning-500-rgb: 161, 98, 7;
  --danger-500: #c9343d;
  --danger-500-rgb: 201, 52, 61;
  --wallet-500: #f97316;
  --wallet-500-rgb: 249, 115, 22;

  /* Legacy names kept as aliases so every existing page inherits the same theme. */
  --ink-950: var(--canvas);
  --ink-950-rgb: var(--canvas-rgb);
  --ink-900: var(--surface-2);
  --ink-900-rgb: var(--surface-2-rgb);
  --surface-800: var(--surface-1);
  --surface-800-rgb: var(--surface-1-rgb);
  --surface-700: var(--surface-3);
  --surface-700-rgb: var(--surface-3-rgb);
  --line-600: var(--border);
  --line-600-rgb: var(--border-rgb);
  --text-100: var(--text-primary);
  --text-100-rgb: var(--text-primary-rgb);
  --text-300: var(--text-secondary);
  --text-300-rgb: var(--text-secondary-rgb);
  --text-500: var(--text-muted);
  --text-500-rgb: var(--text-muted-rgb);

  --bg: var(--canvas);
  --bg-soft: var(--surface-2);
  --panel: var(--surface-1);
  --panel-2: var(--surface-3);
  --panel-3: var(--surface-2);
  --line: var(--border);
  --line-soft: rgba(var(--border-rgb), .58);
  --text: var(--text-primary);
  --muted: var(--text-muted);
  --blue: var(--action-500);
  --violet: var(--action-500);
  --cyan: var(--action-500);
  --green: var(--success-500);
  --red: var(--danger-500);
  --orange: var(--warning-500);

  --font-ui: "Prompt", "Leelawadee UI", "Segoe UI", Tahoma, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --shadow-soft: 0 10px 30px rgba(var(--text-primary-rgb), .05);
  --shadow-float: 0 18px 48px rgba(var(--text-primary-rgb), .08);
  --shadow-overlay: 0 28px 70px rgba(var(--text-primary-rgb), .14);
  --overlay: rgba(var(--text-primary-rgb), .32);
  --header-h: 68px;
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  min-height: 100vh;
  color: var(--text-100);
  background: var(--ink-950);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* Header -------------------------------------------------- */
.site-header,
body > header {
  position: sticky;
  top: 0;
  z-index: 60;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px;
  border-bottom: 1px solid rgba(var(--line-600-rgb), .6);
  background: rgba(var(--ink-950-rgb), .91);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
}
.logo {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-100);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.025em;
  text-decoration: none;
  white-space: nowrap;
}
.logo small {
  margin-left: 4px;
  color: var(--text-500);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.logo-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(var(--action-500-rgb), .48);
  border-radius: var(--radius-sm);
  color: var(--text-100);
  background: rgba(var(--action-500-rgb), .18);
  font-size: 15px;
  font-weight: 700;
}
.header-actions,
#userbox {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.uname { color: var(--text-300); font-size: 13px; }
.bal {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid rgba(var(--success-500-rgb), .26);
  border-radius: var(--radius-sm);
  color: var(--success-500);
  background: rgba(var(--success-500-rgb), .07);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.bal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success-500);
  box-shadow: none;
}
.account-trigger { min-width: 42px; min-height: 42px; padding: 0 11px; font-weight: 600; }
.account-avatar {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xs);
  color: var(--text-100);
  background: rgba(var(--action-500-rgb), .2);
  font-size: 12px;
  font-weight: 700;
}

/* Buttons ------------------------------------------------- */
button,
.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid rgba(var(--line-600-rgb), .95);
  border-radius: var(--radius-md);
  color: var(--text-300);
  background: var(--surface-800);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
  text-decoration: none;
  transition: border-color .16s ease, background .16s ease, color .16s ease, transform .16s ease, opacity .16s ease;
}
button:hover,
.btn:hover { border-color: rgba(var(--action-500-rgb), .45); color: var(--text-100); background: var(--surface-700); }
@media (hover:hover) {
  button:hover,
  .btn:hover { transform: translateY(-1px); }
}
button:active,
.btn:active { transform: none; }
button:disabled,
.btn:disabled,
.disabled-link { opacity: .45; cursor: not-allowed; pointer-events: none; transform: none; }
button.primary,
.primary,
.primary-inline {
  border-color: rgba(var(--action-500-rgb), .95);
  color: var(--text-100);
  background: var(--action-500);
  font-weight: 700;
  box-shadow: none;
}
button.primary,
.primary { width: 100%; }
button.primary:hover,
.primary:hover,
.primary-inline:hover { border-color: var(--action-500); background: rgba(var(--action-500-rgb), .9); filter: none; }
.ghost { background: transparent; }
.admin-link { border-color: rgba(var(--action-500-rgb), .42); background: rgba(var(--action-500-rgb), .08); }
.compact { min-height: 34px; padding: 6px 9px; border-radius: var(--radius-sm); font-size: 11px; }

/* Typography ---------------------------------------------- */
h1, h2, h3, h4 { color: var(--text-100); line-height: 1.25; }
.eyebrow {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--text-500);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.muted { color: var(--text-500); font-size: 12px; }
.ok { color: var(--success-500); }
.err { color: var(--danger-500); }
.mono { font-family: var(--font-mono); }
.tiny { font-size: 10px; }
.nowrap { white-space: nowrap; }

/* Surfaces ------------------------------------------------ */
.card {
  overflow: hidden;
  border: 1px solid rgba(var(--line-600-rgb), .72);
  border-radius: var(--radius-lg);
  background: var(--surface-800);
  box-shadow: none;
}
.panel-card { padding: 20px; }
.pad { padding: 14px; }
.count-chip,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid rgba(var(--line-600-rgb), .9);
  border-radius: var(--radius-sm);
  color: var(--text-500);
  background: var(--ink-900);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.success-chip { color: var(--success-500); border-color: rgba(var(--success-500-rgb), .24); background: rgba(var(--success-500-rgb), .06); }

/* Forms --------------------------------------------------- */
input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid rgba(var(--line-600-rgb), .98);
  border-radius: var(--radius-md);
  outline: none;
  color: var(--text-100);
  background: var(--ink-900);
  font-size: 13px;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input:focus,
select:focus,
textarea:focus { border-color: var(--action-500); box-shadow: 0 0 0 3px rgba(var(--action-500-rgb), .12); }
input::placeholder,
textarea::placeholder { color: rgba(var(--text-500-rgb), .7); }
textarea { resize: vertical; font-family: var(--font-mono); }
label { display: flex; flex-direction: column; gap: 6px; color: var(--text-300); font-size: 12px; font-weight: 500; }
.search-box { position: relative; display: flex; flex: 1; align-items: center; min-width: 220px; }
.search-box > span { position: absolute; left: 13px; z-index: 1; color: var(--text-500); font-size: 17px; }
.search-box input { padding-left: 39px; }
.msg { min-height: 18px; color: var(--text-500); font-size: 12px; }

/* Notices / status --------------------------------------- */
.notice { padding: 10px 12px; border: 1px solid; border-radius: var(--radius-md); font-size: 11.5px; line-height: 1.55; }
.notice.success { color: var(--success-500); background: rgba(var(--success-500-rgb), .06); border-color: rgba(var(--success-500-rgb), .24); }
.notice.danger { color: var(--danger-500); background: rgba(var(--danger-500-rgb), .06); border-color: rgba(var(--danger-500-rgb), .25); }
.notice.warning { color: var(--warning-500); background: rgba(var(--warning-500-rgb), .06); border-color: rgba(var(--warning-500-rgb), .26); }
.notice.info { color: var(--text-300); background: rgba(var(--action-500-rgb), .055); border-color: rgba(var(--action-500-rgb), .22); }
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 7px;
  border: 1px solid;
  border-radius: var(--radius-xs);
  font-size: 9.5px;
  font-weight: 700;
  white-space: nowrap;
}
.status-success { color: var(--success-500); background: rgba(var(--success-500-rgb), .06); border-color: rgba(var(--success-500-rgb), .22); }
.status-processing { color: var(--text-300); background: rgba(var(--action-500-rgb), .07); border-color: rgba(var(--action-500-rgb), .24); }
.status-refunded { color: var(--text-300); background: rgba(var(--text-500-rgb), .07); border-color: rgba(var(--text-500-rgb), .2); }
.status-warning { color: var(--warning-500); background: rgba(var(--warning-500-rgb), .06); border-color: rgba(var(--warning-500-rgb), .24); }
.status-danger { color: var(--danger-500); background: rgba(var(--danger-500-rgb), .06); border-color: rgba(var(--danger-500-rgb), .24); }
.status-neutral { color: var(--text-500); background: rgba(var(--text-500-rgb), .055); border-color: rgba(var(--text-500-rgb), .18); }

/* Modal --------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 18px;
  background: var(--overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(10px);
}
.modal[hidden] { display: none !important; }
.modal-box {
  position: relative;
  width: min(100%, 560px);
  max-height: min(92vh, 900px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  border: 1px solid rgba(var(--line-600-rgb), .98);
  border-radius: var(--radius-xl);
  background: var(--surface-800);
  box-shadow: var(--shadow-overlay);
}
.sheet-handle { display: none; width: 42px; height: 4px; margin: -8px auto 0; border-radius: 999px; background: rgba(var(--text-500-rgb), .35); }
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  color: var(--text-500);
  background: var(--ink-900);
  font-size: 20px;
}
.modal-title { padding-right: 38px; font-size: 22px; letter-spacing: -.025em; }
.result-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid;
  border-radius: var(--radius-lg);
  font-size: 22px;
  font-weight: 700;
}
.result-icon.success { color: var(--success-500); background: rgba(var(--success-500-rgb), .08); border-color: rgba(var(--success-500-rgb), .24); }
.result-icon.warning { color: var(--warning-500); background: rgba(var(--warning-500-rgb), .08); border-color: rgba(var(--warning-500-rgb), .25); }
pre {
  max-height: 320px;
  overflow: auto;
  padding: 11px;
  border: 1px solid rgba(var(--line-600-rgb), .72);
  border-radius: var(--radius-sm);
  color: var(--text-300);
  background: var(--surface-3);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
}
.total-box,
.order-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(var(--line-600-rgb), .72);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.total-box span,
.order-summary span { color: var(--text-500); font-size: 11px; }
.auth-actions { display: grid; grid-template-columns: 1.25fr .75fr; gap: 8px; }

/* Toast --------------------------------------------------- */
.toast-wrap {
  position: fixed;
  top: calc(var(--header-h) + 16px);
  right: 18px;
  z-index: 260;
  width: min(360px, calc(100vw - 36px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 13px;
  border: 1px solid rgba(var(--line-600-rgb), .96);
  border-radius: var(--radius-md);
  color: var(--text-100);
  background: var(--surface-800);
  box-shadow: var(--shadow-float);
  font-size: 11.5px;
  opacity: 0;
  transform: translateX(16px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-success { border-color: rgba(var(--success-500-rgb), .3); }
.toast-error { border-color: rgba(var(--danger-500-rgb), .3); }
.toast-info { border-color: rgba(var(--action-500-rgb), .3); }

/* Generic layout ----------------------------------------- */
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-title h2,
.section-title h3 { font-size: 22px; letter-spacing: -.02em; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.section-head h3 { font-size: 17px; }
.section-block { margin-top: 24px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; color: var(--text-500); font-size: 11px; }
.loading-card,
.empty-state {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  border: 1px dashed rgba(var(--line-600-rgb), .95);
  border-radius: var(--radius-lg);
  color: var(--text-500);
  background: rgba(var(--surface-800-rgb), .55);
  text-align: center;
}
.empty-state b { color: var(--text-300); font-size: 15px; }
.empty-state.danger { border-color: rgba(var(--danger-500-rgb), .27); }
.empty-state .btn { margin-top: 8px; }
code {
  padding: 2px 5px;
  border: 1px solid rgba(var(--line-600-rgb), .75);
  border-radius: var(--radius-xs);
  color: var(--text-300);
  background: var(--ink-900);
  font-family: var(--font-mono);
}

/* Accessible interaction -------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid rgba(var(--action-500-rgb), .45);
  outline-offset: 2px;
}

@keyframes sheet-in { from { transform: translateY(16px); opacity: .75; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  :root { --header-h: 64px; }
  body > header,
  .site-header { min-height: var(--header-h); padding: 9px 12px; }
  .logo { font-size: 17px; }
  .logo small { display: none; }
  .logo-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .uname { display: none; }
  button, .btn { min-height: 44px; font-size: 13px; }
  .modal { align-items: flex-end; padding: 0; overflow: hidden; }
  .modal-box {
    width: 100%;
    max-height: min(92dvh, 760px);
    overscroll-behavior: contain;
    padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheet-in .18s ease-out;
  }
  .sheet-handle { display: block; }
  .close { top: 10px; right: 12px; }
  .modal-title { font-size: 20px; }
  .section-title h2,
  .section-title h3 { font-size: 20px; }
  .toast-wrap { top: 74px; right: 12px; width: calc(100vw - 24px); }
  .auth-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
