/* theme.css — พื้นผิวกลางของทุกหน้า (ดู DESIGN.md "The Clear Ledger")
   โหลดหลัง <style> ของแต่ละหน้า จึงทับของเดิมได้ */

/* สีจากเว็บหลัก brandlegacythailand.com */
:root {
  --ink: #1f2937;
  --ink-soft: #374151;
  --ink-muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f3f4f6;
  --canvas: #fafafc;
  --surface: #ffffff;
  --harbor-600: #2563eb;
  --harbor-700: #1d4ed8;
  --harbor-800: #0f172a;
}

body.app-canvas,
body {
  background: var(--canvas);
  color: var(--ink);
}

/* หัวเว็บสีขาว ตัวหนังสือเข้ม น้ำเงินเป็นจุดเน้น (เจ้าของ 23/10: หัวเข้มเกินไป)
   markup เดิมทุกหน้าเขียนไว้สำหรับหัวสีเข้ม (text-white, bg-white/10) — แปลงที่นี่ที่เดียว */
header.app-header {
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
  border-bottom: 1px solid var(--line);
}
header.app-header [class*="text-white"]:not([class*="bg-red"]):not([class*="bg-primary"]):not([class*="bg-blue"]) { color: var(--ink) !important; }
header.app-header [class*="text-white/"] { color: var(--ink-muted) !important; }
header.app-header .text-blue-100 { color: var(--ink-muted) !important; }
/* ปุ่มเมนู (หน้าเดิมเขียนไว้เป็น xl:bg-white/10 + xl:hover:bg-white/20) */
header.app-header [class*="bg-white/10"] { background-color: transparent !important; color: var(--ink-soft) !important; }
header.app-header [class*="bg-white/10"]:hover { background-color: var(--line-soft) !important; color: var(--harbor-600) !important; }
/* วงกลมชื่อผู้ใช้ (xl:bg-white/20 ที่ไม่ใช่ตอนชี้เมาส์) และหน้าที่เปิดอยู่ */
header.app-header [class*=" xl:bg-white/20"],
header.app-header [aria-current="page"] { background-color: #eff6ff !important; color: var(--harbor-600) !important; }
header.app-header .shadow-inner { box-shadow: none; border: 1px solid var(--line); }
header.app-header .shadow-md { box-shadow: none; }

/* กล่อง "glass" เดิม = กระจกเบลอ → การ์ดขาวขอบบาง (The Flat Desk Rule) */
.glass {
  background: var(--surface) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--line) !important;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05) !important;
}

/* สไตล์ที่บางหน้าเขียนไว้เอง (แท็บ ปุ่มไล่สี ลายตกแต่ง) → สีชุดเดียวกัน */
.tab-active,
.tab-btn.active {
  background: var(--harbor-600) !important;
  color: #fff !important;
  box-shadow: none !important;
}
.btn-gradient { background: var(--harbor-600) !important; }
.btn-gradient:hover { background: var(--harbor-700) !important; }
.dropdown-item:hover { background: #eff6ff !important; color: var(--harbor-700) !important; }
.stat-income::before,
.stat-expense::before,
.stat-profit::before { background: var(--line-soft) !important; }

/* ปุ่ม Export Excel = ปุ่มรอง (เดิมเขียวทึบทุกหน้า แย่งสายตาจากปุ่มหลัก) */
:is(button, a):has(> .fa-file-excel):not(:disabled) {
  background: #fff !important;
  color: var(--ink) !important;
  border: 1px solid #d1d5db !important;
  box-shadow: none !important;
}
:is(button, a):has(> .fa-file-excel):hover { background: var(--line-soft) !important; }
:is(button, a) > .fa-file-excel { color: #16884a !important; }

/* ไอคอนหน้าหัวข้อการ์ดเป็นเทา — ชื่อหัวข้อบอกเรื่องอยู่แล้ว สีไอคอนหลายสีทำให้หน้าดูสีเยอะ
   (ไอคอนบนพื้นสี เช่น text-white ไม่แตะ) */
:is(h3, h4, h5) > i.fas[class*="text-"]:not([class*="text-white"]),
:is(h3, h4, h5) > i.fa-solid[class*="text-"]:not([class*="text-white"]) { color: #94a3b8 !important; }

/* ส่วนที่เบราว์เซอร์วาดเอง */
::selection { background: #bfdbfe; color: var(--ink); }
:focus-visible { outline: 2px solid var(--harbor-600); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
* { scrollbar-color: #cbd5e1 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9999px; border: 2px solid var(--canvas); }
::-webkit-scrollbar-track { background: transparent; }

/* ตัวเลขในตารางเรียงหลักตรงกัน */
table td, .tabular-nums { font-variant-numeric: tabular-nums; }

/* ลดการเคลื่อนไหวสำหรับคนที่ตั้งค่าไว้ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* หน้าโปรเจกต์: หัวการ์ด "ฝั่งลูกค้า / ฝั่งโรงงาน" (เดิมน้ำเงิน/ม่วงทึบ ตัวหนังสือขาว) */
.side-head { background: #f8fafc; border-bottom: 1px solid var(--line); }
.side-head [class*="text-white"]:not([class*="bg-red"]) { color: var(--ink) !important; }
.side-head [class*="bg-white/"] { background-color: #fff !important; border: 1px solid #d1d5db; color: var(--ink) !important; }
.side-head [class*="bg-white/"]:hover { background-color: var(--line-soft) !important; }
.side-head-sales h3 > i { color: var(--harbor-600) !important; }
.side-head-factory h3 i { color: #64748b !important; }

/* มือถือ: ชื่อบริษัทบนหัวเว็บไม่กินพื้นที่สองบรรทัดใหญ่ */
@media (max-width: 639px) {
  header.app-header h1, header.app-header #headerCompanyName { font-size: 15px !important; line-height: 1.35 !important; }
  header.app-header .py-4 { padding-top: 10px !important; padding-bottom: 10px !important; }
}

/* จอ 1280–1439px: ชื่อบริษัทกว้าง 445px เมนูเหลือที่ไม่พอ ปุ่มออกจากระบบล้นขอบขวา (หน้าเลื่อนข้างได้)
   → ให้ชื่อบริษัทขึ้นบรรทัดใหม่ในกรอบแคบลง และลดช่องไฟระหว่างปุ่มเมนู */
@media (min-width: 1280px) and (max-width: 1535px) {   /* ถึง 1535: ที่ 1440 พอดีปุ่มออกจากระบบยังหลุดขอบจอได้ */
  header.app-header > div > div:first-child { max-width: 22rem; min-width: 0; }
  header.app-header #mobileMenu { gap: 0.25rem !important; }
}

/* ─── SweetAlert (หน้าบัญชี / สต็อก / ตั้งค่า) ให้หน้าตาเดียวกับหน้าต่างกลาง app-dialog.js ───
   การทำงานเหมือนเดิมทุกอย่าง (ฟอร์ม กำลังโหลด ปุ่มสามทาง) — ปรับแค่หน้าตา: Sarabun มุม 16px
   ปุ่มน้ำเงิน/ขาว สูง 44px · ปุ่มที่โค้ดตั้งสีเอง (เช่นแดงตอนลบ) ยังใช้สีนั้น เพราะตั้งเป็น inline style */
.swal2-popup { font-family: 'Sarabun', Inter, sans-serif; border-radius: 16px; padding: 24px; color: var(--ink); }
.swal2-popup.swal2-toast { border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(16, 24, 40, .12); }
.swal2-title { font-size: 18px; font-weight: 700; line-height: 1.4; color: var(--ink); padding: 0; }
.swal2-toast .swal2-title { font-size: 14px; font-weight: 600; }
.swal2-html-container { font-size: 14px; line-height: 1.6; color: var(--ink-soft); margin: 8px 0 0; }
.swal2-actions { gap: 8px; margin-top: 20px; }
.swal2-styled { min-height: 44px; padding: 0 18px; border-radius: 12px; font-size: 14px; font-weight: 600; margin: 0; }
.swal2-styled.swal2-confirm { background-color: var(--harbor-600); }
.swal2-styled.swal2-confirm:hover { background-color: var(--harbor-700); }
.swal2-styled.swal2-cancel { background-color: #fff; color: var(--ink); border: 1px solid var(--line); }
.swal2-styled.swal2-cancel:hover { background-color: var(--line-soft); }
.swal2-styled.swal2-deny { background-color: #fff; color: #b91c1c; border: 1px solid #fecaca; }
.swal2-styled:focus-visible { box-shadow: 0 0 0 3px #93c5fd; }
.swal2-input, .swal2-textarea, .swal2-select { border-radius: 12px; border-color: #d1d5db; font-family: inherit; font-size: 16px; box-shadow: none; }
.swal2-input:focus, .swal2-textarea:focus { border-color: var(--harbor-600); box-shadow: 0 0 0 3px #dbeafe; }
.swal2-icon { transform: scale(.75); margin: 0 auto 4px; }
.swal2-container.swal2-backdrop-show { background: rgba(15, 23, 42, .45); }

/* ─── โฟกัสจากคีย์บอร์ด (audit P2: outline-none 29 จุดไม่มีกรอบโฟกัสเลย) ───
   กดแท็บแล้วต้องเห็นว่าอยู่ที่ปุ่ม/ช่องไหน · เมาส์/นิ้วไม่ขึ้นกรอบ (focus-visible) */
a:focus-visible, button:focus-visible, [role="button"]:focus-visible, summary:focus-visible {
  outline: 3px solid #93c5fd; outline-offset: 2px; border-radius: 8px;
}
input.outline-none:focus-visible, select.outline-none:focus-visible, textarea.outline-none:focus-visible {
  border-color: var(--harbor-600); box-shadow: 0 0 0 3px #dbeafe;
}

/* ─── ผู้ใช้ที่ตั้งเครื่องให้ลดภาพเคลื่อนไหว: หยุดจุดกะพริบ/วงกระเพื่อม (ตัวหมุนตอนโหลดยังหมุน = บอกว่ากำลังทำงาน) ─── */
@media (prefers-reduced-motion: reduce) {
  .animate-ping, .animate-pulse, .animate-bounce { animation: none !important; }
  *, *::before, *::after { transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
