/* ธีมตาม design tokens ใน BUILD_PROMPT.md ข้อ 9 — override ตัวแปร Bootstrap 5.3 */
:root {
  --hait-bg: #F4F5F2;
  --hait-card: #FFFFFF;
  --hait-border: #E2E5E0;
  --hait-border-soft: #EEF0EC;
  --hait-input-border: #C9CEC6;
  --hait-text: #17202B;
  --hait-muted: #5A6472;
  --hait-primary: #0B6B6B;
  --hait-primary-hover: #084E4E;
  --hait-sidebar: #12312F;
  --hait-sidebar-hover: #1C4541;
  --hait-highlight: #E3F0EE;

  --bs-body-font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  --bs-body-bg: var(--hait-bg);
  --bs-body-color: var(--hait-text);
  --bs-secondary-color: var(--hait-muted);
  --bs-border-color: var(--hait-border);
  --bs-border-radius: 8px;
  --bs-border-radius-lg: 12px;
  --bs-link-color: var(--hait-primary);
  --bs-link-color-rgb: 11, 107, 107;
  --bs-link-hover-color: var(--hait-primary-hover);
  --bs-link-hover-color-rgb: 8, 78, 78;
  --bs-primary: var(--hait-primary);
  --bs-primary-rgb: 11, 107, 107;
  --bs-focus-ring-color: rgba(11, 107, 107, .3);
}

body { background: var(--hait-bg); color: var(--hait-text); font-family: var(--bs-body-font-family); }
h1, h2, h3, h4 { color: var(--hait-text); }
.muted { color: var(--hait-muted); }
.fs-13 { font-size: 13px; } .fs-14 { font-size: 14px; } .fs-12 { font-size: 12px; }

/* ---------- โครงหน้า ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  flex: 0 0 248px; width: 248px; background: var(--hait-sidebar); padding: 24px 14px;
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { padding: 0 12px 16px; }
.sidebar .brand-org { font-size: 13px; color: #A9C7C2; }
.sidebar .brand-name { font-size: 18px; font-weight: 600; color: #FFFFFF; line-height: 1.35; }
.navh { font-size: 12px; letter-spacing: .04em; color: #8FB3AD; padding: 16px 12px 6px; }
.nav-link-h {
  display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 12px;
  border-radius: 8px; color: #D5E5E2; text-decoration: none; font-size: 15px;
}
.nav-link-h:hover { background: var(--hait-sidebar-hover); color: #FFFFFF; }
.nav-link-h.on { background: var(--hait-highlight); color: #0B3B38; font-weight: 600; }
.sidebar .me { margin-top: auto; padding: 16px 12px 0; border-top: 1px solid #24504B; color: #D5E5E2; font-size: 14px; }
.sidebar .me a { color: #A9C7C2; }

.main { flex: 1 1 auto; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head .eyebrow { font-size: 14px; color: var(--hait-muted); }
.page-head h1 { margin: 4px 0 0; font-size: 30px; font-weight: 700; }

.topbar { display: none; }

@media (max-width: 991.98px) {
  .app { flex-direction: column; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--hait-sidebar); color: #FFFFFF; padding: 8px 12px; position: sticky; top: 0; z-index: 1030;
  }
  .topbar .title { font-weight: 600; font-size: 16px; }
  .topbar .menu-btn { min-width: 44px; min-height: 44px; border: 1px solid #2F5F5A; border-radius: 8px; background: transparent; color: #FFFFFF; font-size: 20px; }
  .sidebar { position: static; width: 100%; height: auto; flex-basis: auto; display: none; padding: 8px 14px 16px; }
  .sidebar.open { display: flex; }
  .sidebar .brand { display: none; }
  .main { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 24px; }
}

/* ---------- องค์ประกอบ ---------- */
.card-h { background: var(--hait-card); border: 1px solid var(--hait-border); border-radius: 12px; padding: 20px; }
.card-h h2 { font-size: 20px; margin: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; color: var(--hait-muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--hait-border); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--hait-border-soft); vertical-align: top; }
.tbl-wrap { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.g { background: #E2F2E7; color: #1F6B3A; }
.pill.y { background: #FFF1D1; color: #7A4F00; }
.pill.r { background: #FBE4E1; color: #9B2316; }
.pill.n { background: #ECEEEA; color: #4A5360; }
.pill.pP { background: #E4ECF8; color: #234C88; }
.pill.pD { background: #E3F0EE; color: #0B5A5A; }
.pill.pC { background: #FFF1D1; color: #7A4F00; }
.pill.pA { background: #EFE7F8; color: #5B3291; }
.risk-low { background: #D6EDDC; } .risk-medium { background: #FBE7B5; } .risk-high { background: #F7CFAE; } .risk-veryhigh { background: #F2B8B0; }

.btn-h, .btn-h2 {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 8px; font: inherit; font-size: 15px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-h { border: 1px solid var(--hait-primary); background: var(--hait-primary); color: #FFFFFF; }
.btn-h:hover { background: var(--hait-primary-hover); border-color: var(--hait-primary-hover); color: #FFFFFF; }
.btn-h2 { border: 1px solid var(--hait-input-border); background: #FFFFFF; color: var(--hait-text); font-weight: 500; padding: 0 16px; }
.btn-h2:hover { background: #F7F8F6; color: var(--hait-text); }
.btn-h[disabled], .btn-h2[disabled] { opacity: .55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--hait-muted); }
.field input, .field select, .field textarea, .input-h {
  min-height: 44px; border: 1px solid var(--hait-input-border); border-radius: 8px; padding: 0 12px;
  font: inherit; font-size: 15px; background: #FFFFFF; color: var(--hait-text);
}
.field textarea { padding: 10px 12px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(11, 107, 107, .35); outline-offset: 1px; border-color: var(--hait-primary); }

.bar { height: 8px; background: #E8EBE6; border-radius: 99px; overflow: hidden; position: relative; display: block; }
.bar > .fill { display: block; height: 100%; background: var(--hait-primary); }
.bar > .tgt { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--hait-text); }

.demo-banner { background: #FFF8E6; border: 1px solid #F0D9A0; color: #6B4500; border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.flag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: #FFF1D1; color: #7A4F00; font-weight: 500; }

/* ต้นไม้แผน */
.tog { display: flex; width: 100%; align-items: center; gap: 14px; min-height: 64px; padding: 12px 16px; border: 0; background: #FFFFFF; font: inherit; color: var(--hait-text); text-align: left; cursor: pointer; }
.tog:hover { background: #F7F8F6; }
.tog .no { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--hait-highlight); color: #0B5A5A; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.tog .chev { flex: none; width: 24px; text-align: center; font-size: 18px; color: var(--hait-muted); transition: transform .15s; }
.tog[aria-expanded="true"] .chev { transform: rotate(90deg); }
.tree-body { border-top: 1px solid var(--hait-border); padding: 8px 16px 16px 70px; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 575.98px) { .tree-body { padding-left: 16px; } }
.tree-proj { padding: 12px 0; border-bottom: 1px solid var(--hait-border-soft); }
.tree-proj:last-child { border-bottom: 0; }
.vision { background: var(--hait-sidebar); border-color: var(--hait-sidebar); color: #FFFFFF; padding: 18px 22px; }
.vision .chip { background: var(--hait-sidebar-hover); border-radius: 6px; padding: 4px 10px; font-size: 13px; }

a:focus-visible, button:focus-visible { outline: 3px solid #5FB3AE; outline-offset: 2px; }

/* ---------- ผู้ใช้และสิทธิ์ (Users.dc.html) ---------- */
.pill.b { background: #E4ECF8; color: #234C88; }
.sel { min-height: 44px; border: 1px solid var(--hait-input-border); border-radius: 8px; padding: 0 10px; font: inherit; font-size: 14px; background: #FFFFFF; color: var(--hait-text); }
.av { width: 36px; height: 36px; border-radius: 50%; background: var(--hait-highlight); color: #0B5A5A; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none; }
.tbl td.ck { text-align: center; color: #1F6B3A; font-weight: 700; }
.tbl td.no { text-align: center; color: #8A938D; }
.pick { position: relative; min-width: 220px; }
.pick > summary { display: flex; align-items: center; cursor: pointer; list-style: none; }
.pick > summary::-webkit-details-marker { display: none; }
.pick > summary::after { content: "▾"; margin-left: auto; padding-left: 8px; color: var(--hait-muted); }
.pick-list { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; width: 340px; max-width: 80vw; max-height: 320px; overflow: auto; background: #FFFFFF; border: 1px solid var(--hait-border); border-radius: 10px; box-shadow: 0 8px 24px rgba(23, 32, 43, .12); padding: 6px; }
.pick-list.static { position: static; width: auto; max-width: none; box-shadow: none; }
.pick-list label { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-radius: 6px; font-size: 14px; cursor: pointer; line-height: 1.4; }
.pick-list label:hover { background: #F7F8F6; }
.pick-list input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.audit-json { font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 0; max-width: 360px; color: var(--hait-text); }
.sidebar .nav-link-h .pill { margin-left: auto; }
.nav-link-h { display: flex; align-items: center; }

/* ---------- กำหนดรอบ KPI (KpiCycles.dc.html) ---------- */
.tl { min-width: 760px; }
.tl-row { display: grid; grid-template-columns: 150px repeat(12, minmax(0, 1fr)); align-items: center; min-height: 44px; border-bottom: 1px solid var(--hait-border-soft); }
.tl-row:last-child { border-bottom: 0; }
.tl-head { font-size: 12px; color: var(--hait-muted); border-bottom: 1px solid var(--hait-border); min-height: 0; padding-bottom: 6px; }
.tl-name { font-size: 14px; font-weight: 600; }
.tl-cell { display: block; margin: 0 2px; padding: 4px 8px; border-radius: 6px; font-size: 12px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 28px; line-height: 20px; }
.tl-cell.st-draft { background: #ECEEEA; color: #4A5360; }
.tl-cell.st-open { background: #E2F2E7; color: #1F6B3A; }
.tl-cell.st-closed { background: #FFF1D1; color: #7A4F00; }
.tl-cell.st-locked { background: #E4ECF8; color: #234C88; }
.tl-cell:hover { filter: brightness(.96); }
.tl-cell.sel-on { outline: 2px solid var(--hait-primary); outline-offset: -2px; font-weight: 600; }
.period-panel { background: #F7F8F6; border: 1px solid var(--hait-border); border-radius: 10px; padding: 14px 16px; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 8px; background: #F7F8F6; border: 1px solid var(--hait-border); border-radius: 10px; padding: 10px 12px; }

/* ---------- กรอกผล KPI (KpiEntry.dc.html) ---------- */
.entry-grid { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 991.98px) { .entry-grid { grid-template-columns: 1fr; } }
.entry-list { padding: 14px; max-height: calc(100vh - 160px); overflow-y: auto; position: sticky; top: 16px; }
@media (max-width: 991.98px) { .entry-list { position: static; max-height: 360px; } }
.entry-list .grp { font-size: 12px; font-weight: 600; color: var(--hait-muted); padding: 12px 6px 4px; }
.entry-list .grp-r { color: #9B2316; }
.task { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 48px; padding: 8px 10px; border-radius: 8px; color: var(--hait-text); text-decoration: none; font-size: 14px; line-height: 1.4; }
.task:hover { background: #F7F8F6; color: var(--hait-text); }
.task.on { background: var(--hait-highlight); font-weight: 600; }
.calc-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; align-items: end; }
.calc-row input { font-size: 18px; }
.result-box { background: #F7F8F6; border-radius: 10px; padding: 8px 14px; min-height: 64px; }
.result-value { font-size: 26px; font-weight: 700; }
.defs summary { cursor: pointer; color: var(--hait-primary); font-size: 14px; min-height: 32px; }
.trend { position: relative; display: flex; align-items: flex-end; gap: 12px; height: 200px; padding: 0 4px; border-bottom: 1px solid var(--hait-border); }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; height: 100%; }
.trend-bar { width: 100%; max-width: 56px; border-radius: 6px 6px 0 0; background: #A9C7C2; }
.trend-bar.cur { background: var(--hait-primary); }
.trend-target { position: absolute; left: 0; right: 0; border-top: 2px dashed #9B2316; pointer-events: none; }
.trend-target span { position: absolute; right: 0; top: -20px; font-size: 12px; color: #9B2316; background: #FFFFFF; padding: 0 4px; }
.evid { border: 1px dashed #8A938D; border-radius: 10px; padding: 12px 14px; }
fieldset[disabled] input, fieldset[disabled] textarea { background: #F7F8F6; }

/* ---------- หน้ามือถือ (MobileEntry.dc.html) ---------- */
.m-body { min-height: 100vh; display: flex; flex-direction: column; }
.m-head { background: var(--hait-sidebar); color: #FFFFFF; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; z-index: 10; }
.m-form { flex: 1; display: flex; flex-direction: column; }
.m-main { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 560px; width: 100%; margin: 0 auto; }
.m-card { background: #FFFFFF; border: 1px solid var(--hait-border); border-radius: 14px; padding: 16px; }
.m-field input { min-height: 48px; font-size: 18px; border-radius: 10px; }
.m-field textarea { border-radius: 10px; }
.m-result { display: flex; align-items: center; justify-content: space-between; background: #F7F8F6; border-radius: 10px; padding: 10px 12px; }
.m-evid { border: 1px dashed #8A938D; border-radius: 10px; padding: 12px; text-align: center; }
.m-foot { position: sticky; bottom: 0; background: #FFFFFF; border-top: 1px solid var(--hait-border); padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.m-foot .btn-h, .m-foot .btn-h2 { min-height: 50px; border-radius: 10px; }
.task > span:first-child, .kpi-name { white-space: pre-line; }

/* ---------- งบประมาณ / ความเสี่ยง / หลักฐาน (M6) ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat { font-size: 32px; font-weight: 700; line-height: 1.2; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.qchart { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.qcol { display: flex; flex-direction: column; }
.qbars { display: flex; align-items: flex-end; justify-content: center; gap: 8px; height: 180px; border-bottom: 1px solid var(--hait-border); }
.qbar { width: 36%; max-width: 48px; border-radius: 6px 6px 0 0; min-height: 2px; }
.qbar.plan { background: #C9CEC6; }
.qbar.act { background: var(--hait-primary); }
.cov-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 48px; gap: 12px; align-items: center; min-height: 32px; }
@media (max-width: 575.98px) { .cov-row { grid-template-columns: 1fr 80px 40px; } }
.heat { display: grid; grid-template-columns: 90px repeat(5, minmax(44px, 1fr)); gap: 4px; align-items: stretch; }
.heat .lbl { font-size: 12px; color: var(--hait-muted); display: flex; align-items: center; }
.heat .ax { font-size: 12px; color: var(--hait-muted); text-align: center; }
.heat a.cell { min-height: 56px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 700; text-decoration: none; }
.heat a.cell.empty { opacity: .55; }
.heat a.cell.on { outline: 3px solid var(--hait-text); outline-offset: -3px; }
.risk-low { color: #1F5A33; } .risk-medium { color: #6B4500; } .risk-high { color: #7A3208; } .risk-veryhigh { color: #7A1A10; }
.lvl { display: inline-flex; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
