/* คอนโซลออฟฟิศ — เดสก์ท็อปเป็นหลัก ตารางแน่น ตัวเลขอ่านง่าย */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
  background: linear-gradient(155deg, #0f4c81 0%, #0d2c48 100%);
}
.login-box { width: 100%; max-width: 460px; padding: 24px; }
.login-logo {
  width: 42px; height: 42px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); border-radius: 10px; font-size: 22px;
}
.demo-accounts { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.demo-btn {
  width: 100%; text-align: left; font-size: 12px; padding: 7px 10px;
  min-height: 34px; border-radius: var(--radius-sm);
}
.demo-btn b { font-weight: 650; }

/* ── โครงหน้า ─────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }

.sidebar {
  background: #0d2c48;
  color: #e7eef5;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; }
.side-brand .login-logo { background: rgba(255,255,255,.14); color: #fff; width: 34px; height: 34px; font-size: 18px; }
.side-project { padding: 4px 14px 12px; }
.side-project label { color: rgba(231,238,245,.7); }
.side-project select {
  background: rgba(255,255,255,.1); color: #fff;
  border-color: rgba(255,255,255,.2); font-size: 13px; min-height: 34px;
}
.side-project select option { color: #101826; }

.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 8px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; gap: 10px; align-items: center;
  background: transparent; border: none; color: rgba(231,238,245,.82);
  text-align: left; font-size: 13.5px; font-weight: 550;
  padding: 9px 10px; border-radius: var(--radius-sm); min-height: 38px;
}
.nav-item span[aria-hidden] { width: 16px; text-align: center; opacity: .8; }
.nav-item:hover { background: rgba(255,255,255,.08); border-color: transparent; color: #fff; }
.nav-item.is-on { background: rgba(255,255,255,.16); color: #fff; font-weight: 650; }
.nav-badge.is-warn { background: var(--warn); }
.nav-badge {
  margin-left: auto; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
  padding: 3px 7px; border-radius: 999px; font-variant-numeric: tabular-nums;
}

/* กล่องงาน */
.inbox-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 0; border-bottom: 1px solid var(--line-2);
}
.inbox-item:last-child { border-bottom: none; }
.inbox-icon {
  width: 30px; height: 30px; flex: none; border-radius: 7px;
  display: grid; place-items: center; font-size: 14px;
  background: var(--brand-soft); color: var(--brand);
}
.inbox-icon.is-line { background: var(--ok-soft); color: var(--ok); }
.inbox-icon.is-failed { background: var(--bad-soft); color: var(--bad); }
.inbox-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.inbox-text { font-size: 13px; color: var(--ink-2); white-space: pre-line; }
.inbox-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.inbox-link {
  font-size: 12px; font-weight: 600; padding: 4px 10px; min-height: 28px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); text-decoration: none; display: inline-flex; align-items: center;
}
.inbox-link.is-approve { border-color: var(--ok); color: var(--ok); }
.inbox-link.is-reject { border-color: var(--bad); color: var(--bad); }

.side-foot { padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.12); }
.side-foot .muted { color: rgba(231,238,245,.6); }
.side-foot button { color: #9dc6e8; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; gap: 14px; align-items: flex-end;
  padding: 18px 24px 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.view { padding: 18px 24px 60px; display: flex; flex-direction: column; gap: 16px; }

/* ── ส่วนประกอบ ───────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 3px; letter-spacing: -.02em; }
.kpi-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.is-bad .kpi-value { color: var(--bad); }
.kpi.is-ok .kpi-value { color: var(--ok); }
.kpi.is-warn .kpi-value { color: var(--warn); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
}
.panel-head h2 { font-size: 15px; }
.panel-body { padding: 14px 16px; }
.panel-body.is-flush { padding: 0; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1180px) { .two-col { grid-template-columns: 1fr; } }

/* น้ำตกกำไร */
.waterfall { display: flex; flex-direction: column; gap: 8px; }
.wf-row { display: grid; grid-template-columns: 230px 1fr 140px; gap: 12px; align-items: center; }
.wf-label { font-size: 13px; }
.wf-track { height: 26px; background: var(--line-2); border-radius: var(--radius-sm); position: relative; overflow: hidden; }
.wf-fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.wf-fill.is-base { background: var(--brand-2); }
.wf-fill.is-down { background: var(--bad); }
.wf-fill.is-up { background: var(--ok); }
.wf-fill.is-final { background: var(--brand); }
.wf-amount { font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.wf-row.is-total .wf-label { font-weight: 700; }
.wf-row.is-total { padding-top: 6px; border-top: 1px dashed var(--line); }

/* รายการตรวจ */
.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.check-row:last-child { border-bottom: none; }
.check-mark { width: 20px; flex: 0 0 auto; font-weight: 700; }
.check-mark.is-ok { color: var(--ok); }
.check-mark.is-bad { color: var(--bad); }

/* 4 กอง */
.bucket-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.bucket { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; border-top-width: 4px; }
.bucket.is-green { border-top-color: var(--ok); }
.bucket.is-yellow { border-top-color: #c98a00; }
.bucket.is-red { border-top-color: var(--bad); }
.bucket.is-lock { border-top-color: var(--ink-2); background: var(--line-2); }
.bucket-count { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ทะเบียนแบบ */
.rev-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--brand); border: 1px solid transparent;
}
.rev-chip.is-old { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.rev-arrow { color: var(--ink-3); margin: 0 4px; }

.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: grid; grid-template-columns: 76px 1fr; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line-2);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item.is-current { background: var(--ok-soft); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }

.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }

.btn-doc {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; text-decoration: none;
  padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}
.btn-doc:hover { border-color: var(--ink-3); }

.empty { padding: 26px; text-align: center; color: var(--ink-3); font-size: 14px; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { max-width: 260px; }

.toast {
  /* ข้อความแจ้งผลต้องไม่กินคลิก — เคยบังปุ่มหลักที่มุมขวาล่างจนกดไม่โดน */
  pointer-events: none;
  position: fixed; right: 22px; bottom: 22px;
  background: var(--ink); color: #fff; padding: 11px 16px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; z-index: 90;
  max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
/* หน้าถอดแบบวางปุ่มหลักไว้มุมขวาล่าง — ย้ายข้อความแจ้งผลขึ้นบนไม่ให้บังกัน */
body.is-takeoff-open .toast { bottom: auto; top: 20px; }
.toast.is-bad { background: var(--bad); }
.toast.is-ok { background: var(--ok); }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(16,24,38,.45); z-index: 60; display: flex; justify-content: flex-end; }
.drawer { width: min(720px, 96vw); background: var(--surface); height: 100%; display: flex; flex-direction: column; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; gap: 12px; align-items: flex-start; }
.drawer-body { padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }


/* ── ฟอร์มในกล่องยืนยัน ─────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.field > span { font-weight: 600; color: var(--ink-2); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,38,.5); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: min(520px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 18px 48px rgba(0,0,0,.3);
  display: flex; flex-direction: column; gap: 14px;
}
.modal h3 { font-size: 17px; }
.modal-body { gap: 12px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; }

/* ── U3 · หน้าถอดแบบ ───────────────────────────────────────────── */
tr.is-muted td { opacity: .62; }

.takeoff-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,38,.62); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.takeoff-shell {
  width: min(1560px, 100%); height: 100%;
  background: var(--surface); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.36);
}
.takeoff-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line-2);
  display: flex; gap: 12px; align-items: flex-start;
}
.takeoff-head h2 { font-size: 18px; }

.takeoff-tools {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--line-2); background: var(--bg);
}
.takeoff-tool {
  min-height: 38px; padding: 0 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
}
.takeoff-tool.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.takeoff-tool:disabled { opacity: .45; cursor: not-allowed; }
.takeoff-tool-gap { flex: 1; }
.takeoff-zoom {
  font-size: 12px; font-weight: 700; min-width: 46px; text-align: center;
  padding: 5px 8px; border-radius: var(--radius-sm); background: var(--line-2); color: var(--ink-2);
}
.takeoff-zoom.is-coarse { background: var(--warn-soft); color: var(--warn); }

.takeoff-body { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.takeoff-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.takeoff-stage {
  /* จัดกึ่งกลางด้วย margin ของลูก ไม่ใช่ justify-content
     เพราะ flex centering จะตัดส่วนที่ล้นทางซ้ายทิ้งจนเลื่อนกลับไปดูไม่ได้
     ซึ่งทำให้ครึ่งซ้ายของแบบคลิกไม่ถึงทันทีที่ขยายเกินกรอบ */
  flex: 1; overflow: auto; background: #eceff3; padding: 12px;
}
.takeoff-canvas {
  position: relative; line-height: 0; box-shadow: var(--shadow);
  margin: 0 auto;
}
.takeoff-image { display: block; width: 100%; height: auto; user-select: none; }
.takeoff-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.takeoff-overlay.is-drawing { cursor: crosshair; }

.takeoff-foot {
  padding: 10px 18px; border-top: 1px solid var(--line-2);
  display: flex; gap: 14px; align-items: center; min-height: 46px;
}
.takeoff-hint { font-size: 13px; color: var(--ink-2); flex: 1; }
.takeoff-readout {
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  color: var(--brand); white-space: nowrap;
}
.takeoff-preview {
  font-family: var(--mono); font-size: 24px; font-weight: 700;
  color: var(--brand); text-align: center;
  background: var(--brand-soft); border-radius: var(--radius-sm); padding: 12px;
}
.takeoff-compare { font-family: var(--mono); }

.takeoff-side {
  border-left: 1px solid var(--line-2); display: flex; flex-direction: column;
  min-height: 0; padding: 14px; gap: 10px;
}
.takeoff-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.takeoff-row {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 10px; display: flex; gap: 8px; align-items: flex-start;
}
.takeoff-row.is-selected { border-color: var(--brand); background: var(--brand-soft); }
.takeoff-row.is-applied { background: var(--ok-soft); border-color: #bfe3ce; }
.takeoff-row-main { display: flex; gap: 9px; align-items: flex-start; flex: 1; cursor: pointer; }
.takeoff-row-value {
  text-align: right; white-space: nowrap; min-width: 92px;
  display: flex; flex-direction: column; gap: 4px; align-items: flex-end;
}
/* หลักฐานที่ผู้ช่วยอ้างมักยาว — ตัดให้เหลือสองบรรทัด แล้วดูเต็มได้จาก tooltip
   ไม่งั้นแถวเดียวสูงจนรายการอื่นหลุดออกนอกสายตา */
.takeoff-row-evidence {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.takeoff-sum {
  border-top: 1px solid var(--line-2); padding-top: 12px;
  display: flex; gap: 10px; align-items: center;
}
.takeoff-evidence { display: flex; flex-direction: column; gap: 8px; list-style: none; }
.takeoff-evidence li { border-left: 3px solid var(--line); padding-left: 10px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .side-nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .wf-row { grid-template-columns: 150px 1fr 110px; }
  /* จอเล็กวางชั้นวัดไว้ใต้ภาพ — บีบให้อยู่ข้างกันแล้วทั้งสองฝั่งใช้ไม่ได้ */
  .takeoff-backdrop { padding: 0; }
  .takeoff-shell { border-radius: 0; }
  .takeoff-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .takeoff-side { border-left: none; border-top: 1px solid var(--line-2); max-height: 44vh; }
}
