/*
 * @suphark/ui/styles.css — token + ฟอนต์ + base ของ design system (Tailwind v4, shadcn base-nova, baseColor slate)
 *
 * แอปเป็นคน @import "tailwindcss" เอง แล้ว import ไฟล์นี้ต่อ พร้อม @source ให้ Tailwind สแกน class ในแพ็กเกจ:
 *
 *   @import "tailwindcss";
 *   @import "@suphark/ui/styles.css";
 *   @source "../../node_modules/@suphark/ui/src";
 *
 * ฟอนต์: Noto Sans Thai Looped (@fontsource) โหลดที่นี่ — แอปที่ต้องการฟอนต์อื่น override --font-sans ใน @theme ของตัวเอง
 * ส่วน print/A4 และสไตล์เฉพาะ feature ของ supplychain ไม่ได้ยกมา (อยู่ที่แอปนั้น)
 *
 * Override contract (ดู docs/agent-rules.md):
 *   แอปแก้ได้: --brand / --brand-foreground (บน wrapper), --font-sans / --font-mono, --radius
 *   ห้ามแก้: semantic token (--primary --background --muted --destructive …), --sidebar-*, --chart-*, วิธีสลับธีม
 */
@import "tw-animate-css";
@import "@fontsource/noto-sans-thai-looped/400.css";
@import "@fontsource/noto-sans-thai-looped/500.css";
@import "@fontsource/noto-sans-thai-looped/700.css";
/* ชุดสีป้ายกำกับ 20 สี (label-*) — สร้างจาก scripts/gen-palette.mjs */
@import "./palette.css";

@custom-variant dark (&:is(.dark *));

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --font-sans: "Noto Sans Thai Looped", Tahoma, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  --color-sidebar-ring: var(--sidebar-ring);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar: var(--sidebar);
  --color-chart-5: var(--chart-5);
  --color-chart-4: var(--chart-4);
  --color-chart-3: var(--chart-3);
  --color-chart-2: var(--chart-2);
  --color-chart-1: var(--chart-1);
  --color-ring: var(--ring);
  --color-input: var(--input);
  --color-border: var(--border);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
  --color-warning-muted-foreground: var(--warning-muted-foreground);
  --color-info: var(--info);
  --color-info-foreground: var(--info-foreground);
  /* พื้นอ่อน/ตัวอักษร/เส้นขอบของโทน (Notice, StatusBadge, callout ของแอป) — bg-info-subtle text-info-subtle-foreground border-info-border */
  --color-info-subtle: var(--info-subtle);
  --color-info-subtle-foreground: var(--info-subtle-foreground);
  --color-info-border: var(--info-border);
  --color-success-subtle: var(--success-subtle);
  --color-success-subtle-foreground: var(--success-subtle-foreground);
  --color-success-border: var(--success-border);
  --color-warning-subtle: var(--warning-subtle);
  --color-warning-subtle-foreground: var(--warning-subtle-foreground);
  --color-warning-border: var(--warning-border);
  --color-destructive-subtle: var(--destructive-subtle);
  --color-destructive-subtle-foreground: var(--destructive-subtle-foreground);
  --color-destructive-border: var(--destructive-border);
  --color-accent-foreground: var(--accent-foreground);
  --color-accent: var(--accent);
  --color-muted-foreground: var(--muted-foreground);
  --color-muted: var(--muted);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-secondary: var(--secondary);
  --color-primary-foreground: var(--primary-foreground);
  --color-primary: var(--primary);
  --color-popover-foreground: var(--popover-foreground);
  --color-popover: var(--popover);
  --color-card-foreground: var(--card-foreground);
  --color-card: var(--card);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
}

/*
 * Typography by role, not by t-shirt size.
 *
 * Each token points at a `--fs-*` variable rather than a literal, so the value
 * can change per breakpoint while the generated utility stays one class
 * (`text-body`, and its variants such as `md:text-body`, keep working).
 * Values below are mobile-first and get *denser* on wide screens: a phone is
 * held further away and tapped, a desktop is read up close with a mouse — the
 * same reason iOS uses a 17px body where macOS uses 13px.
 *
 * Apps should reach for these roles instead of `text-xs`/`text-sm`, which
 * carry no meaning and cannot respond to the viewport.
 */
@theme {
  /* ตัวเล็กกว่า text-xs (10px) สำหรับป้ายนับ/ตัวกำกับแน่น ๆ — ค่าเดียวกับ supplychain (ไม่ใช่บทบาท ใช้เท่าที่จำเป็น) */
  --text-2xs: 0.625rem;
  --text-2xs--line-height: 0.875rem;
  --text-title-lg: var(--fs-title-lg);
  --text-title-lg--line-height: var(--lh-title-lg);
  --text-title: var(--fs-title);
  --text-title--line-height: var(--lh-title);
  --text-subtitle: var(--fs-subtitle);
  --text-subtitle--line-height: var(--lh-subtitle);
  --text-body: var(--fs-body);
  --text-body--line-height: var(--lh-body);
  --text-caption: var(--fs-caption);
  --text-caption--line-height: var(--lh-caption);
  --text-label: var(--fs-label);
  --text-label--line-height: var(--lh-label);
}

:root {
  /* Phones and small tablets. */
  --fs-title-lg: 1.5rem; /* 24px */
  --lh-title-lg: 1.25;
  --fs-title: 1.125rem; /* 18px */
  --lh-title: 1.3;
  --fs-subtitle: 1.0625rem; /* 17px */
  --lh-subtitle: 1.4;
  --fs-body: 1rem; /* 16px */
  --lh-body: 1.45;
  --fs-caption: 0.875rem; /* 14px */
  --lh-caption: 1.4;
  --fs-label: 0.75rem; /* 12px */
  --lh-label: 1.35;
}

@media (width >= 48rem) {
  :root {
    --fs-subtitle: 1rem; /* 16px */
    --fs-body: 0.9375rem; /* 15px */
    --fs-caption: 0.8125rem; /* 13px */
  }
}

:root {
  --radius: 0.625rem;
  --background: oklch(1 0 0);
  --foreground: oklch(0.129 0.042 264.695);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.129 0.042 264.695);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.129 0.042 264.695);
  --primary: oklch(0.208 0.042 265.755);
  --primary-foreground: oklch(0.984 0.003 247.858);
  --secondary: oklch(0.968 0.007 247.896);
  --secondary-foreground: oklch(0.208 0.042 265.755);
  --muted: oklch(0.968 0.007 247.896);
  /* 0.554 → 0.52: บนพื้น --muted (แท็บ, ป้ายนับ, ช่อง disabled) เดิมได้ 4.35:1 ไม่ผ่าน AA → 5.02:1 (บนขาว 5.4:1) */
  --muted-foreground: oklch(0.52 0.046 257.417);
  --accent: oklch(0.968 0.007 247.896);
  --accent-foreground: oklch(0.208 0.042 265.755);
  /* L 0.577 → 0.535: ตัวหนังสือบนพื้นจาง bg-destructive/10 (ปุ่ม/ป้ายโทนลบ) 3.99 → 4.61:1, บนพื้นขาว 5.53:1 */
  --destructive: oklch(0.535 0.235 27.325);
  /* ตัวหนังสือบนพื้น --destructive (ป้ายนับแจ้งเตือน) — ขาว 4.76:1 */
  --destructive-foreground: oklch(1 0 0);
  --success: oklch(0.527 0.154 150.069);
  --success-foreground: oklch(0.985 0.002 247.839);
  --warning: oklch(0.852 0.199 91.936);
  --warning-foreground: oklch(0.286 0.066 53.813);
  --warning-muted-foreground: oklch(0.421 0.095 57.708);
  /* โทน: ค่าเท่า Tailwind sky/emerald/amber/red ที่ Notice/StatusBadge เคยใช้ตรง ๆ (50 พื้น · 200 ขอบ · 800 ตัวอักษร) */
  /* 0.588 → 0.53: `text-info` บนขาวเดิม 4.02:1 ไม่ผ่าน AA → 5.05:1 (ตัวหนังสือขาวบน bg-info ก็ผ่านเท่ากัน) */
  --info: oklch(0.53 0.158 241.966);
  --info-foreground: oklch(0.984 0.003 247.858);
  --info-subtle: oklch(0.977 0.013 236.62);
  --info-subtle-foreground: oklch(0.443 0.11 240.79);
  --info-border: oklch(0.901 0.058 230.902);
  --success-subtle: oklch(0.979 0.021 166.113);
  --success-subtle-foreground: oklch(0.432 0.095 166.913);
  --success-border: oklch(0.905 0.093 164.15);
  --warning-subtle: oklch(0.987 0.022 95.277);
  --warning-subtle-foreground: oklch(0.473 0.137 46.201);
  --warning-border: oklch(0.924 0.12 95.746);
  --destructive-subtle: oklch(0.971 0.013 17.38);
  --destructive-subtle-foreground: oklch(0.444 0.177 26.899);
  --destructive-border: oklch(0.885 0.062 18.334);
  /* ปุ่มโทน (`Button tone=`) — ตัวอักษร/ขอบ/พื้นตอน hover ของแต่ละโทน · แอป override เป็นสีประเภทรายการของตัวเองได้
     ตัวอักษร = subtle-foreground ของตระกูลเดียวกัน (วัดแล้ว ≥ 7:1 ทั้งสองธีม) · ขอบ ≥ 3:1 กับพื้น (non-text contrast) */
  --tone-income: var(--success-subtle-foreground);
  --tone-income-border: oklch(0.64 0.1 165);
  --tone-income-hover: var(--success-subtle);
  --tone-expense: var(--destructive-subtle-foreground);
  --tone-expense-border: oklch(0.64 0.13 18);
  --tone-expense-hover: var(--destructive-subtle);
  --tone-reminder: oklch(0.45 0.15 300);
  --tone-reminder-border: oklch(0.62 0.12 300);
  --tone-reminder-hover: oklch(0.97 0.02 300);
  --tone-warning: var(--warning-subtle-foreground);
  --tone-warning-border: oklch(0.66 0.13 70);
  --tone-warning-hover: var(--warning-subtle);
  --border: oklch(0.929 0.013 255.508);
  --input: oklch(0.929 0.013 255.508);
  /* L 0.704 → 0.554 (slate-500): ขอบโฟกัส (focus-visible:border-ring) บนพื้นขาว 2.63 → 4.77:1 — ต้อง ≥ 3:1 (WCAG 1.4.11) */
  --ring: oklch(0.554 0.046 257.417);
  --chart-1: oklch(0.646 0.222 41.116);
  --chart-2: oklch(0.6 0.118 184.704);
  --chart-3: oklch(0.398 0.07 227.392);
  --chart-4: oklch(0.828 0.189 84.429);
  --chart-5: oklch(0.769 0.188 70.08);
  --sidebar: oklch(0.984 0.003 247.858);
  --sidebar-foreground: oklch(0.129 0.042 264.695);
  --sidebar-primary: oklch(0.208 0.042 265.755);
  --sidebar-primary-foreground: oklch(0.984 0.003 247.858);
  --sidebar-accent: oklch(0.968 0.007 247.896);
  --sidebar-accent-foreground: oklch(0.208 0.042 265.755);
  --sidebar-border: oklch(0.929 0.013 255.508);
  --sidebar-ring: oklch(0.554 0.046 257.417);
  --scrollbar-thumb: rgba(0, 0, 0, 0.1);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.2);
}

.dark {
  --background: oklch(0.129 0.042 264.695);
  --foreground: oklch(0.984 0.003 247.858);
  --card: oklch(0.208 0.042 265.755);
  --card-foreground: oklch(0.984 0.003 247.858);
  --popover: oklch(0.208 0.042 265.755);
  --popover-foreground: oklch(0.984 0.003 247.858);
  --primary: oklch(0.929 0.013 255.508);
  --primary-foreground: oklch(0.208 0.042 265.755);
  --secondary: oklch(0.279 0.041 260.031);
  --secondary-foreground: oklch(0.984 0.003 247.858);
  --muted: oklch(0.279 0.041 260.031);
  --muted-foreground: oklch(0.704 0.04 256.788);
  --accent: oklch(0.279 0.041 260.031);
  --accent-foreground: oklch(0.984 0.003 247.858);
  --destructive: oklch(0.704 0.191 22.216);
  /* ขาวบน --destructive ธีมมืด = 2.89:1 ไม่ผ่าน — ใช้สีพื้นหลังมืดเป็นตัวหนังสือ = 6.97:1
     (ไม่ลดความสว่างของ --destructive เพราะ text-destructive บนพื้นมืดจะไม่ผ่านแทน) */
  --destructive-foreground: oklch(0.129 0.042 264.695);
  --success: oklch(0.627 0.194 149.214);
  --success-foreground: oklch(0.145 0.028 147.727);
  --warning: oklch(0.852 0.199 91.936);
  --warning-foreground: oklch(0.286 0.066 53.813);
  --warning-muted-foreground: oklch(0.905 0.182 98.111);
  /* dark: 950 พื้น · 900 ขอบ · 200 ตัวอักษร · info ทึบ = sky-400 */
  --info: oklch(0.746 0.16 232.661);
  --info-foreground: oklch(0.293 0.066 243.157);
  --info-subtle: oklch(0.293 0.066 243.157);
  --info-subtle-foreground: oklch(0.901 0.058 230.902);
  --info-border: oklch(0.391 0.09 240.876);
  --success-subtle: oklch(0.262 0.051 172.552);
  --success-subtle-foreground: oklch(0.905 0.093 164.15);
  --success-border: oklch(0.378 0.077 168.94);
  --warning-subtle: oklch(0.279 0.077 45.635);
  --warning-subtle-foreground: oklch(0.924 0.12 95.746);
  --warning-border: oklch(0.414 0.112 45.904);
  --destructive-subtle: oklch(0.258 0.092 26.042);
  --destructive-subtle-foreground: oklch(0.885 0.062 18.334);
  --destructive-border: oklch(0.396 0.141 25.723);
  --tone-income: var(--success-subtle-foreground);
  --tone-income-border: oklch(0.52 0.09 165);
  --tone-income-hover: var(--success-subtle);
  --tone-expense: var(--destructive-subtle-foreground);
  --tone-expense-border: oklch(0.52 0.12 20);
  --tone-expense-hover: var(--destructive-subtle);
  --tone-reminder: oklch(0.85 0.07 300);
  --tone-reminder-border: oklch(0.52 0.12 300);
  --tone-reminder-hover: oklch(0.28 0.07 300);
  --tone-warning: var(--warning-subtle-foreground);
  --tone-warning-border: oklch(0.55 0.11 60);
  --tone-warning-hover: var(--warning-subtle);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.551 0.027 264.364);
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);
  --sidebar: oklch(0.208 0.042 265.755);
  --sidebar-foreground: oklch(0.984 0.003 247.858);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.984 0.003 247.858);
  --sidebar-accent: oklch(0.279 0.041 260.031);
  --sidebar-accent-foreground: oklch(0.984 0.003 247.858);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.551 0.027 264.364);
  --scrollbar-thumb: rgba(255, 255, 255, 0.1);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
}

/*
 * สีแบรนด์ต่อ tenant/แอป (จาก Pi Auth) — ตั้ง --brand / --brand-foreground inline บน wrapper
 * (<div style="--brand: oklch(...); --brand-foreground: ...">) แล้ว primary / ring / sidebar-primary ในนั้นตามไปด้วย
 * ต้องเป็น rule บน wrapper ไม่ใช่ --primary: var(--brand) ที่ :root — เพราะ custom property ถูกคำนวณที่จุดประกาศ
 * แล้วลูกสืบทอด "ค่าที่คำนวณแล้ว" การตั้ง --brand ใหม่ที่ลูกจึงไม่เปลี่ยน --primary (บั๊ก @pi/ui 4cd39d8)
 * ค่าเริ่มต้นของแพ็กเกจไม่ตั้ง --brand → primary เป็น slate ตามต้นทาง supplychain
 */
[style*="--brand"],
[data-brand] {
  --primary: var(--brand);
  /* ไม่ได้ตั้ง --brand-foreground = ตัวหนังสือขาวแบบ primary เดิม (ไม่มี fallback = ค่าใช้ไม่ได้ → สืบทอดสีเข้มจากแม่) */
  --primary-foreground: var(--brand-foreground, oklch(0.984 0.003 247.858));
  --ring: var(--brand);
  --sidebar-primary: var(--brand);
  --sidebar-primary-foreground: var(--brand-foreground, oklch(0.984 0.003 247.858));
  --sidebar-ring: var(--brand);
}

/*
 * โหมดมืด (0.95.0): สีแบรนด์ที่เข้มพอบนพื้นขาวมักจางเกินบนพื้นมืด (ลิงก์ text-primary 3.1:1, A7)
 * ตั้ง --brand-dark (+ --brand-dark-foreground) เพิ่มได้ — ไม่ตั้ง = ใช้ --brand เดิม
 * วางที่ <body> แทน wrapper ได้ เมนู/dialog/sheet ที่ portal ไปท้าย body จะได้สีแบรนด์ด้วย (S6)
 */
.dark [style*="--brand"],
.dark[style*="--brand"],
.dark [data-brand],
.dark[data-brand] {
  --primary: var(--brand-dark, var(--brand));
  --primary-foreground: var(
    --brand-dark-foreground,
    var(--brand-foreground, oklch(0.984 0.003 247.858))
  );
  --ring: var(--brand-dark, var(--brand));
  --sidebar-primary: var(--brand-dark, var(--brand));
  --sidebar-primary-foreground: var(
    --brand-dark-foreground,
    var(--brand-foreground, oklch(0.984 0.003 247.858))
  );
  --sidebar-ring: var(--brand-dark, var(--brand));
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background font-sans text-foreground;
  }
}

@utility no-scrollbar {
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
  &::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
  }
}

/* ขอบล่างของจอ iPhone (home indicator) — แถบที่ fixed ติดล่าง เช่น MobileTabBar */
@utility pb-safe {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ความสูงของ MobileTabBar (ไม่รวม safe-area) — มีแถบแท็บในหน้า (จอ < md) = 4rem ให้ `AppToaster` ยก toast พ้นแถบ */
@media (width < 48rem) {
  :root:has([data-slot="mobile-tab-bar"]) {
    --tab-bar-height: 4rem;
  }
}

/* แถบปุ่มล่างของ DocumentHeader (`stickyActionsOnMobile`, จอ < md): เว้นที่ท้ายหน้าไม่ให้บังเนื้อหาสุดท้าย
   และยกขึ้นเหนือ MobileTabBar เมื่อหน้ามีแถบแท็บ */
@media (width < 48rem) {
  :root:has([data-slot="document-action-bar"]) body {
    padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
  }
  :root:has([data-slot="mobile-tab-bar"]) [data-slot="document-action-bar"] {
    bottom: calc(var(--tab-bar-height, 4rem) + env(safe-area-inset-bottom, 0px));
    padding-bottom: 0.5rem;
  }
}

/* เว้นที่ใต้เนื้อหาให้พ้น MobileTabBar (สูง ~4rem + safe-area) — AppShell mobileTabs ใส่ให้เอง */
@utility pb-tab-bar {
  padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
}

@utility scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Global scrollbar styling — อยู่ใน @layer base ให้ utility (no-scrollbar, scrollbar-thin, className ของแอป) ชนะได้
   (เดิมไม่มี layer → `*{scrollbar-width:thin}` ทับ no-scrollbar ทุกที่ เช่นคอลัมน์ TimePicker แถบแท็บ) */
@layer base {
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 9999px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
  }

  * {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
  }
}

html,
body,
.font-sans {
  font-family: var(--font-sans);
}

/*
 * CommandItem ที่ active (ลูกศร/hover) มองไม่ออก: shadcn ใช้ `data-selected:bg-muted` แต่ Tailwind `data-selected:`
 * = `[data-selected]` (มีแอตทริบิวต์) ขณะที่ cmdk ใส่ `data-selected="false"` ให้รายการอื่นด้วย → ทุกแถวได้ bg-muted
 * เท่ากัน (รายงานจาก Pi Done ใน dark mode) → เน้นเฉพาะ "true" โดยผสม foreground; override ที่นี่แบบไม่อยู่ใน layer
 * จึงชนะ utility โดยไม่แก้ command.tsx ของ shadcn
 */
[data-slot="command-item"][data-selected="true"] {
  background-color: color-mix(in oklch, var(--muted), var(--foreground) 8%);
}
.dark [data-slot="command-item"][data-selected="true"] {
  background-color: color-mix(in oklch, var(--muted), var(--foreground) 14%);
}

/*
 * AppToaster `richColors` — สีโทนของแพ็กเกจ (พื้น `*-subtle` + ตัวหนังสือ `*-subtle-foreground` ผ่าน AA ทั้งสองธีม)
 * แทนสีตั้งต้นของ sonner (toast สำเร็จธีมสว่าง 4.26:1) · sonner ใส่ CSS ของตัวเองท้าย <head> ที่
 * `[data-sonner-toaster][data-sonner-theme='light']` (0,2,0) → ที่นี่ใช้ (0,3,0) ไม่อยู่ใน layer จึงชนะ
 * · ปรับสีเองได้โดยไม่ต้องสู้ specificity: ตั้ง `--toast-success-bg` / `-text` / `-border` (และ info/warning/error)
 *   ที่ `:root` หรือ container ใดก็ได้ (0.116.0 — เดิมเป็น inline style ที่ทับ CSS ของแอปทุกตัว)
 * · `--success-border` ฯลฯ ชื่อชนกับ token ของแพ็กเกจ อ้างตัวเองบน element เดียวกันไม่ได้ → section ที่ครอบ toaster
 *   (parent โดยตรง) เก็บค่าของ token ไว้ก่อน — คำนวณจากธีม/แบรนด์ที่ครอบ toaster อยู่จริง ไม่ใช่จาก :root
 */
section:has(> [data-sonner-toaster].app-toaster) {
  --app-toast-success-border: var(--success-border);
  --app-toast-info-border: var(--info-border);
  --app-toast-warning-border: var(--warning-border);
}
[data-sonner-toaster][data-sonner-theme].app-toaster {
  --success-bg: var(--toast-success-bg, var(--success-subtle));
  --success-text: var(--toast-success-text, var(--success-subtle-foreground));
  --success-border: var(--toast-success-border, var(--app-toast-success-border));
  --info-bg: var(--toast-info-bg, var(--info-subtle));
  --info-text: var(--toast-info-text, var(--info-subtle-foreground));
  --info-border: var(--toast-info-border, var(--app-toast-info-border));
  --warning-bg: var(--toast-warning-bg, var(--warning-subtle));
  --warning-text: var(--toast-warning-text, var(--warning-subtle-foreground));
  --warning-border: var(--toast-warning-border, var(--app-toast-warning-border));
  --error-bg: var(--toast-error-bg, var(--destructive-subtle));
  --error-text: var(--toast-error-text, var(--destructive-subtle-foreground));
  --error-border: var(--toast-error-border, var(--destructive-border));
}

/*
 * ปุ่มโทนลบ (`variant="destructive"` = พื้นจาง bg-destructive/10 + text-destructive) บนพื้นโทนแดงอ่อน: พื้นสองชั้นซ้อนกัน
 * ตัวหนังสือเหลือ ~4.46:1 (ไม่ผ่าน AA) → ใน container ที่ประกาศ `data-surface="destructive"` ใช้ `--destructive-subtle-foreground`
 * (สว่าง 6.70:1, มืด 9.88:1) · DangerZone และ Notice tone="danger" ประกาศให้เอง · แอปใส่ attribute นี้ให้ container
 * พื้นแดงของตัวเองได้ (0.116.0 — เดิมแก้เฉพาะใน DangerZone)
 */
[data-surface="destructive"] [data-slot="button"].text-destructive {
  color: var(--destructive-subtle-foreground);
}

/*
 * นิ้วไม่ใช่เมาส์: รายการในเมนู/ดรอปดาวน์ไม่ได้ตั้งความสูงไว้เลย (`py-1` ≈ 26px) ซึ่งต่ำกว่าเกณฑ์
 * Apple 44pt / Material 48dp มาก บนอุปกรณ์สัมผัสจึงยกพื้นความสูงให้ — ใช้ `pointer: coarse`
 * (คือ "นิ้ว") ไม่ใช่ความกว้างจอ เพราะหน้าต่างแคบบนเดสก์ท็อปยังชี้ด้วยเมาส์อยู่
 * override ที่นี่แบบไม่อยู่ใน layer จึงชนะ utility โดยไม่แก้ component ของ shadcn
 */
@media (pointer: coarse) {
  [data-slot="dropdown-menu-item"],
  [data-slot="dropdown-menu-checkbox-item"],
  [data-slot="dropdown-menu-radio-item"],
  [data-slot="dropdown-menu-sub-trigger"],
  [data-slot="select-item"],
  [data-slot="command-item"] {
    min-height: 2.75rem; /* 44px */
  }
}

/*
 * ตัวควบคุมทั้งชุด (0.68.0): ปุ่ม/ช่องกรอก/ตัวเลือก/แท็บ สูงเดิม 24–32px — สแกนทุกหน้าเดโมบนจอสัมผัสเจอ ~480 จุดที่ต่ำกว่า 44px
 * จึงยกพื้นให้เป็น 44px เฉพาะ `pointer: coarse` (เดสก์ท็อป/เมาส์ไม่เปลี่ยนเลย)
 * ปิดเป็นรายตัวด้วย `data-touch="compact"` (เช่นแถบเครื่องมือหนาแน่นที่แอปรับผิดชอบพื้นที่แตะเอง)
 * ปุ่มที่อยู่ใน InputGroup ไม่ยก (กลุ่มสูง 44px อยู่แล้ว); `:where` ทำให้ความจำเพาะต่ำ ยังทับด้วย `min-h-0` ของแอปได้
 */
@media (pointer: coarse) {
  :where(
    [data-slot="button"],
    [class~="group/button"],
    [data-slot="toggle"],
    [data-slot="toggle-group-item"],
    [data-slot="tabs-trigger"],
    [data-slot="menubar-trigger"],
    [data-slot="sidebar-menu-button"],
    [data-slot="input"],
    [data-slot="select-trigger"],
    [data-slot="native-select"],
    [data-slot="number-input"],
    [data-slot="input-group"],
    [class~="group/input-group"]
  ):not([data-touch="compact"], [class~="group/input-group"] *) {
    min-height: 2.75rem;
  }
  /* ปุ่ม/สลับแบบไอคอนล้วนต้องกว้าง 44px ด้วย */
  :where([data-slot="button"], [class~="group/button"], [data-slot="toggle"]):has(
    > svg:only-child
  ):not([data-touch="compact"], [class~="group/input-group"] *) {
    min-width: 2.75rem;
  }
  /* ปุ่มลด/เพิ่มของ NumberInput และปุ่มก่อนหน้า/ถัดไปของ Carousel (ไอคอน + ข้อความ sr-only จึงไม่เข้ากฎข้างบน) */
  :where(
    [data-slot="number-input"] > button,
    [data-slot="carousel-previous"],
    [data-slot="carousel-next"]
  ):not([data-touch="compact"]) {
    min-width: 2.75rem;
  }
  /* ในกลุ่ม (สูง 44px): ช่องพิมพ์และปุ่มไอคอนข้างในเต็มความสูงของกลุ่ม (ลบกรอบ 1px สองข้าง = 42px) */
  :where([data-slot="input-group"], [class~="group/input-group"]):not([data-touch="compact"])
  :where([data-slot="input-group-control"]) {
    min-height: 2.625rem;
  }
  :where([data-slot="input-group"], [class~="group/input-group"]):not([data-touch="compact"])
    :where([data-slot="button"], [class~="group/button"]) {
    min-height: 2.625rem;
    min-width: 2.625rem;
  }
  :where([data-slot="tabs-list"]):not([data-touch="compact"]) {
    min-height: 2.75rem;
  }
  /* ปฏิทินวันที่ (react-day-picker): ช่องวัน 28px → 44px (7 ช่อง = 308px + padding ยังพอดีจอ 360px) */
  [data-slot="calendar"]:not([data-touch="compact"]) {
    --cell-size: 2.75rem;
  }
  /* ช่องติ๊ก/วิทยุ/สวิตช์: ภาพเล็กเหมือนเดิม ขยายแค่พื้นที่แตะรอบ ๆ (ตัว ::after ที่ shadcn วางไว้อยู่แล้ว) */
  :where([data-slot="checkbox"], [data-slot="radio-group-item"], [data-slot="switch"]):not(
    [data-touch="compact"]
  )::after {
    inset: -0.875rem;
  }
}

/* ผู้ใช้ตั้ง "ลดการเคลื่อนไหว" → ตัด animation/transition ของทุก component (tw-animate, animate-spin, dialog zoom …) */
@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* `Prose` — เนื้อหาแบบยาว ไม่พึ่ง @tailwindcss/typography · `not-prose` = ไม่รับสไตล์นี้
   :where ให้ความเฉพาะเป็นศูนย์ utility ของแอปทับได้เสมอ · หัวข้อใช้ em ย่อทั้งก้อนด้วย text-sm ได้ */
@layer components {
  .ui-prose {
    font-size: var(--fs-body);
    line-height: 1.7;
    color: var(--foreground);
  }
  :where(.ui-prose) > :where(* + *) {
    margin-top: 1em;
  }
  :where(.ui-prose)
    :where(p, ul, ol, h1, h2, h3, h4, blockquote):not(:where(.not-prose, .not-prose *)) {
    max-width: 68ch;
  }
  :where(.ui-prose) :where(h1, h2, h3, h4):not(:where(.not-prose, .not-prose *)) {
    font-weight: 600;
    line-height: 1.35;
    scroll-margin-top: 5rem;
    text-wrap: balance;
  }
  :where(.ui-prose) :where(h1):not(:where(.not-prose, .not-prose *)) {
    font-size: 1.75em;
  }
  :where(.ui-prose) :where(h2):not(:where(.not-prose, .not-prose *)) {
    margin-top: 2.25em;
    font-size: 1.35em;
  }
  :where(.ui-prose) :where(h3):not(:where(.not-prose, .not-prose *)) {
    margin-top: 1.75em;
    font-size: 1.125em;
  }
  :where(.ui-prose) :where(h4):not(:where(.not-prose, .not-prose *)) {
    margin-top: 1.5em;
    font-size: 1em;
  }
  :where(.ui-prose) > :where(:first-child) {
    margin-top: 0;
  }
  :where(.ui-prose) :where(p.lead):not(:where(.not-prose, .not-prose *)) {
    font-size: 1.125em;
    color: var(--muted-foreground);
  }
  :where(.ui-prose) :where(a):not(:where(.not-prose, .not-prose *)) {
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-color: color-mix(in oklab, var(--muted-foreground) 60%, transparent);
  }
  :where(.ui-prose) :where(a:hover):not(:where(.not-prose, .not-prose *)) {
    text-decoration-color: currentColor;
  }
  :where(.ui-prose) :where(ul, ol):not(:where(.not-prose, .not-prose *)) {
    padding-inline-start: 1.4em;
  }
  :where(.ui-prose) :where(ul):not(:where(.not-prose, .not-prose *)) {
    list-style: disc;
  }
  :where(.ui-prose) :where(ol):not(:where(.not-prose, .not-prose *)) {
    list-style: decimal;
  }
  :where(.ui-prose) :where(li + li, li > ul, li > ol):not(:where(.not-prose, .not-prose *)) {
    margin-top: 0.35em;
  }
  :where(.ui-prose) :where(strong):not(:where(.not-prose, .not-prose *)) {
    font-weight: 600;
  }
  :where(.ui-prose) :where(blockquote):not(:where(.not-prose, .not-prose *)) {
    border-inline-start: 3px solid var(--border);
    padding-inline-start: 1em;
    color: var(--muted-foreground);
  }
  :where(.ui-prose) :where(hr):not(:where(.not-prose, .not-prose *)) {
    margin-block: 2em;
    border-color: var(--border);
  }
  :where(.ui-prose) :where(code):not(:where(pre code, .not-prose, .not-prose *)) {
    padding: 0.1em 0.35em;
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    background: var(--muted);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.85em;
    /* ชื่อยาวไม่มีช่องว่าง (เช่น A/B/C, prop={…}) ตัดบรรทัดได้ — มือถือไม่ล้นหน้า */
    overflow-wrap: anywhere;
  }
  :where(.ui-prose) :where(pre):not(:where(.not-prose, .not-prose *)) {
    overflow-x: auto;
    padding: 0.75em 1em;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--muted);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.85em;
    line-height: 1.6;
  }
  :where(.ui-prose) :where(table):not(:where(.not-prose, .not-prose *)) {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375em;
  }
  :where(.ui-prose) :where(th, td):not(:where(.not-prose, .not-prose *)) {
    padding: 0.45em 0.75em;
    border: 1px solid var(--border);
    text-align: start;
    vertical-align: top;
  }
  :where(.ui-prose) :where(th):not(:where(.not-prose, .not-prose *)) {
    background: var(--muted);
    font-weight: 600;
  }
  :where(.ui-prose) :where(img, video):not(:where(.not-prose, .not-prose *)) {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
  }
  /* `Markdown` (@suphark/ui/markdown): ตารางกว้างเลื่อนในกรอบ (มือถือไม่ล้นหน้า) · หัวข้อเป็นลิงก์ #id สีเดียวกับหัวข้อ */
  :where([data-markdown-table]) {
    overflow-x: auto;
    border-radius: var(--radius);
    outline: none;
  }
  :where([data-markdown-table]:focus-visible) {
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 50%, transparent);
  }
  :where([data-markdown-table]) > :where(table) {
    min-width: 36rem;
  }
  :where(.ui-prose) :where(a[data-heading-anchor]) {
    font-weight: inherit;
    color: inherit;
    text-decoration: none;
  }
  :where(.ui-prose) :where(a[data-heading-anchor]:hover) {
    text-decoration: underline;
    text-decoration-color: var(--muted-foreground);
  }
  :where([data-slot="markdown"]) :where(h1, h2, h3, h4) {
    scroll-margin-top: calc(var(--app-header-height, 3.5rem) + 1rem);
  }
}
