/* ============================================================
   YoAI — Showcase design system
   โทนสว่าง สดใส (ฟ้า–ม่วง–ส้ม) · ใช้ร่วมกันทุกเว็บใน /showcase
   ============================================================ */

:root {
  /* ---- แบรนด์: ฟ้าสด + ม่วง + ส้มอุ่น ---- */
  --brand: #2f6bff;
  --brand-dark: #1f4fd8;
  --brand-soft: #e8efff;
  --violet: #7a5cf0;
  --violet-soft: #f0ebff;
  --orange: #ff7a2f;
  --orange-soft: #fff0e6;
  --sun: #ffc233;
  --sun-soft: #fff6dd;
  --mint: #12b886;
  --mint-soft: #e2f8f0;
  --pink: #f5568a;
  --pink-soft: #ffeaf1;

  /* ---- ตัวหนังสือ / พื้น ---- */
  --ink: #1c2440;
  --ink-2: #58658a;
  --ink-3: #8b97b8;

  --bg: #f6f8ff;
  --surface: #ffffff;
  --surface-2: #eef2fd;
  --border: #e2e8f8;

  /* ---- สถานะ ---- */
  --ok: #0f9d6e;      --ok-bg: #e2f8f0;
  --warn: #b8760a;    --warn-bg: #fff4dc;
  --danger: #d93b52;  --danger-bg: #ffe9ed;
  --info: #2f6bff;    --info-bg: #e8efff;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 55, 120, .05), 0 8px 22px rgba(31, 55, 120, .07);
  --shadow-lg: 0 2px 8px rgba(31, 55, 120, .07), 0 22px 50px rgba(31, 55, 120, .14);

  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", -apple-system,
    BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* สีประจำแต่ละเว็บ (override ได้ในแต่ละหน้า) */
  --accent: var(--brand);
  --accent-soft: var(--brand-soft);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { line-height: 1.32; margin: 0; font-weight: 600; letter-spacing: -.012em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

.wrap { width: min(1180px, 100% - 40px); margin-inline: auto; }
.wrap-narrow { width: min(880px, 100% - 40px); margin-inline: auto; }

/* ---------- ป้าย "ระบบสาธิต" (มีทุกเว็บ) ---------- */
.demo-bar {
  background: linear-gradient(90deg, var(--sun-soft), var(--orange-soft) 55%, var(--pink-soft));
  color: #8a5a11;
  border-bottom: 1px solid #ffe0b8;
  font-size: 12.5px;
  padding: 8px 16px;
  text-align: center;
}
.demo-bar strong { color: #6f4200; font-weight: 700; }
.demo-bar a { color: #b8560a; text-decoration: underline; }

/* ---------- แถบหัวเว็บ ---------- */
.site-head {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-head .inner { display: flex; align-items: center; gap: 18px; height: 64px; }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 700; color: var(--ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(140deg, var(--brand), var(--violet));
  color: #fff; display: grid; place-items: center;
  font-size: 15px; font-weight: 700; letter-spacing: -.03em;
  box-shadow: 0 4px 12px rgba(47, 107, 255, .38);
}
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); letter-spacing: .01em; }

.site-nav { margin-inline-start: auto; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.site-nav a { padding: 7px 13px; border-radius: 9px; font-size: 14px; color: var(--ink-2); font-weight: 500; }
.site-nav a:hover { background: var(--surface-2); color: var(--brand); text-decoration: none; }
.site-nav a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* จอเล็ก: เมนูเยอะ ๆ ต้องไม่ล้นทับเนื้อหา — ขึ้นบรรทัดใหม่แล้วเลื่อนแนวนอนแทน
   (ก่อนแก้: .inner สูงตายตัว 64px แต่เมนู 5–7 อันสูงถึง 158px จนทะลุออกมาทับหน้า) */
@media (max-width: 900px) {
  .site-head .inner { height: auto; min-height: 58px; padding-block: 9px; gap: 10px; flex-wrap: wrap; }
  .site-nav { width: 100%; margin-inline-start: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a { white-space: nowrap; flex: 0 0 auto; }
}

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border-radius: 11px; border: 1px solid transparent;
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1.4;
  cursor: pointer; transition: .16s ease; white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(47, 107, 255, .3); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-warm { background: linear-gradient(135deg, var(--orange), #ff9d3d); color: #fff; box-shadow: 0 6px 16px rgba(255, 122, 47, .35); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-head h3 { font-size: 15.5px; }
.card-head .spacer { margin-inline-start: auto; }

/* ---------- ป้ายสถานะ ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6;
  background: var(--surface-2); color: var(--ink-2);
}
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.tag-info { background: var(--info-bg); color: var(--info); }
.tag-violet { background: var(--violet-soft); color: #5b3fd0; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.tag-plain::before { display: none; }

/* ---------- ตาราง ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; min-width: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 620px; }
table.data th {
  text-align: start; font-weight: 600; font-size: 12px; letter-spacing: .04em;
  color: var(--ink-3); text-transform: uppercase;
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2);
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f8faff; }
.num { font-variant-numeric: tabular-nums; text-align: end; font-family: var(--mono); font-size: 13.5px; }

/* ---------- ฟอร์ม ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=tel], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 10px 13px; font-family: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); transition: .15s;
}
@media (min-width: 700px) {
  input[type=text], input[type=number], input[type=date], input[type=tel], input[type=email], input[type=search], select, textarea { font-size: 14.5px; }
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--accent-soft); }
input:invalid:not(:placeholder-shown) { border-color: var(--danger); }
textarea { resize: vertical; min-height: 88px; }
.hint { font-size: 12.5px; color: var(--ink-3); }
.err { font-size: 12.5px; color: var(--danger); font-weight: 600; }

/* ---------- KPI ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 17px 19px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset-block-start: 0; inset-inline: 0; height: 3px; background: var(--k, var(--accent)); }
.kpi .label { font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.025em; margin-top: 2px; font-variant-numeric: tabular-nums; color: var(--k, var(--ink)); }
.kpi .foot { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }

/* ---------- แถบความคืบหน้า ---------- */
.bar { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s cubic-bezier(.2,.8,.2,1); }

/* ---------- helper layout ---------- */
.grid { display: grid; gap: 18px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }

/* ⚠️ สำคัญ: ลูกของ grid/flex ตั้งต้นเป็น min-width:auto จึงไม่ยอมหดต่ำกว่าเนื้อหา
   ทำให้ตารางกว้าง ๆ ดันทั้งหน้าจนล้นแนวนอนบนมือถือ — บังคับให้หดได้ */
.grid > *, .stack > *, .two > *, .kpis > *, .card > * { min-width: 0; }
.grid, .stack, .two, .kpis, .card { min-width: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.sep { height: 1px; background: var(--border); border: 0; margin: 18px 0; }
.center { text-align: center; }
.pull-end { margin-inline-start: auto; }

/* ---------- หัวหน้าแอป (เว็บระบบสาธิต) ---------- */
.app-head { padding: 28px 0 34px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2, var(--violet))); position: relative; overflow: hidden; }
.app-head::after {
  content: ""; position: absolute; inset-block-start: -60%; inset-inline-end: -8%;
  width: 420px; height: 420px; border-radius: 50%; background: rgba(255, 255, 255, .13);
}
.app-head .inner { position: relative; z-index: 1; }
.app-head h1 { font-size: clamp(21px, 3.4vw, 28px); color: #fff; }
.app-head p { color: rgba(255, 255, 255, .88); font-size: 14.5px; margin-top: 6px; max-width: 64ch; }
.app-head .eyebrow {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 12px; border-radius: 99px;
  background: rgba(255, 255, 255, .2); font-size: 12px; font-weight: 600; letter-spacing: .04em;
  color: #fff; margin-bottom: 10px;
}
.app-body { padding: 24px 0 64px; }

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; overflow-x: auto; box-shadow: var(--shadow); }
.tabs button {
  flex: 1 0 auto; padding: 9px 16px; border: 0; background: transparent; border-radius: 9px;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }
.tabs button[aria-selected="true"]:hover { background: var(--accent); }
.panel[hidden] { display: none; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(28, 36, 64, .45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 150;
}
.modal-back[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 88vh; overflow: auto; animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }

/* ---------- toast ---------- */
#toast-host { position: fixed; inset-block-end: 22px; inset-inline: 0; display: grid; justify-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .25s ease; max-width: min(92vw, 470px);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- ท้ายเว็บ (โทนสว่าง) ---------- */
.site-foot {
  background: linear-gradient(180deg, #fff, var(--brand-soft));
  border-top: 1px solid var(--border);
  color: var(--ink-2); padding: 40px 0 28px; font-size: 13.5px; margin-top: 40px;
}
.site-foot a { color: var(--brand); }
.site-foot .cols { display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.site-foot h4 { color: var(--ink); font-size: 14px; margin-bottom: 9px; }
.site-foot ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

@media print { .demo-bar, .site-head, .site-foot, .no-print { display: none !important; } }
