/* ==========================================================
   TPchannel — Global Design Foundation (v2 Redesign)
   Branch: design/antigravity-redesign
   
   ไฟล์นี้คือ "แหล่งความจริง" เดียวของ Design System
   ทุกหน้าต้อง import ไฟล์นี้ก่อนไฟล์ CSS เฉพาะหน้า
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&family=Noto+Sans:wght@400;500;600;700;800&display=swap');

/* ---------- Color Tokens ---------- */
:root {
  /* Primary */
  --green: #0f6b4f;
  --green-dark: #0a5540;
  --green-mid: #0d9068;
  --green-light: #3dba8a;
  --green-faint: #e8f5ee;
  --on-green: #ffffff;

  /* Neutral */
  --ink: #111c16;
  --ink-secondary: #2a3a30;
  --muted: #5a6e62;
  --placeholder: #8a9a90;
  --line: #dce5de;
  --surface: #f4f7f5;
  --bg: #ffffff;

  /* Accent */
  --accent-lime: #d4ec7a;
  --accent-purple: #5b5fc7;
  --accent-amber: #c47a20;

  /* Semantic */
  --danger: #c53030;
  --danger-bg: #fff5f5;
  --success: #0f6b4f;
  --success-bg: #e8f5ee;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(17, 28, 22, 0.05);
  --shadow-sm: 0 2px 8px rgba(17, 28, 22, 0.04);
  --shadow-md: 0 4px 16px rgba(17, 28, 22, 0.06);
  --shadow-lg: 0 8px 32px rgba(17, 28, 22, 0.08);
  --shadow-xl: 0 12px 48px rgba(17, 28, 22, 0.1);
  --shadow-glow: 0 4px 14px rgba(15, 107, 79, 0.3);

  /* Spacing (8px system) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Typography */
  --font: 'Noto Sans Thai', 'Noto Sans', system-ui, -apple-system, sans-serif;
  --leading-tight: 1.35;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;

  /* Transition */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.25s;
  --duration-slow: 0.4s;

  /* Z-index scale */
  --z-header: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* ---------- Dark Mode Tokens ---------- */
html.dark,
[data-theme="dark"] {
  --green: #3dba8a;
  --green-dark: #2fa87a;
  --green-mid: #34c890;
  --green-light: #5dd4a4;
  --green-faint: #1a3a2a;
  --on-green: #07120d;

  --ink: #e4ede8;
  --ink-secondary: #c0d0c8;
  --muted: #9baaa0;
  --placeholder: #6a7a70;
  --line: #2a3a30;
  --surface: #1a2820;
  --bg: #111c16;

  --danger: #fc8181;
  --danger-bg: #2d1b1b;
  --success-bg: #1a3a2a;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.15);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.16);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 12px 48px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 4px 18px rgba(61, 186, 138, 0.25);
}

/* Auto dark mode (system preference) */
@media (prefers-color-scheme: dark) {
  html:not(.light):not([data-theme="light"]) {
    --green: #3dba8a;
    --green-dark: #2fa87a;
    --green-mid: #34c890;
    --green-light: #5dd4a4;
    --green-faint: #1a3a2a;
    --on-green: #07120d;
    --ink: #e4ede8;
    --ink-secondary: #c0d0c8;
    --muted: #9baaa0;
    --placeholder: #6a7a70;
    --line: #2a3a30;
    --surface: #1a2820;
    --bg: #111c16;
    --danger: #fc8181;
    --danger-bg: #2d1b1b;
    --success-bg: #1a3a2a;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.15);
    --shadow-sm: 0 2px 8px rgba(0,0,0,.12);
    --shadow-md: 0 4px 16px rgba(0,0,0,.16);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.2);
    --shadow-xl: 0 12px 48px rgba(0,0,0,.25);
    --shadow-glow: 0 4px 18px rgba(61,186,138,.25);
  }
}

/* ---------- CSS Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--sp-6);
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: var(--leading-normal);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis: none;
  transition: background var(--duration-slow), color var(--duration-slow);
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea, summary { font: inherit; color: inherit; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: none; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
h1, h2, h3, h4, h5, h6, p { margin: 0; }
h1, h2, h3, h4 { line-height: var(--leading-tight); letter-spacing: -0.02em; }
img, svg { max-width: 100%; display: block; }
[hidden] { display: none !important; }
::selection { background: var(--green-faint); color: var(--green-dark); }

/* ---------- Focus ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); color: var(--ink); font-size: 22px;
  border: 1px solid var(--line);
}
.theme-toggle:hover { background: var(--green-faint); }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline-offset: 1px;
}

/* ---------- Layout ---------- */
.wrap {
  width: min(1120px, calc(100% - var(--sp-10)));
  margin-inline: auto;
}
.wrap-narrow { width: min(780px, calc(100% - var(--sp-10))); margin-inline: auto; }
.wrap-wide { width: min(1320px, calc(100% - var(--sp-10))); margin-inline: auto; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; line-height: var(--leading-relaxed); }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Eyebrow ---------- */
.eyebrow {
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.eyebrow > span {
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: g-pulse 2s ease-in-out infinite;
}
@keyframes g-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-3);
  min-height: 48px;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.5;
  transition: all var(--duration) var(--ease);
}
.btn-primary {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-mid) 100%);
  color: var(--on-green);
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(15, 107, 79, 0.4);
  text-decoration: none;
}
.btn-primary:active { transform: translateY(0); }
.btn-primary .arrow {
  font-size: 18px;
  transition: transform 0.2s ease;
  display: inline-block;
}
.btn-primary:hover .arrow { transform: translateX(4px); }

.btn-secondary {
  color: var(--green);
  border-color: var(--line);
  background: var(--bg);
}
.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--green);
  text-decoration: none;
}

.btn-ghost {
  color: var(--green);
  padding-inline: var(--sp-3);
}
.btn-ghost:hover { text-decoration: underline; }

/* ---------- Inputs ---------- */
.input, input[type="text"], input[type="url"],
input[type="email"], input[type="password"],
input[type="search"], input[type="tel"],
input[type="number"], textarea, select {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  min-width: 0;
  width: 100%;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--bg);
  min-height: 48px;
  font-size: 16px;
  transition: border-color var(--duration), box-shadow var(--duration);
}
.input::placeholder, input::placeholder,
textarea::placeholder { color: var(--placeholder); }
.input:focus, input:focus, textarea:focus, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 107, 79, 0.1);
  outline: none;
}
.input[aria-invalid="true"], input[aria-invalid="true"] {
  border-color: var(--danger);
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  transition: all var(--duration) var(--ease);
}
.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--green);
}

/* ---------- Labels ---------- */
.label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: var(--sp-2);
  color: var(--ink);
}

/* ---------- Messages ---------- */
.field-error { font-size: 13px; color: var(--danger); overflow-wrap: anywhere; }
.field-error:not(:empty) { margin-top: var(--sp-2); }
.message { font-size: 14px; color: var(--green); overflow-wrap: anywhere; }
.message.is-error { color: var(--danger); }
.message:not(:empty) { margin-top: var(--sp-3); }

/* ---------- Skip Link ---------- */
.skip-link {
  position: fixed; top: -100px; left: var(--sp-5);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg);
  color: var(--green);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: var(--z-toast);
  font-weight: 600;
  font-size: 14px;
}
.skip-link:focus { top: var(--sp-3); }

/* ---------- Section Blocks ---------- */
.section-block { padding-block: var(--sp-12); }
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.section-heading .muted { font-size: 12px; }
.text-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  transition: gap var(--duration);
}
.text-link:hover { gap: var(--sp-3); text-decoration: none; }

/* ---------- Animations ---------- */
@keyframes g-fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes g-slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes g-fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Breakpoints ---------- */
/* Mobile: max-width: 767px */
/* Tablet: max-width: 1023px */
/* Desktop: min-width: 1024px */
/* Wide: min-width: 1440px */

@media (max-width: 767px) {
  .wrap { width: calc(100% - var(--sp-8)); }
  .section-block { padding-block: var(--sp-8); }
  .section-heading {
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-bottom: var(--sp-5);
    align-items: flex-start;
  }
  h2 { font-size: 22px; }
}
