/*
 * Sunstrike — stylesheet เดียวของหน้าเว็บ (เขียนมือ ไม่ใช้ Tailwind/ตัวแปลงใด ๆ)
 *
 * สารบัญ (ค้นหาด้วย "== ชื่อ ==")
 *   1. tokens        ตัวแปรสีและขนาด: :root = โหมดมืด (ค่าเริ่มต้น) · :root[data-theme='light'] = โหมดสว่าง
 *   2. base          reset (เทียบเท่า Tailwind preflight) + พื้นฐานของ body/focus
 *   3. components    ปุ่ม ป้าย การ์ด ช่องกรอก select checkbox switch segmented skeleton ตาราง dialog เมนู toast แท็ก แบ่งหน้า สถานะ หัวข้อหน้า
 *   4. layout        โครงหน้า (sidebar, topbar, drawer) และหน้า login
 *   5. utilities     คลาสช่วยสั้น ๆ (ชื่อเหมือน Tailwind: flex, gap-3, grid-cols-2, sm:hidden …) — เฉพาะที่ใช้จริง ดูรายการที่ README
 *
 * กติกา: ห้ามใส่สี hardcode (hex/rgb/hsl) นอกบล็อก :root — ใช้ var(--ชื่อ) หรือ color-mix(in srgb, var(--ชื่อ) N%, transparent) เสมอ (test/theme.spec.js ตรวจ)
 * CSS เฉพาะหน้า: ทำไฟล์ public/css/pages/<หน้า>.css แล้วใส่ <link> ในหน้านั้น (อย่าแก้ไฟล์นี้เพื่อสไตล์ที่ใช้หน้าเดียว)
 * จุดตัด responsive เหมือน Tailwind: sm 640px · md 768px · lg 1024px · xl 1280px
 */

/* == tokens == */
/*
 * ธีม Sunstrike"sunset horizon": พื้นเข้มอุ่น (ค่าเริ่มต้น) หรือพื้นสว่างอุ่น + ส้มเป็นสีเน้น
 * เปลี่ยนสีทั้งระบบได้ที่ไฟล์นี้ไฟล์เดียว — คอมโพเนนต์ทั้งหมดอ้างตัวแปรเชิงความหมาย (--primary, --card …) ไม่มีสี hardcode
 *
 *   :root                       = สีแบรนด์ (--sun-*, --ember-900, --night) + โหมดมืด (ค่าเริ่มต้น)
 *   :root[data-theme='light']   = โหมดสว่าง (js/core/theme-boot.js ตั้ง data-theme ก่อนวาดหน้า · สลับด้วยปุ่มที่ topbar: js/core/theme.js)
 *
 * กติกาสี:
 * - ส้ม (--primary) เป็น "สีเน้น" ไม่ใช่พื้นหลัง · ข้อความสีส้มบนพื้นใช้ --primary-ink (ผ่าน AA ทั้งสองโหมด) ไม่ใช้ --primary ตรง ๆ
 * - สีสถานะต้องแยกจากส้มแบรนด์ได้: สำเร็จ/บวก = เขียวอมฟ้า · เตือน = เหลือง (--gold) · อันตราย/ลบ = แดงอมชมพู (คนละโทนกับ --sun-700) · ข้อมูล = ฟ้า (--info)
 * - เส้นขอบฟ้า (--horizon) และแสงเรือง (--glow*) ใช้เฉพาะ: ใต้ topbar, เส้นคั่นหัวข้อ, เมนูที่เลือกอยู่, ตัวบอก "สด" และวงโฟกัส
 * - ห้ามวางข้อความเนื้อหาบน --sun-gradient
 */
:root {
  color-scheme: dark;
  --radius: 10px;

  /* สีแบรนด์ (ค่าตายตัว ใช้ร่วมทั้งสองโหมด) */
  --sun-50: #fff4e0; /* แสงขอบฟ้า / ขาวอุ่น */
  --sun-200: #ffd08a;
  --sun-400: #ff9a3c;
  --sun-500: #ff6a1f; /* ส้มหลักของแบรนด์ */
  --sun-600: #e8481a; /* hover / กด */
  --sun-700: #c42a16;
  --ember-900: #2a0d06;
  --night: #0b0604;
  /* ไล่สีประจำแบรนด์: ใช้กับ hero, ไฮไลต์ของปุ่มหลัก และชุดข้อมูลหลักของกราฟเท่านั้น */
  --sun-gradient: linear-gradient(180deg, #ffb347 0%, #ff6a1f 55%, #c42a16 100%);

  /* พื้นผิว */
  --background: #0b0604; /* พื้นหน้า */
  --foreground: #fff4e0;
  --card: #140b07; /* พื้นผิวชั้นแรก (การ์ด, sidebar, topbar) */
  --card-foreground: #fff4e0;
  --muted: #1c110c; /* พื้นผิวชั้นสอง (แถบรอง, ช่องที่ยกขึ้น) */
  --muted-foreground: #b9a89a;
  --border: rgb(255 154 60 / 0.12);
  --input: #80624d; /* ขอบของช่องกรอก (ต้องเห็นชัด 3:1 กับพื้น) */
  --ring: #ff9a3c;

  /* Primary: ส้ม (ปุ่มหลัก, เมนูที่เลือก) — ตัวอักษรบนพื้นส้มเป็นสีเข้ม (ขาวบนส้มคอนทราสต์ไม่ถึง AA) */
  --primary: #ff6a1f;
  --primary-hover: #e8481a;
  --primary-soft: rgb(255 106 31 / 0.14);
  --primary-foreground: #0b0604;
  --primary-ink: #ff9a3c; /* ข้อความ/ลิงก์สีส้มบนพื้นผิว */
  --secondary: rgb(255 106 31 / 0.14);
  --secondary-foreground: #ffd08a; /* ข้อความบนพื้น --primary-soft */
  --accent: rgb(255 154 60 / 0.08); /* พื้น hover ของรายการ/เมนู */
  --accent-foreground: #fff4e0;

  /* เตือน: เหลือง (ชื่อตัวแปรยังเป็น --gold) — ต้องต่างจากส้มแบรนด์ */
  --gold: #f5c542;
  --gold-soft: rgb(245 197 66 / 0.14);
  --gold-foreground: #f9dc8a; /* ข้อความบนพื้นเหลืองอ่อน */
  /* ข้อมูล: ฟ้า */
  --info: #60a5fa;
  --info-soft: rgb(96 165 250 / 0.14);
  --info-ink: #a5cdfd;

  /* Sentiment (บวก/กลาง/ลบ) + พื้นอ่อนและสีตัวอักษรของป้ายกำกับ */
  --positive: #34d399;
  --positive-soft: rgb(52 211 153 / 0.14);
  --positive-ink: #6ee7b7;
  --neutral: #a8998c; /* เทาอุ่น */
  --neutral-soft: rgb(185 168 154 / 0.14);
  --neutral-ink: #d6c8bb;
  --negative: #f0457d;
  --negative-soft: rgb(240 69 125 / 0.15);
  --negative-ink: #fda4bf;
  /* สีตัวอักษรที่อ่านได้บนพื้นสี sentiment ของแท่งในกราฟ */
  --on-positive: #0b0604;
  --on-neutral: #0b0604;
  --on-negative: #0b0604;
  --destructive: #f0457d;
  --destructive-foreground: #0b0604;

  /* Sidebar: พื้นผิวเดียวกับการ์ด คั่นด้วยเส้นขอบ */
  --sidebar: #140b07;
  --sidebar-foreground: #fff4e0;
  --sidebar-muted: #b9a89a;
  --sidebar-hover: rgb(255 154 60 / 0.08);
  --sidebar-active: rgb(255 106 31 / 0.14);
  --sidebar-border: rgb(255 154 60 / 0.12);

  /* กราฟ: เส้นกริดและแกนเป็น hairline · ชุดเทียบ (ช่วงก่อนหน้า) เป็นเทาอุ่น ไม่แย่งสายตาจากชุดหลักสีส้ม */
  --chart-grid: rgb(255 154 60 / 0.1);
  --chart-axis: #a39284;
  --chart-previous: #8d7d70;
  --chart-main: #ff6a1f; /* ชุดข้อมูลหลักของกราฟ */
  /* พื้นใต้เส้นของชุดหลัก: ไล่สีพระอาทิตย์ตก (ทอง → ส้ม → โปร่งใส) + แสงเรืองของเส้น */
  --chart-fill-top: rgb(255 179 71 / 0.42);
  --chart-fill-mid: rgb(255 106 31 / 0.2);
  --chart-fill-bottom: rgb(196 42 22 / 0);
  --chart-glow: rgb(255 120 40 / 0.75);
  /* ตัวเลข KPI หลัก และ sparkline ของมัน */
  --kpi-gradient: linear-gradient(180deg, #ffe2b0 0%, #ffb347 45%, #ff6a1f 100%);
  --spark-1: #ffb347;
  --spark-2: #ff6a1f;
  --spark-3: #c42a16;
  --strike-flash: linear-gradient(90deg, transparent 0%, rgb(255 154 60 / 0.42) 45%, rgb(255 244 224 / 0.3) 50%, rgb(255 154 60 / 0.42) 55%, transparent 100%);

  /* เส้นขอบฟ้า: แกนกลางขาวอุ่น จางเป็นส้มที่ปลาย */
  --horizon: linear-gradient(90deg, transparent 0%, #ff6a1f 18%, #fff4e0 50%, #ff6a1f 82%, transparent 100%);
  --horizon-v: linear-gradient(180deg, #ff6a1f 0%, #fff4e0 50%, #ff6a1f 100%);
  --horizon-glow: 0 0 12px rgb(255 154 60 / 0.55);
  /* แสงเรืองอุ่น: เฉพาะโฟกัส / สถานะที่เลือก / สด */
  --glow-focus: 0 0 0 3px rgb(255 154 60 / 0.28);
  --glow-active: 0 0 16px rgb(255 106 31 / 0.25);

  /* สีแบรนด์ทางการของแพลตฟอร์ม (ใช้เฉพาะในโลโก้ — ห้ามเอาไปใช้เป็นสี UI) */
  --brand-facebook: #0866ff;
  --brand-facebook-mark: #ffffff;
  --brand-instagram-1: #fdf497;
  --brand-instagram-2: #fd5949;
  --brand-instagram-3: #d6249f;
  --brand-instagram-4: #285aeb;
  --brand-tiktok-cyan: #25f4ee;
  --brand-tiktok-red: #fe2c55;
  --brand-youtube: #ff0000;
  --brand-youtube-mark: #ffffff;

  /* เงา: โหมดมืดพึ่งเส้นขอบ 1px เป็นหลัก เงาใช้กับสิ่งที่ลอย (dialog, เมนู, toast) */
  --overlay: rgb(0 0 0 / 0.62);
  --elev-card: 0 0 0 0 transparent;
  --elev-pop: 0 16px 40px rgb(0 0 0 / 0.6);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.35);
  --shadow-xs: 0 0 0 0 transparent;
}

:root[data-theme='light'] {
  color-scheme: light;

  --background: #fffbf6;
  --foreground: #1a100b;
  --card: #ffffff;
  --card-foreground: #1a100b;
  --muted: #fbf2e8;
  --muted-foreground: #7a6656;
  --border: #f1e4d6;
  --input: #a08670;
  --ring: #e8481a;

  --primary: #ff6a1f;
  --primary-hover: #e8481a;
  --primary-soft: #ffeedd;
  --primary-foreground: #1a100b;
  --primary-ink: #b93c0d;
  --secondary: #ffeedd;
  --secondary-foreground: #8f2f0b;
  --accent: #fff3e6;
  --accent-foreground: #1a100b;

  --gold: #b98900;
  --gold-soft: #fdf3cf;
  --gold-foreground: #6f4e00;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --info-ink: #1d4fc4;

  --positive: #0a8259;
  --positive-soft: #e3f6ee;
  --positive-ink: #0a6646;
  --neutral: #7a6b5e;
  --neutral-soft: #f3ece5;
  --neutral-ink: #5c4e42;
  --negative: #d81b4a;
  --negative-soft: #fdeaef;
  --negative-ink: #a30f36;
  --on-positive: #ffffff;
  --on-neutral: #ffffff;
  --on-negative: #ffffff;
  --destructive: #d81b4a;
  --destructive-foreground: #ffffff;

  --sidebar: #ffffff;
  --sidebar-foreground: #1a100b;
  --sidebar-muted: #7a6656;
  --sidebar-hover: #fff3e6;
  --sidebar-active: #ffeedd;
  --sidebar-border: #f1e4d6;

  --chart-grid: #f3e8dc;
  --chart-axis: #7a6656;
  --chart-previous: #8d7d70;
  --chart-main: #e8481a; /* ส้มเข้มขึ้นหนึ่งขั้นให้มาร์กเห็นชัดบนพื้นขาว */
  --chart-fill-top: rgb(255 154 60 / 0.34);
  --chart-fill-mid: rgb(255 106 31 / 0.14);
  --chart-fill-bottom: rgb(255 106 31 / 0);
  --chart-glow: rgb(255 106 31 / 0.28);
  --kpi-gradient: linear-gradient(180deg, #e8481a 0%, #c42a16 100%);
  --spark-1: #ff9a3c;
  --spark-2: #e8481a;
  --spark-3: #c42a16;
  --strike-flash: linear-gradient(90deg, transparent 0%, rgb(255 154 60 / 0.3) 50%, transparent 100%);

  /* พื้นสว่าง: แกนกลางขาวจะมองไม่เห็น จึงใช้อำพันเป็นแกน */
  --horizon: linear-gradient(90deg, transparent 0%, #ff6a1f 18%, #ff9a3c 50%, #ff6a1f 82%, transparent 100%);
  --horizon-v: linear-gradient(180deg, #ff9a3c 0%, #ff6a1f 50%, #ff9a3c 100%);
  --horizon-glow: 0 0 10px rgb(255 106 31 / 0.35);
  --glow-focus: 0 0 0 3px rgb(255 106 31 / 0.22);
  --glow-active: 0 0 14px rgb(255 106 31 / 0.18);

  --overlay: rgb(26 16 11 / 0.45);
  --elev-card: 0 1px 2px rgb(26 16 11 / 0.04);
  --elev-pop: 0 12px 32px rgb(26 16 11 / 0.16);
  --shadow-sm: 0 1px 2px rgb(26 16 11 / 0.08);
  --shadow-xs: 0 1px 2px rgb(26 16 11 / 0.04);
}

/* ค่าที่ไม่ขึ้นกับโหมด (อนุพันธ์จากตัวแปรด้านบน) */
:root {
  /* Google Sans (Google Fonts) ครอบคลุมทั้งละติน ตัวเลข และอักษรไทยในตัว · ที่เหลือเป็นฟอนต์สำรองของระบบ */
  --font-sans: 'Google Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'Noto Sans Thai', Sarabun, Thonburi, Tahoma, sans-serif;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 2px);
  --shadow-card: var(--elev-card);
  --shadow-pop: var(--elev-pop);
  --sidebar-width: 256px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  /* skeleton: พื้นโปร่งจากสีตัวอักษรของโหมดนั้น ๆ (เห็นชัดทั้งมืด/สว่าง บนพื้น card หรือ background) + แถบแสงที่กวาดผ่าน */
  --skeleton-base: color-mix(in srgb, var(--foreground) 9%, transparent);
  --skeleton-shine: color-mix(in srgb, var(--foreground) 12%, transparent);
}

/* == base == */
*,
::before,
::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid var(--border);
}
html {
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  tab-size: 4;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
  scrollbar-gutter: stable;
}
body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  /* ภาษาไทยมีสระบน/ล่าง ต้องการระยะบรรทัดมากกว่าละติน */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* ตัวเลขของตัวชี้วัด/ตาราง: ความกว้างเท่ากันทุกหลัก (ไม่ขยับเมื่อค่าเปลี่ยน) */
.tabular-nums, .table td, .stat-value, .pagination, time { font-variant-numeric: tabular-nums; }
hr { height: 0; color: inherit; border-top-width: 1px; }
abbr:where([title]) { text-decoration: underline dotted; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }
a { color: inherit; text-decoration: inherit; }
b, strong { font-weight: bolder; }
code, kbd, samp, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 1em; }
small { font-size: 80%; }
table { text-indent: 0; border-color: inherit; border-collapse: collapse; }
progress { vertical-align: baseline; }
summary { display: list-item; }
ol, ul, menu { list-style: none; }
img, svg, video, canvas, audio, iframe, embed, object { display: block; vertical-align: middle; }
img, video { max-width: 100%; height: auto; }
button, input, select, optgroup, textarea, ::file-selector-button {
  font: inherit;
  font-feature-settings: inherit;
  font-variation-settings: inherit;
  letter-spacing: inherit;
  color: inherit;
  border-radius: 0;
  background-color: transparent;
  opacity: 1;
}
button, [type='button'], [type='reset'], [type='submit'] { -webkit-appearance: button; appearance: button; }
::placeholder { opacity: 1; color: var(--muted-foreground); }
textarea { resize: vertical; }
::-webkit-search-decoration { -webkit-appearance: none; }
::-webkit-date-and-time-value { min-height: 1lh; text-align: inherit; }
::-webkit-datetime-edit { display: inline-flex; }
::-webkit-inner-spin-button, ::-webkit-outer-spin-button { height: auto; }
:-moz-ui-invalid { box-shadow: none; }
[hidden]:where(:not([hidden='until-found'])) { display: none !important; }

/*
 * ทุกอย่างที่กดได้ใช้เคอร์เซอร์มือชี้ที่นี่ที่เดียว (:where ให้ specificity เป็น 0 — disabled ยังชนะเสมอ)
 */
:where(
    button,
    summary,
    select,
    [role='button'],
    [role='tab'],
    [role='radio'],
    [role='checkbox'],
    [role='switch'],
    [role='menuitem'],
    [role='option'],
    input:where([type='checkbox'], [type='radio'], [type='file'], [type='submit'], [type='button'], [type='reset']),
    label:has(input:where([type='checkbox'], [type='radio']), [role='checkbox'], [role='radio'], [role='switch'])
  ):where(:not(:disabled, [aria-disabled='true'], [data-disabled])) {
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
::selection {
  background: var(--primary-soft);
  color: var(--secondary-foreground);
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
html.dialog-open { overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  z-index: 100;
  border-radius: var(--radius-md);
  background: var(--background);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-pop);
}
.skip-link:focus { top: 0.5rem; }
.noscript { padding: 1.5rem; text-align: center; }

/* ไอคอน (icons.js): ขนาดมาจาก attribute width/height; ตัวหนังสือรอบข้างกำหนดสี (currentColor) */
.icon { flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.5; } }
@keyframes skeleton-shimmer { to { background-position: 200% 0; } }
@keyframes ping { 75%, 100% { transform: scale(2); opacity: 0; } }
@keyframes live-pulse { 0%, 100% { opacity: 1; transform: scaleX(1); } 50% { opacity: 0.45; transform: scaleX(0.7); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* == components == */

/* ---- ปุ่ม: .btn (primary) + .btn-secondary|outline|ghost|destructive|link · ขนาด .btn-sm|lg|icon ---- */
.btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  height: 2.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-sm);
  font-size: 0.875rem;
  line-height: 1.4286;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s var(--ease-out), background-color 0.15s var(--ease-out), border-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
}
.btn:hover { background: var(--primary-hover); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring), var(--glow-active); }
.btn:disabled,
.btn[aria-disabled='true'] { pointer-events: none; opacity: 0.5; }
.btn svg { pointer-events: none; flex-shrink: 0; }
.btn svg:not([class*='size-']) { width: 1rem; height: 1rem; }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); box-shadow: none; }
.btn-secondary:hover { background: color-mix(in srgb, var(--primary-soft) 60%, transparent); }
.btn-outline { border: 1px solid var(--input); background: var(--card); color: var(--foreground); box-shadow: none; }
.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-ghost { background: transparent; color: var(--foreground); box-shadow: none; }
.btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover { background: color-mix(in srgb, var(--destructive) 90%, transparent); }
.btn-link { height: auto; padding: 0; background: transparent; color: var(--primary-ink); box-shadow: none; text-underline-offset: 4px; }
.btn-link:hover { background: transparent; text-decoration: underline; }
/* ปุ่มไอคอนลบ/อันตรายแบบเบา (ghost สีแดง) */
.btn-danger-ghost { color: var(--negative-ink); }
.btn-danger-ghost:hover { background: var(--negative-soft); color: var(--negative-ink); }
.btn-sm { height: 2rem; gap: 0.375rem; padding: 0 0.75rem; font-size: 13px; }
.btn-lg { height: 2.75rem; padding: 0 1.5rem; font-size: 1rem; line-height: 1.5; }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; }

/* ---- ป้าย: .badge (soft) + .badge-solid|gold|outline|muted|positive|neutral|negative ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  background: var(--primary-soft);
  color: var(--secondary-foreground);
  font-size: 0.75rem;
  line-height: 1.3333;
  font-weight: 500;
}
.badge svg { width: 0.875rem; height: 0.875rem; flex-shrink: 0; }
/* รอบเก็บข้อมูลในตาราง: เน้นให้กวาดตาหาได้เร็ว (ตัวหนา + พื้นสีเน้น) · แถวที่ปิดใช้งานจางลงตามแถว */
.interval-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
  border-radius: 0.5rem;
  padding: 0.25rem 0.625rem;
  background: var(--primary-soft);
  color: var(--secondary-foreground);
  font-size: 0.875rem;
  line-height: 1.4286;
  font-weight: 600;
}
.interval-chip svg { width: 0.875rem; height: 0.875rem; flex-shrink: 0; opacity: 0.75; }
.row-inactive .interval-chip { background: var(--muted); color: var(--muted-foreground); font-weight: 500; }
.badge-solid { background: var(--primary); color: var(--primary-foreground); }
.badge-gold { background: var(--gold-soft); color: var(--gold-foreground); }
.badge-outline { border: 1px solid var(--border); background: transparent; color: var(--foreground); }
.badge-info { background: var(--info-soft); color: var(--info-ink); }
.badge-muted { background: var(--muted); color: var(--muted-foreground); }
.badge-positive { background: var(--positive-soft); color: var(--positive-ink); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral-ink); }
.badge-negative { background: var(--negative-soft); color: var(--negative-ink); }

/* ---- การ์ด ---- */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--card-foreground);
  box-shadow: var(--shadow-card);
}
.card-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 0.75rem; padding: 1.25rem 1.25rem 0; }
.card-title { font-size: 15px; font-weight: 600; line-height: 1.375; letter-spacing: -0.01em; }
.card-description { margin-top: 0.125rem; font-size: 13px; color: var(--muted-foreground); }
.card-content { padding: 1rem 1.25rem 1.25rem; }

/* ---- ฟอร์ม: label / input / field / error ---- */
.field { display: grid; gap: 0.5rem; }
.label { font-size: 0.875rem; line-height: 1; font-weight: 500; user-select: none; }
.field-hint { font-size: 0.75rem; line-height: 1.3333; color: var(--muted-foreground); }
.field-error { font-size: 0.75rem; line-height: 1.3333; color: var(--negative-ink); }
.alert { border-radius: var(--radius-md); padding: 0.5rem 0.75rem; font-size: 0.875rem; line-height: 1.4286; }
.alert-error { border: 1px solid color-mix(in srgb, var(--negative) 30%, transparent); background: var(--negative-soft); color: var(--negative-ink); }
.input {
  display: flex;
  height: 2.5rem;
  width: 100%;
  min-width: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--input);
  background: var(--background);
  padding: 0.5rem 0.75rem;
  box-shadow: var(--shadow-xs);
  font-size: 0.875rem;
  line-height: 1.4286;
  outline: none;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.input:focus-visible { outline: none; border-color: var(--ring); box-shadow: var(--glow-focus); }
.input:disabled { cursor: not-allowed; opacity: 0.5; }
.input[aria-invalid='true'],
.select[aria-invalid='true'] { border-color: var(--destructive); box-shadow: 0 0 0 2px color-mix(in srgb, var(--destructive) 20%, transparent); }
.input-date { height: 2.25rem; width: 150px; }

/* ---- select (native <select> + ลูกศร) ---- */
.select-wrap { position: relative; display: block; min-width: 0; }
.select {
  display: block;
  height: 2.5rem;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--input);
  background: var(--background);
  padding: 0.5rem 2.25rem 0.5rem 0.75rem;
  box-shadow: var(--shadow-xs);
  font-size: 0.875rem;
  line-height: 1.4286;
  text-overflow: ellipsis;
  white-space: nowrap;
  outline: none;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.select:focus-visible { outline: none; border-color: var(--ring); box-shadow: var(--glow-focus); }
.select:disabled { cursor: not-allowed; opacity: 0.5; }
.select-icon { position: absolute; right: 0.75rem; top: 50%; width: 1rem; height: 1rem; transform: translateY(-50%); color: var(--muted-foreground); pointer-events: none; }
.select-sm { height: 2rem; padding: 0 1.75rem 0 0.625rem; font-size: 13px; }
.select-sm + .select-icon { right: 0.5rem; }
.select-compact { width: 72px; }

/* ---- checkbox (native) + แถวเลือกแพลตฟอร์ม ---- */
.checkbox {
  display: inline-grid;
  place-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 5px;
  border: 1px solid var(--input);
  background-color: var(--background);
  box-shadow: var(--shadow-xs);
  vertical-align: middle;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.checkbox::after {
  content: '';
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid var(--primary-foreground);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.1s;
}
.checkbox:checked { border-color: var(--primary); background-color: var(--primary); }
.checkbox:checked::after { transform: rotate(45deg) scale(1); }
.checkbox:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--background), 0 0 0 3px var(--ring); }
.checkbox:disabled { cursor: not-allowed; opacity: 0.5; }
.check-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.4286;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.check-row:hover { background: var(--accent); }
.check-row.is-checked { border-color: color-mix(in srgb, var(--primary) 50%, transparent); background: color-mix(in srgb, var(--primary-soft) 50%, transparent); }

/* ---- switch (button role="switch") ---- */
.switch {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  width: 2.5rem;
  height: 22px;
  border-radius: 9999px;
  border: 2px solid transparent;
  background: var(--input);
  padding: 0;
  transition: background-color 0.15s;
}
.switch[aria-checked='true'] { background: var(--primary); }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }
.switch:disabled,
.switch[aria-disabled='true'] { cursor: not-allowed; opacity: 0.5; }
.switch-thumb {
  pointer-events: none;
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  background: var(--sun-50);
  box-shadow: var(--shadow-sm);
  transform: translateX(0);
  transition: transform 0.15s;
}
.switch[aria-checked='true'] .switch-thumb { transform: translateX(18px); }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--muted) 50%, transparent);
  padding: 0.75rem 1rem;
}

/* ---- segmented (radiogroup ของปุ่ม) ---- */
.segmented { display: inline-flex; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--muted); padding: 0.125rem; }
.segmented-btn {
  white-space: nowrap;
  border-radius: 7px;
  padding: 0.375rem 0.75rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-foreground);
  transition: color 0.15s, background-color 0.15s;
}
.segmented-btn:hover { color: var(--foreground); }
.segmented-btn[aria-checked='true'] { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm); }
.segmented-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.segmented-sm .segmented-btn { padding: 0.25rem 0.625rem; font-size: 0.75rem; line-height: 1.3333; }

/* ---- skeleton ----
 * แท่งหลอกระหว่างโหลด: สี --skeleton-base/--skeleton-shine (เดิมใช้ --muted ซึ่งเกือบกลืนกับพื้นจนมองไม่เห็น) + แสงกวาดผ่านจากซ้ายไปขวา
 * ผู้ใช้ตั้งลดการเคลื่อนไหว = ไม่กวาด (กฎ prefers-reduced-motion ด้านบนตัด animation เหลือแท่งนิ่ง ๆ) · ความสูง/กว้างกำหนดด้วยคลาสขนาด (h-14 w-56 …) ที่ต้องมีนิยามเสมอ ไม่งั้นแท่งสูง 0 */
.skeleton {
  border-radius: var(--radius-md);
  background-color: var(--skeleton-base);
  background-image: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  background-repeat: no-repeat;
  background-size: 45% 100%;
  background-position: -100% 0;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
}

/* ---- ตาราง: <div class="table-wrap"><table class="table"> ---- */
.table-wrap { position: relative; width: 100%; overflow-x: auto; }
.table { width: 100%; caption-side: bottom; font-size: 0.875rem; line-height: 1.4286; }
.table tr { border-bottom: 1px solid var(--border); transition: background-color 0.15s; }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr.row-inactive { background: color-mix(in srgb, var(--muted) 40%, transparent); color: var(--muted-foreground); }
.table tbody tr:hover,
.table thead tr:hover { background: color-mix(in srgb, var(--accent) 60%, transparent); }
.table tr.no-hover:hover { background: transparent; }
.table th { height: 2.5rem; white-space: nowrap; padding: 0 0.75rem; text-align: left; vertical-align: middle; font-size: 0.75rem; line-height: 1.3333; font-weight: 500; color: var(--muted-foreground); }
.table td { padding: 0.75rem; vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 1.25rem; }
.table th:last-child, .table td:last-child { padding-right: 1.25rem; }
.table th.text-right, .table td.text-right { text-align: right; }
.link-hover { border-radius: var(--radius-sm); text-underline-offset: 4px; outline: none; }
.link-hover:hover { color: var(--primary-ink); text-decoration: underline; }
.link-hover:focus-visible { box-shadow: 0 0 0 2px var(--ring); }
.is-refreshing { opacity: 0.6; transition: opacity 0.2s; }
.mark { border-radius: 3px; background: var(--gold-soft); padding: 0 0.125rem; color: var(--gold-foreground); }
/* keyword ที่จับได้ในเนื้อหาโพสต์ (หน้ารายละเอียดโพสต์): พื้นส้มของแบรนด์ + เส้นใต้ส้มทึบ ตัวอักษรคงสีปกติเพื่อให้ยังอ่านชัดทั้งสองธีม */
.mark.mark-keyword { background: color-mix(in srgb, var(--primary) 34%, transparent); box-shadow: inset 0 -2px 0 var(--primary); color: var(--foreground); }

/* ---- dialog ---- */
.dialog-root { position: fixed; inset: 0; z-index: 50; }
.dialog-overlay { position: fixed; inset: 0; background: var(--overlay); animation: fade-in 0.15s ease-out; }
.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 50;
  display: grid;
  gap: 1rem;
  width: calc(100% - 2rem);
  max-width: 32rem;
  max-height: calc(100dvh - 2rem);
  transform: translate(-50%, -50%);
  overflow-y: auto;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1.5rem;
  color: var(--card-foreground);
  box-shadow: var(--shadow-pop);
  outline: none;
}
.dialog-sm { max-width: 24rem; }
.dialog-md { max-width: 28rem; }
.dialog-lg { max-width: 32rem; }
.dialog-xl { max-width: 36rem; }
.dialog-2xl { max-width: 42rem; }
.dialog-header { display: flex; flex-direction: column; gap: 0.375rem; padding-right: 1.5rem; }
.dialog-title { font-size: 1.125rem; line-height: 1.375; font-weight: 600; }
.dialog-description { font-size: 0.875rem; line-height: 1.4286; color: var(--muted-foreground); }
.dialog-footer { display: flex; flex-direction: column-reverse; gap: 0.5rem; }
@media (min-width: 640px) {
  .dialog-footer { flex-direction: row; justify-content: flex-end; }
}
.dialog-close {
  position: absolute;
  right: 1rem;
  top: 1rem;
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  color: var(--muted-foreground);
  transition: color 0.15s, background-color 0.15s;
}
.dialog-close:hover { background: var(--accent); color: var(--foreground); }
.dialog-close:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.dialog-close svg { width: 1rem; height: 1rem; }

/* ---- เมนูดรอปดาวน์ ---- */
.menu-popover {
  position: fixed;
  z-index: 60;
  min-width: 14rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.25rem;
  color: var(--card-foreground);
  box-shadow: var(--shadow-pop);
}
.menu { outline: none; }
.menu-header { margin-bottom: 0.25rem; border-bottom: 1px solid var(--border); padding: 0.5rem 0.75rem 0.5rem; }
.menu-header-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; line-height: 1.4286; font-weight: 500; }
.menu-header-email,
.menu-header-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; line-height: 1.3333; color: var(--muted-foreground); }
.menu-header-role { margin-top: 0.25rem; }
.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.875rem;
  line-height: 1.4286;
  outline: none;
}
.menu-item svg { width: 1rem; height: 1rem; color: var(--muted-foreground); }
.menu-item:hover,
.menu-item:focus { background: var(--accent); color: var(--accent-foreground); }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--ring); }
.menu-item:disabled { opacity: 0.5; pointer-events: none; }
.menu-separator { margin: 0.25rem 0; height: 1px; background: var(--border); }

/* ---- toast (มุมขวาบน) ---- */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 100; width: min(356px, calc(100vw - 2rem)); pointer-events: none; }
.toast-region { display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1rem;
  color: var(--card-foreground);
  box-shadow: var(--shadow-pop);
  font-size: 13px;
  line-height: 1.45;
  animation: toast-in 0.2s ease-out;
}
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast[data-type='success'] .toast-icon { color: var(--positive); }
.toast[data-type='error'] .toast-icon { color: var(--negative); }
.toast[data-type='info'] .toast-icon { color: var(--info); }
.toast-body { min-width: 0; flex: 1; }
.toast-title { font-weight: 500; }
.toast-description { margin-top: 0.125rem; color: var(--muted-foreground); }
.toast-close { flex-shrink: 0; border-radius: var(--radius-sm); padding: 0.125rem; color: var(--muted-foreground); }
.toast-close:hover { background: var(--accent); color: var(--foreground); }
.toast-close:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }

/* ---- ช่องแท็ก (คำยกเว้น) ---- */
.tag-input {
  display: flex;
  min-height: 2.5rem;
  width: 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--input);
  background: var(--background);
  padding: 0.375rem 0.5rem;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tag-input:focus-within { border-color: var(--ring); box-shadow: var(--glow-focus); }
.tag-input.is-invalid { border-color: var(--destructive); }
.tag {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 0.25rem;
  border-radius: 9999px;
  background: var(--primary-soft);
  padding: 0.125rem 0.25rem 0.125rem 0.625rem;
  color: var(--secondary-foreground);
  font-size: 0.75rem;
  line-height: 1.3333;
  font-weight: 500;
}
.tag-remove { display: flex; width: 1rem; height: 1rem; align-items: center; justify-content: center; border-radius: 9999px; }
.tag-remove:hover { background: color-mix(in srgb, var(--primary) 15%, transparent); }
.tag-remove:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.tag-input-field { min-width: 8rem; flex: 1; background: transparent; padding: 0.125rem 0.25rem; font-size: 0.875rem; line-height: 1.4286; outline: none; }
.tag-input-field:focus-visible { outline: none; }

/* ---- แบ่งหน้า ---- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.75rem 1.25rem; }
.pagination-summary { font-size: 13px; color: var(--muted-foreground); }
.pagination-strong { font-weight: 500; color: var(--foreground); }
.pagination-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.pagination-size { display: flex; align-items: center; gap: 0.5rem; font-size: 13px; color: var(--muted-foreground); }
.pagination-pages { display: flex; align-items: center; gap: 0.25rem; }
.pagination-gap { padding: 0 0.25rem; color: var(--muted-foreground); }

/* ---- สถานะว่าง/ผิดพลาด ---- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 3.5rem 1.5rem; text-align: center; }
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 3rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.state-icon { display: flex; width: 3rem; height: 3rem; align-items: center; justify-content: center; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--muted); color: var(--muted-foreground); }
.state-icon-negative { border-color: transparent; background: var(--negative-soft); color: var(--negative-ink); }
.empty-title { margin-top: 0.25rem; font-weight: 500; }
.state-text { max-width: 28rem; font-size: 0.875rem; line-height: 1.4286; color: var(--muted-foreground); }
.state-action { margin-top: 0.5rem; }
.error-state .btn { margin-top: 0.5rem; }

/* ---- หัวข้อหน้า (pageHeader): ชื่อหน้า + คำอธิบาย ทางซ้าย · ปุ่มทางขวา (จอแคบเรียงลงมา) ---- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem 1.5rem; margin-bottom: 1.5rem; }
.page-header-body { min-width: 0; }
.page-title { font-size: 1.5rem; line-height: 1.3333; font-weight: 600; letter-spacing: -0.025em; color: var(--foreground); }
.page-description { margin-top: 0.25rem; max-width: 48rem; font-size: 0.875rem; line-height: 1.4286; color: var(--muted-foreground); }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

/* ---- เส้นขอบฟ้า (ลายเซ็นของแบรนด์): เส้นบางเรืองแสง — ใช้เท่าที่จำเป็น (ใต้ topbar, คั่น hero, เมนูที่เลือก, ตัวบอก "สด") ---- */
.horizon-line { display: block; height: 1px; width: 100%; border: 0; background: var(--horizon); box-shadow: var(--horizon-glow); }
/* ตัวบอก "สด": เส้นขอบฟ้าสั้น ๆ เต้นเบา ๆ (หยุดเมื่อผู้ใช้ขอลดการเคลื่อนไหว) */
.live-line { display: inline-block; flex-shrink: 0; width: 1.25rem; height: 2px; border-radius: 2px; background: var(--horizon); box-shadow: var(--horizon-glow); animation: live-pulse 2s ease-out infinite; }
.live-line.is-idle { animation: none; background: var(--muted-foreground); box-shadow: none; opacity: 0.6; }
.live-badge { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; line-height: 1.3333; font-weight: 500; color: var(--muted-foreground); }

/* ---- โลโก้แพลตฟอร์ม / แบรนด์ ---- */
.platform-icon { width: 1rem; height: 1rem; flex-shrink: 0; color: var(--foreground); }
.platform-icon-news { border-radius: 22%; background: var(--card); object-fit: contain; box-shadow: 0 0 0 1px var(--border); }
.brand-mark { flex-shrink: 0; user-select: none; }

/* == layout == */

/* ---- โครงหน้าหลังล็อกอิน ---- */
.app-shell { min-height: 100dvh; background: var(--background); }
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: 16rem;
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.2s, visibility 0s linear 0.2s;
}
.sidebar-panel { display: flex; height: 100%; flex-direction: column; gap: 1.5rem; overflow-y: auto; border-right: 1px solid var(--sidebar-border); background: var(--sidebar); padding: 1rem; color: var(--sidebar-foreground); }
.sidebar-close { position: absolute; right: 0.5rem; top: 0.75rem; color: var(--sidebar-foreground); }
.sidebar-close:hover { background: var(--sidebar-hover); color: var(--sidebar-foreground); }
.app-shell[data-drawer='open'] .sidebar { transform: none; visibility: visible; transition: transform 0.2s; }
.drawer-backdrop { position: fixed; inset: 0; z-index: 39; background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.app-shell[data-drawer='open'] .drawer-backdrop { opacity: 1; pointer-events: auto; }

.app-body { display: flex; min-height: 100dvh; min-width: 0; flex-direction: column; overflow-x: clip; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: 3.5rem;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--background) 85%, transparent);
  padding: 0 1rem;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
/* เส้นขอบฟ้าใต้ topbar */
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--horizon); box-shadow: var(--horizon-glow); opacity: 0.8; pointer-events: none; }
.topbar-heading { display: flex; min-width: 0; align-items: center; gap: 0.5rem; }
/* "หมวด / ชื่อหน้า" บอกว่าหน้านี้อยู่หมวดไหนของเมนู — มือถือซ่อนหมวดเพื่อให้ชื่อหน้าอ่านออก */
.topbar-section, .topbar-sep { display: none; flex-shrink: 0; font-size: 0.875rem; line-height: 1.4286; color: var(--muted-foreground); white-space: nowrap; }
.topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; line-height: 1.4286; font-weight: 500; color: var(--muted-foreground); }
.topbar-section ~ .topbar-title { color: var(--foreground); }
.topbar-actions { margin-left: auto; display: flex; min-width: 0; align-items: center; gap: 0.375rem; }
/* --main-pad: ระยะขอบของพื้นที่เนื้อหา — pageHeader ใช้ค่าเดียวกันดึงให้ชิดขอบ (แก้ที่นี่ที่เดียว) */
.app-main { --main-pad: 1rem; margin-inline: auto; width: 100%; max-width: 1400px; flex: 1; padding: var(--main-pad); }
.app-main:focus { outline: none; }
.page-content { min-width: 0; }
/* มีประกาศ (เช่น "ยังไม่ได้อยู่ในทีม") เหนือเนื้อหา */
.app-main.has-notice .notice { margin-bottom: 1.25rem; }
@media (min-width: 640px) {
  .topbar { padding: 0 1.5rem; }
  .topbar-actions { gap: 0.75rem; }
  .app-main { --main-pad: 1.5rem; }
  .topbar-section, .topbar-sep { display: inline; }
}
@media (min-width: 1024px) {
  .app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; z-index: auto; width: auto; height: 100dvh; transform: none; visibility: visible; transition: none; }
  .sidebar-close, .drawer-backdrop { display: none; }
  .topbar { padding: 0 2rem; }
  .app-main { --main-pad: 2rem; }
}

.brand { display: flex; align-items: center; gap: 0.75rem; border-radius: var(--radius-md); padding: 0.25rem 0.25rem 0; color: var(--sidebar-foreground); }
.brand:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.brand .brand-mark { width: 2rem; height: 2rem; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 1rem; font-weight: 600; letter-spacing: -0.02em; }
.brand-tagline { font-size: 11px; color: var(--sidebar-muted); }
.side-nav { display: flex; flex-direction: column; gap: 1.125rem; }
/* หมวดเมนู: หัวหมวดเล็ก ๆ มีเส้นต่อท้าย แยกกลุ่มให้เห็นว่าแต่ละกลุ่มใช้ทำอะไร */
.nav-group { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-group-label { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.75rem 0.125rem; font-size: 11px; line-height: 1.5; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--sidebar-muted); }
.nav-group-label::after { content: ''; height: 1px; flex: 1; background: var(--sidebar-border); }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  color: var(--sidebar-muted);
  font-size: 0.875rem;
  line-height: 1.4286;
  font-weight: 500;
  position: relative;
  transition: color 0.15s var(--ease-out), background-color 0.15s var(--ease-out);
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-foreground); }
.nav-link.is-active { background: var(--sidebar-active); color: var(--sidebar-foreground); }
/* เมนูที่เลือกอยู่: เส้นขอบฟ้าแนวตั้งที่ขอบซ้าย */
.nav-link.is-active::before { content: ''; position: absolute; left: 0; top: 22%; bottom: 22%; width: 2px; border-radius: 2px; background: var(--horizon-v); box-shadow: var(--horizon-glow); }
.nav-link:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link.is-active .nav-icon { color: var(--primary-ink); }
.nav-text { display: flex; min-width: 0; flex-direction: column; line-height: 1.25; }
.nav-label,
.nav-hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-hint { font-size: 11px; font-weight: 400; color: var(--sidebar-muted); }
/* รายการที่เลือกอยู่: พื้นอ่อนลงทำให้คอนทราสต์ของ --sidebar-muted ต่ำกว่า 4.5:1 จึงใช้ตัวอักษรขาวเต็ม */
.nav-link.is-active .nav-hint { color: var(--sidebar-foreground); }
.sidebar-note { margin-top: auto; padding: 0 0.75rem; font-size: 11px; line-height: 1.625; color: var(--sidebar-muted); }

.notice { margin-bottom: 1.5rem; display: flex; align-items: flex-start; gap: 0.75rem; border-radius: var(--radius-lg); padding: 0.75rem 1rem; font-size: 0.875rem; line-height: 1.4286; }
.notice-warn { border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); background: var(--gold-soft); color: var(--gold-foreground); }
.notice-icon { margin-top: 0.125rem; width: 1rem; height: 1rem; flex-shrink: 0; }
.notice strong { font-weight: 600; }

.team-badge { max-width: 200px; }

/* ---- ตัวเลือก "ตั้งค่าของทีมไหน" ของหน้าตั้งค่าทุกหน้า (core/team-scope.js): admin = ช่องเลือกทีม · สมาชิก = ชื่อทีมของตัวเอง ---- */
.team-scope { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); padding: 0.625rem 1rem; font-size: 0.875rem; line-height: 1.4286; }
.team-scope strong { font-weight: 600; }
.team-scope-label { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 500; white-space: nowrap; }
.team-scope-icon { width: 1rem; height: 1rem; flex-shrink: 0; color: var(--primary-ink); }
.team-scope > .team-scope-icon { align-self: flex-start; margin-top: 0.125rem; }
.team-scope > span { min-width: 0; flex: 1 1 12rem; }
.team-scope-select { width: 100%; max-width: 18rem; }
.team-scope-hint { min-width: 0; flex: 1 1 16rem; font-size: 13px; color: var(--muted-foreground); }
.team-scope-compact { min-width: 0; max-width: 12rem; }
.team-scope-compact .team-scope-select { max-width: none; }
.worker-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  line-height: 1.3333;
  font-weight: 500;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.worker-pill:hover { background: var(--accent); }
.worker-pill:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.worker-pill-warn { border-color: color-mix(in srgb, var(--gold) 40%, transparent); background: var(--gold-soft); color: var(--gold-foreground); }
.worker-pill-warn:hover { background: color-mix(in srgb, var(--gold-soft) 70%, transparent); }
/* จุดสถานะแบบเดิม (ยังใช้ในหน้า jobs: ตัวบอก "อัปเดตล่าสุด") */
.ping-dot { position: relative; display: flex; width: 0.5rem; height: 0.5rem; }
.ping-ring { position: absolute; display: inline-flex; width: 100%; height: 100%; border-radius: 9999px; background: var(--positive); opacity: 0.5; animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }
.ping-core { position: relative; display: inline-flex; width: 0.5rem; height: 0.5rem; border-radius: 9999px; background: var(--positive); }
.theme-toggle { color: var(--muted-foreground); }

.user-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.25rem 0.625rem 0.25rem 0.25rem;
  font-size: 0.875rem;
  line-height: 1.4286;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.user-trigger:hover { background: var(--accent); }
.user-trigger:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.user-avatar { width: 1.75rem; height: 1.75rem; border-radius: 9999px; background: var(--muted); object-fit: cover; }
.user-initials { display: flex; width: 1.75rem; height: 1.75rem; align-items: center; justify-content: center; border-radius: 9999px; background: var(--primary); color: var(--primary-foreground); font-size: 11px; line-height: 1.5; font-weight: 600; }
/* ชื่อผู้ใช้เป็นชื่อของปุ่มเสมอ: จอแคบซ่อนแบบ sr-only (ไม่ใช้ display:none ไม่งั้นปุ่มไม่มีชื่อที่ screen reader อ่านได้) */
.user-name { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.user-chevron { width: 1rem; height: 1rem; color: var(--muted-foreground); }
@media (min-width: 640px) {
  .user-name { position: static; display: block; width: auto; height: auto; max-width: 160px; margin: 0; overflow: hidden; clip: auto; text-overflow: ellipsis; }
}

/* ระหว่างรอ /api/auth/me (shell.js: renderLoadingShell) — ใช้คลาสของโครงจริง (.sidebar .topbar .app-main .page-header) ขนาดและตำแหน่งจึงตรงกับหน้าที่จะมาแทน ไม่กระโดด
 * แบรนด์กับหัวหมวดเมนูเป็นข้อความตายตัวจึงแสดงของจริง · รายการเมนู/ปุ่มผู้ใช้ต้องรู้ผู้ใช้ก่อนจึงเป็นแท่งหลอก */
.nav-skeleton { display: flex; min-height: 2.95rem; align-items: center; gap: 0.75rem; padding: 0.5rem 0.75rem; }
.nav-skeleton-icon { width: 18px; height: 18px; flex-shrink: 0; border-radius: 5px; }
.nav-skeleton-text { width: 6rem; height: 0.75rem; }
.nav-skeleton:nth-child(3n + 2) .nav-skeleton-text { width: 7.5rem; }
.nav-skeleton:nth-child(3n) .nav-skeleton-text { width: 4.75rem; }
.loading-lead { height: 0.875rem; width: 26rem; max-width: 100%; margin-top: 0.75rem; }
.topbar-skeleton-menu { width: 2.25rem; height: 2.25rem; flex-shrink: 0; }
.topbar-skeleton-pill { width: 6.5rem; height: 2rem; border-radius: 9999px; }
.topbar-skeleton-user { width: 2.25rem; height: 2rem; border-radius: 9999px; }
@media (min-width: 640px) {
  .topbar-skeleton-pill { width: 9rem; }
  .topbar-skeleton-user { width: 11rem; }
}
.boot-error { display: flex; min-height: 100dvh; align-items: center; justify-content: center; background: var(--background); padding: 1.5rem; }

/* ---- หน้า login: hero = โลโก้ + ชื่อ + คำโปรย คั่นด้วยเส้นขอบฟ้า แล้วตามด้วยฟอร์ม ---- */
.login-page { position: relative; display: flex; min-height: 100dvh; align-items: center; justify-content: center; background: var(--background); padding: 2.5rem 1rem; }
.login-theme { position: absolute; top: 1rem; right: 1rem; }
.login-box { width: 100%; max-width: 400px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 1rem; text-align: center; }
.login-brand .brand-mark { width: 3rem; height: 3rem; border-radius: 12px; }
.login-title { font-size: 1.75rem; line-height: 1.2; font-weight: 600; letter-spacing: -0.03em; }
.login-subtitle { margin-top: 0.375rem; font-size: 0.875rem; line-height: 1.4286; color: var(--muted-foreground); }
.login-horizon { margin: 1.5rem 0; }
.login-card { padding: 1.5rem; }
.login-card-title { margin-bottom: 1.25rem; font-size: 1rem; line-height: 1.375; font-weight: 600; }
.divider { margin: 1.25rem 0; display: flex; align-items: center; gap: 0.75rem; font-size: 0.75rem; line-height: 1.3333; color: var(--muted-foreground); }
.divider-line { height: 1px; flex: 1; background: var(--border); }
@media (min-width: 640px) {
  .login-card { padding: 1.75rem; }
}

/* == utilities ==
 * ชื่อเหมือน Tailwind เพื่อให้แปลงจากโค้ด React เดิมได้ตรง ๆ — มีเฉพาะที่ใช้จริง (อยากได้เพิ่มให้เพิ่มที่นี่ พร้อมแก้รายการใน README)
 * วางไว้ท้ายสุดจึงชนะคลาสของคอมโพเนนต์ที่ specificity เท่ากัน (เช่น size-8 ทับ btn-icon)
 */
.block { display: block; }
.inline { display: inline; }
.inline-flex { display: inline-flex; }
.flex { display: flex; }
.grid { display: grid; }
.contents { display: contents; }
.hidden { display: none; }
.relative { position: relative; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; }
.shrink-0 { flex-shrink: 0; }
.self-start { align-self: flex-start; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.25rem; }
.gap-1\.5 { gap: 0.375rem; }
.gap-2 { gap: 0.5rem; }
.gap-2\.5 { gap: 0.625rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-5 { gap: 1.25rem; }
.gap-6 { gap: 1.5rem; }
.gap-x-3 { column-gap: 0.75rem; }
.gap-x-4 { column-gap: 1rem; }
.gap-y-1 { row-gap: 0.25rem; }
.gap-y-2 { row-gap: 0.5rem; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.m-0 { margin: 0; }
.mx-auto { margin-inline: auto; }
.ml-auto { margin-left: auto; }
.mt-auto { margin-top: auto; }
.mt-0\.5 { margin-top: 0.125rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-1\.5 { margin-top: 0.375rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.25rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.mb-6 { margin-bottom: 1.5rem; }
.p-0 { padding: 0; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.px-2 { padding-inline: 0.5rem; }
.px-2\.5 { padding-inline: 0.625rem; }
.px-3 { padding-inline: 0.75rem; }
.py-1 { padding-block: 0.25rem; }
.py-2 { padding-block: 0.5rem; }
.w-full { width: 100%; }
.w-fit { width: fit-content; }
.w-auto { width: auto; }
.w-32 { width: 8rem; }
.w-52 { width: 13rem; }
.w-56 { width: 14rem; }
.w-64 { width: 16rem; }
.min-w-0 { min-width: 0; }
.max-w-full { max-width: 100%; }
.max-w-160 { max-width: 160px; }
.max-w-240 { max-width: 240px; }
.h-4 { height: 1rem; }
.h-6 { height: 1.5rem; }
.h-7 { height: 1.75rem; }
.h-9 { height: 2.25rem; }
.h-12 { height: 3rem; }
.h-14 { height: 3.5rem; }
.h-16 { height: 4rem; }
.h-24 { height: 6rem; }
.h-28 { height: 7rem; }
.h-36 { height: 9rem; }
.h-40 { height: 10rem; }
.h-64 { height: 16rem; }
.h-96 { height: 24rem; }
.size-3 { width: 0.75rem; height: 0.75rem; }
.size-3\.5 { width: 0.875rem; height: 0.875rem; }
.size-4 { width: 1rem; height: 1rem; }
.size-5 { width: 1.25rem; height: 1.25rem; }
.size-6 { width: 1.5rem; height: 1.5rem; }
.size-8 { width: 2rem; height: 2rem; }
.size-9 { width: 2.25rem; height: 2.25rem; }
.size-10 { width: 2.5rem; height: 2.5rem; }
.size-12 { width: 3rem; height: 3rem; }
.size-18 { width: 18px; height: 18px; }
.text-xs { font-size: 0.75rem; line-height: 1.3333; }
.text-sm { font-size: 0.875rem; line-height: 1.4286; }
.text-base { font-size: 1rem; line-height: 1.5; }
.text-lg { font-size: 1.125rem; line-height: 1.5556; }
.text-xl { font-size: 1.25rem; line-height: 1.4; }
.text-2xl { font-size: 1.5rem; line-height: 1.3333; }
.text-11 { font-size: 11px; }
.text-13 { font-size: 13px; }
.text-15 { font-size: 15px; }
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.leading-none { line-height: 1; }
.leading-snug { line-height: 1.375; }
.tracking-tight { letter-spacing: -0.025em; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whitespace-nowrap { white-space: nowrap; }
.whitespace-pre-line { white-space: pre-line; }
.break-all { word-break: break-all; }
.select-none { user-select: none; }
/* ตัวเลขในตาราง/แกนให้ตรงหลักกัน (ตัวเลขใหญ่แบบ stat ใช้ตัวเลขปกติ ไม่ใช้คลาสนี้) */
.num { font-variant-numeric: tabular-nums; }
.text-foreground { color: var(--foreground); }
.text-muted-foreground { color: var(--muted-foreground); }
.text-primary { color: var(--primary-ink); }
.text-secondary-foreground { color: var(--secondary-foreground); }
.text-negative-ink { color: var(--negative-ink); }
.text-positive-ink { color: var(--positive-ink); }
.text-gold-foreground { color: var(--gold-foreground); }
.bg-card { background: var(--card); }
.bg-muted { background: var(--muted); }
.bg-primary-soft { background: var(--primary-soft); }
.border-0 { border-width: 0; }
.shadow-none { box-shadow: none; }
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: 9999px; }
.animate-spin { animation: spin 1s linear infinite; }
.animate-pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

@media (min-width: 640px) {
  .sm\:hidden { display: none; }
  .sm\:block { display: block; }
  .sm\:inline { display: inline; }
  .sm\:inline-flex { display: inline-flex; }
  .sm\:flex { display: flex; }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sm\:w-48 { width: 12rem; }
  .sm\:w-64 { width: 16rem; }
  .sm\:w-72 { width: 18rem; }
}
@media (min-width: 768px) {
  .md\:hidden { display: none; }
  .md\:block { display: block; }
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .lg\:hidden { display: none; }
  .lg\:block { display: block; }
  .lg\:flex { display: flex; }
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .xl\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .xl\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .xl\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .xl\:col-span-2 { grid-column: span 2 / span 2; }
}

/* ---- ผลของ AI ที่ใช้ร่วมกันหลายหน้า: ป้ายประเด็น และเหตุผลสั้น ๆ ของความรู้สึก ---- */
.topic-chip { display: inline-flex; align-items: center; border-radius: 9999px; border: 1px solid var(--border); background: var(--card); padding: 0 0.5rem; font-size: 11px; line-height: 1.6; color: var(--foreground); }
a.topic-chip:hover { border-color: var(--primary); color: var(--primary-ink); }
a.topic-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.sentiment-reason { max-width: 14rem; font-size: 11px; line-height: 1.4; color: var(--muted-foreground); overflow-wrap: anywhere; }

/* ---- Ask AI: ตัวแชต (.chat) ใช้ทั้งในแผงด้านขวา (.chat-panel เปิดได้จากทุกหน้า) และหน้าเต็ม (css/pages/chat.css) ---- */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 38; /* ใต้ drawer เมนูมือถือ (39–40) และ dialog (50) */
  display: flex;
  width: 100%;
  max-width: 26rem;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow-pop);
  animation: fade-in 0.15s ease-out;
}
.chat-panel[hidden] { display: none; }
@media (min-width: 1280px) {
  /* จอกว้าง: เว้นคอลัมน์ขวาให้แผง เนื้อหาและแถบบนหดเข้ามา ไม่ถูกแผงบัง */
  .app-shell[data-chat='open'] { grid-template-columns: var(--sidebar-width) minmax(0, 1fr) 26rem; }
  .chat-panel { box-shadow: none; }
}
.chat-toggle[aria-expanded='true'] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); }

.chat { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; border-bottom: 1px solid var(--border); padding: 0.625rem 0.75rem 0.625rem 1rem; }
.chat-title { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9375rem; line-height: 1.4; font-weight: 600; color: var(--primary-ink); }
.chat-actions { display: flex; align-items: center; gap: 0.125rem; }
.chat-body { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.chat-main { display: flex; min-height: 0; flex: 1; flex-direction: column; }

.chat-log { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 0.875rem; overflow-y: auto; overscroll-behavior: contain; padding: 1rem; }
.chat-log:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.chat-intro { display: grid; gap: 0.75rem; }
.chat-hello { border-radius: var(--radius-md); background: var(--primary-soft); padding: 0.75rem 0.875rem; font-size: 0.875rem; line-height: 1.6; color: var(--foreground); }
.chat-suggest-title { font-size: 0.75rem; font-weight: 600; color: var(--muted-foreground); }
.chat-suggestions { display: grid; gap: 0.375rem; }
.chat-suggestion {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--foreground);
  transition: border-color 0.15s, background-color 0.15s;
}
.chat-suggestion:hover { border-color: var(--primary); background: var(--accent); }
.chat-suggestion:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.chat-notice { display: flex; align-items: flex-start; gap: 0.5rem; border-radius: var(--radius-md); background: var(--gold-soft); padding: 0.625rem 0.75rem; font-size: 0.8125rem; line-height: 1.55; color: var(--gold-foreground); }
.chat-notice .icon { margin-top: 0.15rem; flex: none; }

.chat-msg { display: flex; max-width: 100%; flex-direction: column; gap: 0.375rem; }
.chat-msg-user { align-items: flex-end; }
.chat-msg-assistant { align-items: flex-start; }
.chat-author { font-size: 0.6875rem; font-weight: 600; color: var(--primary-ink); }
.chat-bubble { max-width: 92%; border-radius: var(--radius-lg); padding: 0.5rem 0.75rem; font-size: 0.875rem; line-height: 1.65; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-msg-user .chat-bubble { border-bottom-right-radius: var(--radius-sm); background: var(--primary); color: var(--primary-foreground); }
.chat-msg-assistant .chat-bubble { border-bottom-left-radius: var(--radius-sm); background: var(--muted); color: var(--foreground); }
.chat-msg.is-error .chat-bubble { background: var(--negative-soft); color: var(--negative-ink); }
.chat-answer { display: grid; gap: 0.5rem; white-space: normal; }
.chat-answer[hidden] { display: none; }
.chat-msg.is-streaming .chat-answer { white-space: pre-wrap; }
.chat-list { display: grid; gap: 0.25rem; padding-left: 1.25rem; }
ul.chat-list { list-style: disc; }
ol.chat-list { list-style: decimal; }
.chat-inline-link { font-weight: 500; color: var(--primary-ink); text-decoration: underline; text-underline-offset: 2px; }
.chat-inline-link:hover { color: var(--primary-ink); }

.chat-tools { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chat-tool { display: inline-flex; max-width: 100%; align-items: center; gap: 0.25rem; border-radius: 9999px; border: 1px solid var(--border); background: var(--card); padding: 0 0.5rem; font-size: 0.6875rem; line-height: 1.7; color: var(--muted-foreground); }
.chat-tool.is-failed { border-color: color-mix(in srgb, var(--gold) 40%, transparent); background: var(--gold-soft); color: var(--gold-foreground); }
.chat-activity { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; font-size: 0.8125rem; line-height: 1.5; color: var(--muted-foreground); }
.chat-activity-detail { flex-basis: 100%; padding-left: 1.25rem; font-size: 0.75rem; }
.chat-warning { display: flex; max-width: 92%; align-items: flex-start; gap: 0.375rem; border-radius: var(--radius-md); background: var(--gold-soft); padding: 0.375rem 0.625rem; font-size: 0.75rem; line-height: 1.5; color: var(--gold-foreground); }
.chat-warning .icon { margin-top: 0.1rem; flex: none; }
.chat-links { max-width: 92%; }
.chat-links-title { font-size: 0.6875rem; font-weight: 600; color: var(--muted-foreground); }
.chat-links-list { margin-top: 0.25rem; display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chat-link { display: inline-flex; max-width: 100%; align-items: center; gap: 0.25rem; border-radius: 9999px; border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); background: var(--primary-soft); padding: 0.0625rem 0.5rem; font-size: 0.75rem; line-height: 1.6; color: var(--primary-ink); overflow-wrap: anywhere; }
.chat-link:hover { border-color: var(--primary); }
.chat-link:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }

.chat-form { display: flex; align-items: flex-end; gap: 0.5rem; border-top: 1px solid var(--border); padding: 0.75rem 0.75rem 0.25rem; }
.chat-input { height: auto; min-height: 2.75rem; max-height: 9rem; resize: none; line-height: 1.5; }
.chat-send { flex: none; }
.chat-hint { padding: 0.125rem 0.875rem 0.625rem; font-size: 0.6875rem; line-height: 1.5; color: var(--muted-foreground); }

.chat-history { max-height: 40%; overflow-y: auto; border-bottom: 1px solid var(--border); background: var(--muted); padding: 0.625rem 0.75rem; }
.chat-history[hidden] { display: none; }
.chat-history-title { margin-bottom: 0.375rem; font-size: 0.75rem; font-weight: 600; color: var(--muted-foreground); }
.chat-history-empty { font-size: 0.8125rem; color: var(--muted-foreground); }
.chat-history-list { display: grid; gap: 0.125rem; }
.chat-history-row { display: flex; align-items: center; gap: 0.125rem; border-radius: var(--radius-md); }
.chat-history-row:hover, .chat-history-row.is-active { background: var(--accent); }
.chat-history-item { display: flex; min-width: 0; flex: 1; flex-direction: column; align-items: flex-start; border-radius: var(--radius-md); padding: 0.375rem 0.5rem; text-align: left; }
.chat-history-item:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.chat-history-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; line-height: 1.5; font-weight: 500; }
.chat-history-row.is-active .chat-history-name { color: var(--primary-ink); }
.chat-history-time { font-size: 0.6875rem; color: var(--muted-foreground); }
.chat-history-delete { flex: none; color: var(--muted-foreground); }
