/* Sabuy Store design foundation (AS-023): tokens and shared components for the login page, the
   employee store and the admin console. No inline styles anywhere (CSP style-src 'self'). */

:root {
  color-scheme: light dark;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "Noto Sans Thai", "Leelawadee UI", "Sarabun", Tahoma, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, "Noto Sans Mono", monospace;

  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --target: 44px;
  --container: 1120px;

  /* Light palette. Text pairs are 4.5:1 or better; borders of controls 3:1 or better. */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #dde2ea;
  --border-strong: #6f7b8f;
  --text: #172033;
  --muted: #4b5568;
  --link: #0b57d0;
  --brand: #0b57d0;
  --brand-strong: #0842a0;
  --on-brand: #ffffff;
  --brand-soft: #e6eeff;
  --brand-soft-text: #0842a0;
  --ok-bg: #e3f4e8;
  --ok-text: #13612b;
  --warn-bg: #fff3d6;
  --warn-text: #7a4100;
  --danger: #b3261e;
  --on-danger: #ffffff;
  --danger-bg: #fde8e7;
  --danger-text: #a1231b;
  --muted-bg: #eceff4;
  --focus: #0b57d0;
  --skeleton: #e4e8ef;
  --skeleton-hi: #f1f4f8;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
  --shadow-md: 0 4px 12px rgb(16 24 40 / 0.12);
  --shadow-lg: 0 16px 40px rgb(16 24 40 / 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b;
    --surface: #161d28;
    --surface-2: #1e2734;
    --border: #2c3747;
    --border-strong: #8592a6;
    --text: #e7ecf3;
    --muted: #a7b2c3;
    --link: #9cc2ff;
    --brand: #8ab8ff;
    --brand-strong: #b0cfff;
    --on-brand: #08214d;
    --brand-soft: #1b2c49;
    --brand-soft-text: #c3d8ff;
    --ok-bg: #15301f;
    --ok-text: #8ee0a6;
    --warn-bg: #3a2a0d;
    --warn-text: #ffcf7a;
    --danger: #ffb4ab;
    --on-danger: #4a0d08;
    --danger-bg: #3b1513;
    --danger-text: #ffb4ab;
    --muted-bg: #232c3a;
    --focus: #9cc2ff;
    --skeleton: #222b38;
    --skeleton-hi: #2b3545;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 12px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.6);
  }
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 var(--space-3);
}

h1 {
  font-size: var(--text-2xl);
}

h2 {
  font-size: var(--text-xl);
}

h3 {
  font-size: var(--text-lg);
}

p {
  margin: 0 0 var(--space-3);
}

a {
  color: var(--link);
  text-underline-offset: 0.15em;
}

img,
svg {
  max-width: 100%;
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus {
  outline: none;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: var(--text-sm);
}

.nowrap {
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -100px;
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--link);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.skip-link:focus {
  top: var(--space-3);
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 640px) {
  .container {
    padding-inline: var(--space-5);
  }
}

main {
  display: block;
  position: relative;
  padding-block: var(--space-5) var(--space-8);
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  min-height: 64px;
  padding-block: var(--space-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--target);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}

.brand img {
  width: 36px;
  height: 36px;
  flex: none;
}

.brand-tag {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-soft-text);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.user-name {
  color: var(--muted);
  font-size: var(--text-sm);
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 519px) {
  .user-name {
    display: none;
  }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--target);
  min-width: var(--target);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
  border-color: var(--border-strong);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
}

.btn-primary:hover {
  background: var(--brand-strong);
  border-color: transparent;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--link);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
}

.btn-danger {
  background: var(--danger);
  color: var(--on-danger);
}

.btn-danger:hover {
  border-color: transparent;
  filter: brightness(0.92);
}

.btn-sm {
  padding: 8px 14px;
  font-size: var(--text-sm);
}

.btn-lg {
  min-height: 56px;
  padding: 14px 28px;
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0;
  width: var(--target);
  font-size: 1.25rem;
  line-height: 1;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 519px) {
  .card {
    padding: var(--space-4);
  }
}

.stack {
  display: grid;
  gap: var(--space-4);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--muted-bg);
  color: var(--muted);
}

.badge-brand {
  background: var(--brand-soft);
  color: var(--brand-soft-text);
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.badge-muted {
  border: 1px dashed var(--border-strong);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* ---------- Form fields ---------- */

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > label,
.label {
  font-weight: 600;
}

.hint {
  color: var(--muted);
  font-size: var(--text-sm);
  margin: 0;
}

.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: var(--target);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* Error borders only after the user touched the field or tried to submit (D-005-6). */
input:user-invalid,
.touched:invalid,
.submitted :invalid,
[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--target);
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--brand);
}

.form-grid {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 720px) {
  .form-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid.cols-2 > .toast-region,
  .form-grid.cols-2 > .button-row {
    grid-column: 1 / -1;
  }
}

/* ---------- Toasts (role="status" regions near the action) ---------- */

.toast-region {
  display: grid;
  gap: var(--space-2);
}

.toast-region:empty {
  display: none;
}

.toast-region.global {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 60;
  max-width: 520px;
  margin-inline: auto;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.18s ease-out;
}

.toast-body {
  flex: 1;
  min-width: 0;
  padding-block: 10px;
  overflow-wrap: anywhere;
}

.toast-body p {
  margin: 0;
}

.toast-body p + p {
  margin-top: var(--space-1);
}

.toast-ok {
  border-left-color: var(--ok-text);
}

.toast-error {
  border-left-color: var(--danger-text);
  background: var(--danger-bg);
}

.toast-info {
  border-left-color: var(--brand);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- Modal dialog ---------- */

dialog.modal {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog.modal::backdrop {
  background: rgb(8 12 20 / 0.6);
}

.modal-body {
  padding: var(--space-5) var(--space-5) var(--space-4);
}

.modal-body h2 {
  font-size: var(--text-xl);
}

.modal-body p {
  margin: 0;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 0 var(--space-5) var(--space-5);
}

@media (max-width: 419px) {
  .modal-actions .btn {
    flex: 1 1 100%;
  }
}

/* ---------- Skeleton loaders ---------- */

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-hi) 37%, var(--skeleton) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-line {
  height: 14px;
  width: 100%;
}

.skeleton-line + .skeleton-line {
  margin-top: var(--space-2);
}

.skeleton-title {
  height: 22px;
  width: 60%;
}

.sk-w-40 {
  width: 40%;
}

.sk-w-60 {
  width: 60%;
}

.sk-w-80 {
  width: 80%;
}

.skeleton-avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  flex: none;
}

.skeleton-button {
  height: var(--target);
  border-radius: var(--radius);
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .toast {
    animation: none;
  }
}

/* ---------- Empty and error states ---------- */

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-4);
  text-align: center;
}

.empty-state h2 {
  margin: var(--space-2) 0 0;
  font-size: var(--text-lg);
}

.empty-state p {
  max-width: 46ch;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-soft-text);
  font-size: 1.75rem;
  font-weight: 700;
}

.empty-state.error .empty-icon {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* ---------- Letter avatars ---------- */

.avatar {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: var(--radius-lg);
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 1.125rem;
}

.avatar-lg {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  font-size: 2.25rem;
}

/* White text on every tone is 5:1 or better. */
.tone-0 { background: #1d4ed8; }
.tone-1 { background: #047857; }
.tone-2 { background: #b91c1c; }
.tone-3 { background: #7e22ce; }
.tone-4 { background: #c2410c; }
.tone-5 { background: #0f766e; }
.tone-6 { background: #be185d; }
.tone-7 { background: #4338ca; }

/* ---------- Disclosure ---------- */

details.disclosure > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target);
  cursor: pointer;
  font-weight: 600;
  color: var(--link);
  list-style: none;
  border-radius: var(--radius-sm);
}

details.disclosure > summary::-webkit-details-marker {
  display: none;
}

details.disclosure > summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex: none;
}

details.disclosure[open] > summary::before {
  transform: rotate(45deg);
}

/* ---------- Numbered steps ---------- */

ol.steps {
  counter-reset: step;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

ol.steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: var(--space-3);
  align-items: start;
}

ol.steps > li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-soft-text);
  font-weight: 700;
}

ol.steps > li > span {
  padding-top: 4px;
}

/* ---------- Checksum box ---------- */

.hash-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.hash {
  flex: 1 1 16rem;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* ---------- Login page ---------- */

.login-main {
  display: grid;
  place-items: start center;
  padding-top: var(--space-7);
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.login-card .brand-hero {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  text-align: center;
}

.login-card .brand-hero img {
  width: 64px;
  height: 64px;
}

.login-card .brand-hero p {
  margin: 0;
}
