/* ==========================================================================
   Advanced Next Tech — design system: tokens + shared primitives
   Used by both the public website (site.css) and the admin panel (admin.css)
   ========================================================================== */

:root {
  --font-sans: "Archivo", "IBM Plex Sans Thai", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --stretch-display: 112%;

  --signal: #ff5a1f;
  --signal-hover: #ff6d38;
  --signal-press: #ee4b10;
  --on-signal: #111316;
  --ink-950: #0a0c0f;
  --ink-900: #111316;
  --ink-800: #1a1d22;
  --paper-50: #f4f2ed;

  --r-xs: 3px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --dur-1: 140ms;
  --dur-2: 260ms;
  --dur-3: 520ms;

  --container: 1280px;
  --gutter: clamp(18px, 4vw, 44px);
  --header-h: 76px;
}

/* ---------- Light: warm drafting paper ---------- */
:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f2ed;
  --bg-2: #ebe8e1;
  --bg-3: #e2ded5;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #111316;
  --text-2: #41454c;
  --text-3: #5f646b;
  --line: rgba(17, 19, 22, .11);
  --line-2: rgba(17, 19, 22, .2);
  --line-strong: #111316;
  --accent: #ff5a1f;
  --accent-text: #b33a0b;
  --accent-soft: rgba(255, 90, 31, .1);
  --focus: rgba(255, 90, 31, .42);
  --grid-line: rgba(17, 19, 22, .055);
  --overlay: rgba(10, 12, 15, .55);
  --shadow-1: 0 1px 2px rgba(17, 19, 22, .06);
  --shadow-2: 0 12px 32px -14px rgba(17, 19, 22, .22), 0 2px 6px rgba(17, 19, 22, .05);
  --shadow-3: 0 34px 70px -24px rgba(17, 19, 22, .35);
  --success: #146c43;
  --success-soft: rgba(20, 108, 67, .1);
  --warning: #8f5300;
  --warning-soft: rgba(245, 158, 11, .15);
  --danger: #b42318;
  --danger-soft: rgba(217, 45, 32, .09);
  --info: #1b5bb8;
  --info-soft: rgba(46, 144, 250, .1);
}

/* ---------- Dark: graphite ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e11;
  --bg-2: #121418;
  --bg-3: #191c21;
  --surface: #15181c;
  --surface-2: #1b1e23;
  --text: #edebe5;
  --text-2: #b9b7b0;
  --text-3: #8d8c86;
  --line: rgba(237, 235, 229, .1);
  --line-2: rgba(237, 235, 229, .18);
  --line-strong: #edebe5;
  --accent: #ff5a1f;
  --accent-text: #ff7d4a;
  --accent-soft: rgba(255, 90, 31, .14);
  --focus: rgba(255, 125, 74, .55);
  --grid-line: rgba(237, 235, 229, .045);
  --overlay: rgba(4, 5, 7, .7);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 16px 40px -16px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-3: 0 34px 80px -24px rgba(0, 0, 0, .85);
  --success: #45cf87;
  --success-soft: rgba(69, 207, 135, .12);
  --warning: #f5b546;
  --warning-soft: rgba(245, 181, 70, .13);
  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, .12);
  --info: #6aa9ff;
  --info-soft: rgba(106, 169, 255, .12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0c0e11; --bg-2: #121418; --bg-3: #191c21; --surface: #15181c; --surface-2: #1b1e23;
    --text: #edebe5; --text-2: #b9b7b0; --text-3: #8d8c86;
    --line: rgba(237, 235, 229, .1); --line-2: rgba(237, 235, 229, .18); --line-strong: #edebe5;
    --accent-text: #ff7d4a; --accent-soft: rgba(255, 90, 31, .14); --grid-line: rgba(237, 235, 229, .045);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.62;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, video, svg { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .18em; }
p { margin: 0 0 1em; text-wrap: pretty; }
h1, h2, h3, h4, h5 {
  margin: 0;
  font-weight: 600;
  font-stretch: var(--stretch-display);
  letter-spacing: -.022em;
  line-height: 1.08;
  text-wrap: balance;
}
ul, ol { margin: 0; padding: 0; }
dl, dd { margin: 0; }
figure { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
::selection { background: var(--signal); color: var(--on-signal); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
[hidden] { display: none !important; }
.bi { line-height: 1; vertical-align: -.125em; }
.bi::before { vertical-align: 0 !important; }

/* ---------- Layout helpers ---------- */
.container { width: 100%; max-width: calc(var(--container) + var(--gutter) * 2); margin-inline: auto; padding-inline: var(--gutter); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 1000; padding: 10px 16px;
  background: var(--signal); color: var(--on-signal); font-weight: 600; border-radius: var(--r-sm);
  transition: top var(--dur-2) var(--ease-out);
}
.skip-link:focus { top: 12px; }

/* ---------- Type helpers ---------- */
.mono { font-family: var(--font-mono); }
.eyebrow {
  display: inline-flex; align-items: center; gap: .6em;
  font-family: var(--font-mono); font-size: .75rem; font-weight: 500;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-3);
}
.eyebrow .dot { width: 6px; height: 6px; background: var(--accent); border-radius: 1px; flex: none; }
.accent-text { color: var(--accent-text); }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  --btn-h: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: .55em;
  height: var(--btn-h); padding: 0 1.3rem;
  border: 1px solid transparent; border-radius: var(--r-sm);
  font-family: var(--font-sans); font-size: .95rem; font-weight: 550; line-height: 1; letter-spacing: .005em;
  text-decoration: none; white-space: nowrap; user-select: none;
  background: transparent; color: var(--text);
  transition: background-color var(--dur-1) ease, border-color var(--dur-1) ease, color var(--dur-1) ease,
              transform var(--dur-1) ease, box-shadow var(--dur-2) ease;
}
.btn:active { transform: translateY(1px); }
.btn .bi { font-size: 1.05em; transition: transform var(--dur-2) var(--ease-out); }
.btn:hover .bi-arrow-right, .btn:hover .bi-arrow-up-right { transform: translateX(3px); }
.btn:hover .bi-arrow-up-right { transform: translate(2px, -2px); }
.btn-primary { background: var(--signal); color: var(--on-signal); }
.btn-primary:hover { background: var(--signal-hover); box-shadow: 0 10px 26px -10px rgba(255, 90, 31, .75); }
.btn-primary:active { background: var(--signal-press); }
.btn-outline { border-color: var(--line-2); color: var(--text); }
.btn-outline:hover { border-color: var(--text); background: color-mix(in srgb, var(--text) 4%, transparent); }
.btn-ink { background: var(--text); color: var(--bg); }
.btn-ink:hover { background: color-mix(in srgb, var(--text) 86%, var(--accent)); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { --btn-h: 36px; padding: 0 .9rem; font-size: .875rem; }
.btn-xs { --btn-h: 30px; padding: 0 .7rem; font-size: .8125rem; border-radius: 5px; }
.btn-lg { --btn-h: 56px; padding: 0 1.6rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn.is-loading::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: transparent; color: var(--text);
  transition: background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1);
}
.icon-btn:hover { border-color: var(--line-2); background: color-mix(in srgb, var(--text) 5%, transparent); }
.link-arrow {
  display: inline-flex; align-items: center; gap: .45em; font-weight: 550; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--line-2); padding-bottom: 2px; transition: border-color var(--dur-1), gap var(--dur-2) var(--ease-out);
}
.link-arrow:hover { border-color: var(--accent); gap: .7em; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 7px; min-width: 0; }
.label { font-size: .8125rem; font-weight: 600; color: var(--text-2); letter-spacing: .005em; }
.label .req { color: var(--accent-text); margin-left: 2px; }
.label .opt { font-weight: 400; color: var(--text-3); margin-left: 4px; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: .95rem; line-height: 1.4;
  transition: border-color var(--dur-1), box-shadow var(--dur-1), background-color var(--dur-1);
  appearance: none;
}
.textarea { min-height: 130px; resize: vertical; line-height: 1.55; }
.select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23878787' stroke-width='1.6'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 15px center;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--text) 35%, transparent); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus);
}
.input[readonly] { background: var(--bg-2); }
.is-invalid, .is-invalid:hover { border-color: var(--danger) !important; }
.is-invalid:focus { box-shadow: 0 0 0 4px var(--danger-soft) !important; }
.help { font-size: .8125rem; line-height: 1.45; color: var(--text-3); margin: 0; }
.error-text { font-size: .8125rem; color: var(--danger); margin: 0; }
.check { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .92rem; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--signal); flex: none; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; width: 40px; height: 22px; border-radius: 99px; flex: none;
  background: var(--bg-3); border: 1px solid var(--line-2); transition: background-color var(--dur-2), border-color var(--dur-2);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--dur-2) var(--ease-out);
}
.switch input:checked + .track { background: var(--signal); border-color: var(--signal); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .track { box-shadow: 0 0 0 4px var(--focus); }

/* ---------- Tags & badges ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: .6875rem; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 8px 3px; border: 1px solid var(--line-2); border-radius: var(--r-xs); color: var(--text-2);
  line-height: 1.2; white-space: nowrap;
}
.tag-id {
  background: var(--ink-950); color: #f4f2ed; border-color: transparent;
  box-shadow: inset 2px 0 0 var(--signal); padding-left: 9px;
}
.tag-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: 99px; font-size: .72rem; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  background: var(--bg-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 9999; display: grid; gap: 10px; width: min(400px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 12px;
  padding: 14px 14px 14px 16px; border-radius: var(--r-md);
  background: var(--ink-900); color: #f1efe9; box-shadow: var(--shadow-3);
  border: 1px solid rgba(255, 255, 255, .08); pointer-events: auto;
  font-size: .9rem; line-height: 1.45;
  animation: toast-in var(--dur-3) var(--ease-out) both;
}
.toast .bi { font-size: 1.1rem; margin-top: 1px; }
.toast.success .toast-ico { color: #45cf87; }
.toast.danger .toast-ico, .toast.error .toast-ico { color: #ff6b5e; }
.toast.warning .toast-ico { color: #f5b546; }
.toast.info .toast-ico { color: #8fb8ff; }
.toast-close { border: 0; background: none; color: rgba(255, 255, 255, .5); padding: 0 2px; font-size: 1.1rem; line-height: 1; }
.toast-close:hover { color: #fff; }
.toast.is-leaving { animation: toast-out var(--dur-2) ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Brand + blueprint helpers (shared) ---------- */
.blueprint {
  --gl: var(--grid-line);
  background-image:
    linear-gradient(var(--gl) 1px, transparent 1px),
    linear-gradient(90deg, var(--gl) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--gl) 55%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--gl) 55%, transparent) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 24px 24px, 24px 24px;
}
.crop-marks {
  --c: var(--accent); --l: 14px; --t: 1.5px;
  position: absolute; inset: -9px; pointer-events: none;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) top left / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) top right / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) top right / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / var(--t) var(--l) no-repeat;
}
.brand-mark {
  display: inline-block; width: 40px; height: 21px; flex: none; background: currentColor;
  -webkit-mask: url("../img/mark.png") center / contain no-repeat;
  mask: url("../img/mark.png") center / contain no-repeat;
}
.logo-stack {
  display: block; width: 150px; aspect-ratio: 480 / 394; background: currentColor;
  -webkit-mask: url("../img/logo-stack.png") center / contain no-repeat;
  mask: url("../img/logo-stack.png") center / contain no-repeat;
}

/* ---------- Reveal on scroll (content stays visible without JS) ---------- */
html.js [data-reveal] {
  opacity: 0; transform: translateY(22px);
  transition: opacity .9s var(--ease-out), transform .9s var(--ease-out);
  transition-delay: calc(var(--d, 0) * 90ms);
}
html.js [data-reveal].is-in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  html.js [data-reveal] { opacity: 1; transform: none; }
}
