/* core - design system ที่ทุกโมดูลใช้ร่วมกัน
   สไตล์เฉพาะของโมดูลไหน ให้ไปอยู่ใน entry.css / report.css / setup.css
   ฟอนต์ Kanit แนบไฟล์มาในโปรเจกต์ (fonts.css) ไม่ดึงจาก CDN หรือ Google Fonts */

:root {
  --oee-bg: #f4f6f8;
  --oee-surface: #ffffff;
  --oee-line: #dfe4ea;
  --oee-text: #1f2933;
  --oee-muted: #6b7684;
  --oee-accent: #0b6bcb;
  --oee-accent-dark: #08529c;
  --oee-ok: #1a7f4b;
  --oee-warn: #b06000;
  --oee-danger: #c02626;
  --oee-sel: #e6f0fb;
  --oee-radius: 8px;

  /* Kanit เป็นฟอนต์หลักของทั้งระบบ (ไฟล์อยู่ใน static/fonts/kanit) */
  --oee-font: 'Kanit', "Segoe UI", Tahoma, "Leelawadee UI", sans-serif;

  /* ⚠️ Kanit ไม่มี feature 'tnum' และตัวเลขกว้างไม่เท่ากัน (0 = 651 หน่วย
     แต่ 1 = 319) font-variant-numeric: tabular-nums จึงไม่มีผลกับ Kanit
     คอลัมน์ตัวเลขในตารางจะขยับไปมาอ่านยาก -> เซลล์ที่ต้องเรียงตรงกันใช้
     ฟอนต์นี้แทน ส่วนเลขเดี่ยว ๆ อย่าง KPI ยังใช้ Kanit เพราะไม่ต้องเรียงคอลัมน์ */
  --oee-font-num: Consolas, "Segoe UI", ui-monospace, monospace;
}

* { box-sizing: border-box; }

/* ⚠️ ห้ามลบ - attribute hidden ทำงานผ่านกฎ [hidden]{display:none} ของเบราว์เซอร์
   ซึ่ง "แพ้" ทุก rule ใน stylesheet นี้ที่ตั้ง display เอง บั๊กหน้า login ค้าง
   ทับหน้าแอปเกิดจากตรงนี้พอดี (.oee-center ตั้ง display:flex ทับ [hidden])
   กฎนี้ทำให้ el.hidden = true เชื่อถือได้เสมอ ไม่ว่า class จะตั้ง display อะไร */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--oee-bg);
  color: var(--oee-text);
  font-family: var(--oee-font);
  font-size: 15px;
}

/* ==================== หน้าเข้าสู่ระบบ ==================== */
.oee-center {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.oee-loginbox {
  background: var(--oee-surface);
  border: 1px solid var(--oee-line);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 6px 24px rgba(20, 30, 40, .08);
}
/* โลโก้ในหน้าเข้าสู่ระบบ - ใหญ่กว่าใน navbar เพราะมีที่ให้อ่านชื่อบริษัทได้จริง */
.oee-login-logo { display: block; width: 100%; max-width: 240px; height: auto; margin: 0 auto 18px; }
.oee-loginbox h1 { margin: 0; font-size: 22px; }
.oee-loginbox .oee-sub { margin: 4px 0 20px; color: var(--oee-muted); font-size: 14px; }
.oee-loginbox label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--oee-muted); }
.oee-loginbox input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--oee-line);
  border-radius: var(--oee-radius);
  background: #fff;
  color: var(--oee-text);
}
.oee-loginbox input:focus {
  outline: none;
  border-color: var(--oee-accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 203, .15);
}
.oee-err {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: var(--oee-radius);
  background: #fdecec;
  color: var(--oee-danger);
  font-size: 13px;
}

/* ==================== ปุ่ม ==================== */
.oee-btn {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: var(--oee-radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: #eceff3;
  color: var(--oee-text);
}
.oee-btn:hover { filter: brightness(.97); }
.oee-btn-primary { background: var(--oee-accent); color: #fff; }
.oee-btn-primary:hover { background: var(--oee-accent-dark); }
.oee-btn-danger { background: #fdecec; color: var(--oee-danger); border-color: #f6cccc; }
.oee-btn-ghost { background: transparent; border-color: var(--oee-line); }
.oee-btn-sm { padding: 6px 10px; font-size: 13px; }
.oee-btn-full { width: 100%; }
.oee-btn:disabled { opacity: .55; cursor: default; }

.oee-kbd {
  display: inline-block;
  font-size: 11px;
  font-family: Consolas, monospace;
  padding: 1px 5px;
  border: 1px solid rgba(0, 0, 0, .18);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .25);
}

/* ==================== เปลือก: navbar ==================== */
.oee-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--oee-surface);
  border-bottom: 1px solid var(--oee-line);
  flex-wrap: wrap;
}
.oee-brand { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
/* โลโก้เป็น jpg พื้นขาว - navbar กับกล่อง login ก็พื้นขาว (--oee-surface) จึงกลืนพอดี
   ถ้าเปลี่ยนสีพื้นตรงนี้ต้องเปลี่ยนไปใช้ไฟล์โลโก้แบบพื้นโปร่งด้วย */
.oee-logo { height: 26px; width: auto; display: block; }
.oee-brand-name { font-weight: 600; font-size: 16px; }
.oee-brand-sep { width: 1px; height: 24px; background: var(--oee-line); }
.oee-nav-mods { display: flex; gap: 4px; flex-wrap: wrap; }

/* เมนูโมดูล - ตัวที่กำลังเปิดอยู่ต้องเห็นชัดว่าอยู่หน้าไหน */
.oee-modbtn {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border: 1px solid var(--oee-line);
  background: transparent;
  border-radius: var(--oee-radius);
  cursor: pointer;
  color: var(--oee-muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.oee-modbtn:hover { background: var(--oee-bg); }
.oee-modbtn-on {
  background: var(--oee-accent);
  border-color: var(--oee-accent);
  color: #fff;
  font-weight: 600;
}
/* ตัวเลขงานค้างเกาะบนเมนู - เห็นได้จากทุกโมดูลโดยไม่ต้องยัด KPI ลง navbar */
.oee-modbadge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--oee-danger);
  color: #fff;
  text-align: center;
}
.oee-modbtn-on .oee-modbadge { background: rgba(255, 255, 255, .28); }

.oee-who {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--oee-muted);
}

/* ==================== เปลือก: พื้นที่ของโมดูล ==================== */
.oee-page { padding: 0 0 28px; }

/* หัวเรื่องประจำโมดูล - บอกว่าอยู่หน้าไหนและหน้านี้มีไว้ทำอะไร */
.oee-modhead {
  padding: 16px 16px 14px;
  background: var(--oee-surface);
  border-bottom: 1px solid var(--oee-line);
}
.oee-modhead h1 { margin: 0; font-size: 19px; }
.oee-modhead p { margin: 3px 0 0; font-size: 13px; color: var(--oee-muted); }

.oee-body { padding: 14px 16px 0; display: flex; flex-direction: column; gap: 14px; }

/* ==================== แถบเครื่องมือ ==================== */
.oee-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--oee-surface);
  border-bottom: 1px solid var(--oee-line);
  flex-wrap: wrap;
}
.oee-tabs { display: flex; gap: 4px; }
.oee-tab {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border: 1px solid var(--oee-line);
  background: transparent;
  border-radius: var(--oee-radius);
  cursor: pointer;
  color: var(--oee-muted);
}
.oee-tab-on { background: #2b3947; border-color: #2b3947; color: #fff; font-weight: 600; }
.oee-select {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--oee-line);
  border-radius: var(--oee-radius);
  background: #fff;
  color: var(--oee-text);
}
.oee-select-sm { padding: 6px 8px; font-size: 13px; }
.oee-hint { font-size: 12px; color: var(--oee-muted); }
.oee-spacer { flex: 1; }
.oee-inline { font-size: 13px; color: var(--oee-muted); display: inline-flex; align-items: center; gap: 6px; }

/* ==================== การ์ด / หัวข้อ ==================== */
.oee-card {
  background: var(--oee-surface);
  border: 1px solid var(--oee-line);
  border-radius: 10px;
  padding: 16px 18px 18px;
}
.oee-h2 { margin: 0 0 14px; font-size: 16px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.oee-h2-note { font-size: 12px; font-weight: 400; color: var(--oee-muted); }
.oee-h3 { margin: 22px 0 8px; font-size: 14px; }

/* ==================== ตาราง ==================== */
.oee-tablewrap { overflow-x: auto; }
table.oee-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.oee-table th {
  position: sticky;
  top: 0;
  background: #f7f9fb;
  border-bottom: 1px solid var(--oee-line);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--oee-muted);
  white-space: nowrap;
}
table.oee-table td { padding: 9px 12px; border-bottom: 1px solid #eef1f4; white-space: nowrap; }
table.oee-table tbody tr:hover { background: #fafcfe; }
table.oee-table tbody tr.oee-norow { cursor: default; }
table.oee-table tbody tr.oee-norow:hover { background: transparent; }
table.oee-table tbody tr.oee-row-off { opacity: .5; }
table.oee-table tbody tr.oee-row-off:hover { opacity: .75; }
.oee-dur { font-family: var(--oee-font-num); font-variant-numeric: tabular-nums; font-weight: 700; }
.oee-dur-big { color: var(--oee-danger); }
.oee-num { font-family: var(--oee-font-num); font-variant-numeric: tabular-nums; color: var(--oee-muted); font-size: 13px; }

/* ==================== badge / สถานะว่าง ==================== */
.oee-badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 20px; border: 1px solid; }
.oee-badge-planned { background: #eef4ff; color: #2a4d8f; border-color: #cddcf7; }
.oee-badge-unplanned { background: #fdecec; color: var(--oee-danger); border-color: #f6cccc; }
.oee-badge-drift { background: #fff5e6; color: var(--oee-warn); border-color: #f0d7ad; }

.oee-empty { padding: 34px 20px; text-align: center; color: var(--oee-muted); font-size: 14px; }
.oee-loading { padding: 34px 20px; text-align: center; color: var(--oee-muted); font-size: 14px; }

/* ==================== KPI ==================== */
.oee-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.oee-tile { border: 1px solid var(--oee-line); border-radius: var(--oee-radius); padding: 12px 14px; background: var(--oee-bg); }
.oee-tile-label { font-size: 12px; color: var(--oee-muted); }
.oee-tile-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; }
.oee-tile-unit { font-size: 13px; font-weight: 400; color: var(--oee-muted); margin-left: 4px; }
.oee-tile-hint { font-size: 12px; color: var(--oee-muted); }
.oee-tile-big .oee-tile-value { font-size: 34px; }
.oee-tile-ok { background: #eaf6ee; border-color: #bfe0cb; }
.oee-tile-ok .oee-tile-value { color: var(--oee-ok); }
.oee-tile-warn { background: #fff5e6; border-color: #f0d7ad; }
.oee-tile-warn .oee-tile-value { color: var(--oee-warn); }
.oee-tile-bad { background: #fdecec; border-color: #f6cccc; }
.oee-tile-bad .oee-tile-value { color: var(--oee-danger); }

/* ==================== หมายเหตุ / คำเตือน ==================== */
.oee-note {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--oee-radius);
  background: var(--oee-bg);
  border: 1px solid var(--oee-line);
  font-size: 13px;
  color: var(--oee-muted);
  line-height: 1.55;
}
.oee-note b { color: var(--oee-text); }
.oee-note-warn { background: #fff5e6; border-color: #f0d7ad; color: #7a4a00; }
.oee-note-warn b { color: #5c3800; }
.oee-note-bad { background: #fdecec; border-color: #f6cccc; color: #8f1f1f; }
.oee-note-bad b { color: #6d1717; }
.oee-ul { margin: 8px 0 0; padding-left: 20px; line-height: 1.7; }
.oee-ul li { margin-bottom: 3px; }

/* ==================== ฟอร์ม ==================== */
.oee-field { display: block; margin-bottom: 14px; }
.oee-field > span:first-child { display: block; font-size: 13px; color: var(--oee-muted); margin-bottom: 5px; }
.oee-req { color: var(--oee-danger); }
.oee-help { display: block; font-size: 12px; color: var(--oee-muted); margin-top: 5px; }

.oee-in {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  width: 100%;
  min-width: 90px;
  border: 1px solid var(--oee-line);
  border-radius: 6px;
  background: #fff;
  color: var(--oee-text);
}
.oee-in:focus { outline: none; border-color: var(--oee-accent); box-shadow: 0 0 0 2px rgba(11, 107, 203, .15); }
.oee-in-sm { min-width: 120px; width: auto; }
.oee-in-xs { min-width: 62px; width: 72px; }

/* ==================== toast ==================== */
.oee-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: 380px;
  padding: 12px 16px;
  border-radius: var(--oee-radius);
  font-size: 14px;
  color: #fff;
  background: #2b3947;
  box-shadow: 0 6px 22px rgba(20, 30, 40, .22);
}
.oee-toast-ok { background: var(--oee-ok); }
.oee-toast-err { background: var(--oee-danger); }

/* ==================== จอเล็ก ==================== */
@media (max-width: 640px) {
  .oee-nav { gap: 8px; }
  .oee-who { width: 100%; margin-left: 0; }
}
