/* TASK-17: สไตล์กลางแบบง่ายๆ ใช้ร่วมกันทั้งหน้า login และหน้า dashboard placeholder
   Phase 3+ ที่จะมาใส่เนื้อหาจริงของแต่ละ dashboard ปรับ/ขยายไฟล์นี้ได้ตามต้องการ ไม่จำเป็นต้องคงโครงเดิม */
:root {
  --bravi-navy: #1b2a4a;
  --bravi-navy-light: #2d3f66;
  --bravi-gold: #b8925a;
  --bravi-bg: #f4f5f7;
  --bravi-card-bg: #ffffff;
  --bravi-text: #1f2430;
  --bravi-text-muted: #6b7280;
  /* เพิ่มพร้อม critique fix (2026-08-26): --bravi-text-muted (#6b7280) ผ่าน 4.5:1 แค่ตอนอยู่บน
     การ์ดขาว (#ffffff → 4.83:1) แต่ตกที่ 4.28-4.43:1 ตอนอยู่บนพื้นหน้าเว็บ/กล่องเทาอ่อนโดยตรง
     (#f4f5f7, #f0f1f4) — โทเค็นนี้เข้มขึ้นเล็กน้อย ผ่าน 4.5:1 ทุกพื้นหลังที่ใช้จริงในระบบ (คำนวณจริง
     ไม่ได้กะเอา: 5.30:1 บน #f4f5f7, 5.12:1 บน #f0f1f4, 5.78:1 บนขาว) ใช้เฉพาะจุดที่ตัวหนังสือ muted
     วางอยู่บนพื้นที่ไม่ใช่การ์ดขาวโดยตรง (.dashboard-welcome .muted, .placeholder-box, .pipeline-label) */
  --bravi-text-muted-strong: #5f6672;
  --bravi-error-bg: #fdecec;
  --bravi-error-text: #b3261e;
  --bravi-border: #e2e4ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bravi-bg);
  color: var(--bravi-text);
}

/* ---- หน้า login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* เพิ่มพร้อมภาพพื้นหลังหน้า login (2026-08-26) — ภาพ full-bleed โทนเนวี่/ทองตรงกับแบรนด์
     (public/js/../images/login-background.jpg, ผ่าน sharp บีบจาก PNG 3.4MB เหลือ ~90KB) กึ่งกลาง
     ภาพเว้นพื้นที่โล่งไว้ให้การ์ด login วางทับพอดีอยู่แล้วตั้งแต่ตอนสร้าง ไม่ต้องปรับ opacity/overlay
     เพิ่ม background-color เดิม (--bravi-bg) ไว้เป็น fallback ระหว่างโหลดภาพ/ถ้าโหลดภาพไม่สำเร็จ */
  background-color: var(--bravi-bg);
  background-image: url("/images/login-background.jpg");
  background-size: cover;
  background-position: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bravi-card-bg);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 8px 24px rgba(27, 42, 74, 0.12);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: var(--bravi-navy);
}

.login-card .subtitle {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--bravi-text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 14px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--bravi-border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: inherit;
  width: 100%;
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--bravi-navy-light);
  outline-offset: 1px;
}

.field .hint {
  font-size: 12px;
  color: var(--bravi-text-muted);
  font-weight: 400;
}

.btn-primary {
  width: 100%;
  padding: 11px 12px;
  border: none;
  border-radius: 8px;
  background: var(--bravi-navy);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-message {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bravi-error-bg);
  color: var(--bravi-error-text);
  font-size: 14px;
}

.error-message[hidden] {
  display: none;
}

.error-message .btn-secondary {
  margin-top: 8px;
}

.kpi-detail-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--bravi-navy);
  text-decoration: underline;
}

/* ---- ฟอร์มเพิ่มทรัพย์ (TASK-21) — ใช้ .error-message เดิมสำหรับ error, เพิ่ม success/duplicate ---- */
.success-message {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #e8f5ec;
  color: #1e6b3a;
  font-size: 14px;
}

.success-message[hidden] {
  display: none;
}

.duplicate-message {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff4e0;
  color: #8a5a00;
  font-size: 14px;
  font-weight: 600;
}

.duplicate-message[hidden] {
  display: none;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.btn-secondary {
  padding: 11px 16px;
  border: 1px solid var(--bravi-border);
  border-radius: 8px;
  background: #fff;
  color: var(--bravi-navy);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.form-card {
  max-width: 640px;
  margin: 32px auto;
  background: var(--bravi-card-bg);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 4px 16px rgba(27, 42, 74, 0.08);
}

.form-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  color: var(--bravi-navy);
}

.form-card .subtitle {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--bravi-text-muted);
}

/* ---- หน้า dashboard placeholder ---- */
.dash-header {
  background: var(--bravi-navy);
  color: #fff;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dash-header h1 {
  margin: 0;
  font-size: 18px;
}

.dash-header a {
  color: #fff;
  text-decoration: underline;
  font-size: 14px;
}

.dash-main {
  max-width: 640px;
  margin: 40px auto;
  padding: 0 24px;
}

.dash-card {
  background: var(--bravi-card-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(27, 42, 74, 0.08);
}

.dash-card p {
  line-height: 1.7;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bravi-gold);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ---- หน้ารายการทรัพย์ (TASK-22) ---- */
.properties-main {
  max-width: 960px;
}

.properties-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-field {
  margin-bottom: 0;
  min-width: 200px;
}

.empty-message {
  color: var(--bravi-text-muted);
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

.properties-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.properties-table th,
.properties-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bravi-border);
  white-space: nowrap;
}

.properties-table th {
  color: var(--bravi-navy);
  font-weight: 600;
  background: #f9fafb;
}

.properties-table td:nth-child(2) {
  white-space: normal;
  min-width: 220px;
}

/* ---- หน้ารายการลูกค้า (TASK-26) — ปุ่ม "รับเรื่อง" ใช้ .btn-secondary เดิม ---- */
.filter-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.filter-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.claim-btn {
  padding: 6px 12px;
  font-size: 13px;
}

.claim-status {
  font-size: 13px;
  font-weight: 600;
}

.claim-status-mine {
  color: #1e6b3a;
}

.claim-status-other {
  color: var(--bravi-text-muted);
  font-weight: 400;
}

/* ---- หน้ารายการดีล (TASK-32) — ตารางใช้ pattern เดียวกับ .properties-table ---- */
.deals-main {
  max-width: 960px;
}

.deals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.deals-table th,
.deals-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bravi-border);
  white-space: nowrap;
}

.deals-table th {
  color: var(--bravi-navy);
  font-weight: 600;
  background: #f9fafb;
}

.deals-table td:nth-child(1) {
  white-space: normal;
  min-width: 200px;
}

/* ---- หน้ารายละเอียดดีล / timeline (TASK-32) ---- */
.deal-main {
  max-width: 720px;
}

.deal-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
  margin-bottom: 24px;
  font-size: 14px;
}

.deal-summary dt {
  color: var(--bravi-text-muted);
  font-weight: 600;
}

.deal-summary dd {
  margin: 0 0 8px;
}

/* stepper แสดงขั้นบันไดของดีล: นัดดู → เจรจา → วางมัดจำ → นัดโอน → ปิดดีล */
.deal-stepper {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  margin: 24px 0 28px;
}

.deal-step {
  flex: 1;
  text-align: center;
  position: relative;
  font-size: 13px;
  color: var(--bravi-text-muted);
}

.deal-step::before {
  content: "";
  display: block;
  width: 100%;
  height: 4px;
  background: var(--bravi-border);
  margin-bottom: 8px;
  border-radius: 2px;
}

.deal-step:first-child::before {
  border-top-left-radius: 2px;
  border-bottom-left-radius: 2px;
}

.deal-step:last-child::before {
  border-top-right-radius: 2px;
  border-bottom-right-radius: 2px;
}

.deal-step.is-done::before,
.deal-step.is-current::before {
  background: var(--bravi-navy);
}

.deal-step.is-current {
  color: var(--bravi-navy);
  font-weight: 700;
}

.deal-step.is-done {
  color: var(--bravi-navy-light);
}

.deal-section {
  margin-bottom: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--bravi-border);
}

.deal-section h2 {
  margin: 0 0 4px;
  font-size: 16px;
  color: var(--bravi-navy);
}

.deal-section .subtitle {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--bravi-text-muted);
}

.commission-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 220px;
}

.commission-input-row input {
  flex: 1;
}

.deal-warning {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff4e0;
  color: #8a5a00;
  font-size: 14px;
}

.deal-warning[hidden] {
  display: none;
}

.deal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.approval-status {
  font-size: 13px;
  color: var(--bravi-text-muted);
  margin-top: 8px;
}

.btn-disabled-note {
  display: inline-block;
  padding: 11px 16px;
  border-radius: 8px;
  background: #f0f1f4;
  color: var(--bravi-text-muted);
  font-size: 15px;
  font-weight: 600;
}

.placeholder-box {
  padding: 12px 14px;
  border-radius: 8px;
  background: #f0f1f4;
  color: var(--bravi-text-muted-strong);
  font-size: 14px;
}

/* ---- หน้ารายงาน (TASK-56) — รวม 4 การ์ดจาก TASK-52-55 ---- */
.reports-main {
  max-width: 960px;
}

.report-card {
  margin-bottom: 24px;
}

.report-card h2 {
  margin: 0 0 4px;
  font-size: 17px;
  color: var(--bravi-navy);
}

.report-card-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.month-field {
  margin-bottom: 0;
  min-width: 160px;
}

/* ---- TASK-57: ปุ่ม Export Excel ในการ์ดรายงาน ---- */
.report-export-btn {
  padding: 8px 14px;
  font-size: 13px;
}

.report-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.report-stat-box {
  padding: 14px 16px;
  border-radius: 8px;
  background: #f9fafb;
}

.report-stat-box .label {
  font-size: 13px;
  color: var(--bravi-text-muted);
}

.report-stat-box .value {
  font-size: 20px;
  font-weight: 700;
  color: var(--bravi-navy);
  margin-top: 4px;
}

.report-stat-box .sub {
  font-size: 13px;
  color: var(--bravi-text-muted);
  margin-top: 2px;
}

.pipeline-list {
  margin-top: 8px;
}

.pipeline-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.pipeline-label {
  width: 84px;
  flex-shrink: 0;
  font-size: 14px;
  color: var(--bravi-text-muted-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-track {
  flex: 1;
  height: 20px;
  background: #f0f1f4;
  border-radius: 10px;
  overflow: hidden;
}

.pipeline-fill {
  height: 100%;
  background: var(--bravi-navy);
  border-radius: 10px 0 0 10px;
  min-width: 2px;
}

.pipeline-count {
  width: 36px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 600;
  color: var(--bravi-navy);
}

/* ---- การ์ด 5: ค่าใช้จ่ายการตลาด (TASK-97) ---- */
/* ตัวเลือกช่วงเวลา สัปดาห์/เดือน/ปี — ใช้ .field เดิม (generic) แค่กำหนด min-width เหมือน .month-field
   ตั้งชื่อ class แยกเพราะความหมายคนละอย่าง (period ไม่ใช่ month) */
.period-field {
  margin-bottom: 0;
  min-width: 140px;
}

/* แยกตามช่องทาง: reuse .pipeline-row/.pipeline-track/.pipeline-fill เป๊ะตาม pattern การ์ด Pipeline
   เดิม (TASK-56) แต่ .pipeline-label/.pipeline-count เดิมถูกออกแบบมาสำหรับคำสั้นๆ (สถานะดีล) และ
   ตัวเลขจำนวนเต็มแคบๆ — ชื่อช่องทาง/จำนวนเงินบาทยาวกว่านั้น เพิ่ม modifier class ต่อท้ายเฉพาะการ์ดนี้
   ไม่แก้ .pipeline-label/.pipeline-count เดิม (การ์ด Pipeline เดิมไม่ได้ใช้ modifier นี้ ไม่กระทบกัน) */
.marketing-channel-label {
  width: 140px;
}

.marketing-channel-amount {
  width: auto;
  min-width: 100px;
}

/* ---- รูปภาพ/เอกสารทรัพย์ (TASK-77) — uploader ใน property.html ---- */
.media-dropzone {
  border: 2px dashed var(--bravi-border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  margin-bottom: 14px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.media-dropzone.is-dragover {
  border-color: var(--bravi-navy);
  background: #f0f3fa;
}

.media-dropzone-text {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--bravi-text-muted);
}

.media-choose-btn {
  width: auto;
}

.media-upload-queue {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.media-upload-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f4f5f7;
  font-size: 13px;
}

.media-upload-item.is-error {
  background: var(--bravi-error-bg);
  color: var(--bravi-error-text);
}

.media-upload-filename {
  flex-shrink: 0;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #e2e4ea;
  overflow: hidden;
}

.media-progress-fill {
  height: 100%;
  width: 100%;
  background: var(--bravi-navy);
  border-radius: 4px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s ease;
}

.media-upload-item.is-error .media-progress-fill {
  background: var(--bravi-error-text);
}

.media-upload-status {
  flex-shrink: 0;
  color: var(--bravi-text-muted);
}

.media-upload-item.is-error .media-upload-status {
  color: var(--bravi-error-text);
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.media-item {
  border: 1px solid var(--bravi-border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.media-thumb-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #f0f1f4;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-doc-thumb {
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  text-align: center;
}

.media-doc-icon {
  font-size: 32px;
}

.media-doc-thumb a {
  font-size: 12px;
  color: var(--bravi-navy);
  word-break: break-all;
}

.media-cover-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bravi-navy);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.media-item-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.media-item-actions .btn-secondary {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
}

/* ==========================================================================
   Dashboard sidebar redesign (2026-08-26)
   ขอบเขต: แค่ 3 หน้า dashboard-owner.html / dashboard-exec.html / dashboard-agent.html
   เท่านั้น — หน้าอื่นทั้งหมด (properties.html, deals.html ฯลฯ) ยังใช้ .dash-header/.dash-main
   เดิมต่อไป (ไม่ใช่ขอบเขตของงานนี้ ขยายทีหลังได้โดยห่อเนื้อหาเดิมด้วยโครง .app-shell นี้)
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--bravi-navy);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
  /* จงใจไม่ transition width — animate layout property (width/height/padding) ทำให้ browser
     ต้อง reflow ทุก frame (layout thrash) พับ/ขยายแบบ snap ทันทีเร็วกว่าและลื่นกว่าจริง */
}

.sidebar.is-collapsed {
  width: 76px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 66px;
}

/* พับแล้ว (76px): แถวเดิม (โลโก้+ชื่อ+ปุ่มพับ แนวนอน) ไม่พอที่ — ต้อง fixed-shrink ของ 3
   ชิ้นรวมกัน (32+30px) + gap + padding เกิน 76px แน่นอน สลับเป็นแนวตั้งแทน ซ้อนกันแค่โลโก้กับ
   ปุ่มพับ (ซ่อนชื่อ) ก็พอดีกับความกว้างที่เหลือสบายๆ ไม่ต้องคำนวณความกว้างให้พอดีเป๊ะแบบเดิม */
.sidebar.is-collapsed .sidebar-brand {
  flex-direction: column;
  gap: 10px;
  padding: 14px 8px;
}

.sidebar.is-collapsed .sidebar-brand-text {
  display: none;
}

.sidebar-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bravi-gold);
  color: var(--bravi-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  /* เพิ่มพร้อม critique fix (2026-08-26) — ตอนนี้เป็น <a> ลิงก์กลับหน้าแดชบอร์ดของ role ตัวเอง
     ไม่ใช่ <div> เฉยๆ แล้ว (ก่อนหน้านี้ไม่มีทางกลับแดชบอร์ดจากหน้าอื่นเลยนอกจาก browser back) */
  text-decoration: none;
  cursor: pointer;
}

.sidebar-brand-text {
  flex: 1;
  min-width: 0;
  color: #fff;
  font-weight: 700;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-collapse-btn,
.sidebar-close-btn {
  flex-shrink: 0;
  /* 44px ไม่ใช่ 30px — เดิมเล็กกว่าเกณฑ์ touch-target ขั้นต่ำ (44×44) ที่ critique เจอจริง */
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
}

.sidebar-collapse-btn:hover,
.sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-collapse-btn svg {
  width: 17px;
  height: 17px;
  transition: transform 0.16s ease;
}

.sidebar.is-collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

.sidebar-close-btn {
  display: none;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
}

.sidebar-section-label {
  padding: 14px 10px 6px;
  font-size: 11.5px;
  font-weight: 600;
  /* 0.55 ไม่ใช่ 0.4 — ที่ 0.4 คำนวณ contrast บนพื้นเนวี่ ~#1b2a4a ได้แค่ ~3.6:1 ซึ่งไม่ผ่าน 4.5:1
     ของตัวหนังสือขนาดนี้ (11.5px หนา ยังไม่ถึงเกณฑ์ "ตัวใหญ่" ที่ผ่อนเป็น 3:1 ได้) 0.55 คำนวณได้ ~5.5:1 */
  color: rgba(255, 255, 255, 0.55);
}

.sidebar-section-label:first-child {
  padding-top: 2px;
}

.sidebar.is-collapsed .sidebar-section-label {
  visibility: hidden;
  height: 8px;
  padding: 8px 0 0;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sidebar-nav-link {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 14px;
}

.sidebar-nav-link svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.sidebar-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar.is-collapsed .sidebar-nav-label {
  display: none;
}

.sidebar-nav-link:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.sidebar-nav-link.is-active {
  background: var(--bravi-gold);
  color: var(--bravi-navy);
  font-weight: 600;
}

.sidebar-add-link {
  flex-shrink: 0;
  /* 44px ไม่ใช่ 26px — เดิมเล็กกว่าเกณฑ์ touch-target ขั้นต่ำมาก และเป็นปุ่มที่กดพลาดแล้วสร้าง
     record จริง (เพิ่มทรัพย์/ลูกค้าใหม่) ยิ่งต้องกดแม่นบนมือถือ */
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
}

.sidebar-add-link svg {
  width: 15px;
  height: 15px;
}

.sidebar-add-link:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar.is-collapsed .sidebar-add-link {
  display: none;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-user-text {
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
}

.sidebar.is-collapsed .sidebar-user-text {
  display: none;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.62);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}

.sidebar-logout-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-logout-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.sidebar.is-collapsed .sidebar-logout-btn span {
  display: none;
}

/* เพิ่มพร้อม critique fix (2026-08-26) — ก่อนหน้านี้ทั้งไฟล์มี :focus rule เดียว (.field input/
   select/textarea) ซึ่งไม่ตรงกับ element ไหนในหน้า dashboard เลย ทุกปุ่ม/ลิงก์ใน sidebar เลยตกไปใช้
   native focus ring เดิมที่ไม่ออกแบบ ไม่สม่ำเสมอกับพื้นเนวี่ — ใช้ :focus-visible (ไม่ใช่ :focus เฉยๆ)
   กันไม่ให้ outline โผล่ตอนคลิกด้วยเมาส์/แตะ ให้เห็นเฉพาะตอน keyboard navigation จริง */
.sidebar-nav-link:focus-visible,
.sidebar-add-link:focus-visible,
.sidebar-collapse-btn:focus-visible,
.sidebar-close-btn:focus-visible,
.sidebar-logout-btn:focus-visible,
.app-topbar-menu-btn:focus-visible {
  outline: 2px solid var(--bravi-gold);
  outline-offset: 2px;
}

/* Skip-link: ก่อนหน้านี้ไม่มีทางข้าม 8 nav item + user info + logout เลยสำหรับ keyboard/screen
   reader — ซ่อนไว้นอกจอปกติ โผล่มาเป็นแถบแรกสุดตอน focus เท่านั้น (pattern มาตรฐาน) */
.skip-to-content-link {
  position: absolute;
  top: -48px;
  left: 8px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--bravi-navy);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.12s ease;
}

.skip-to-content-link:focus {
  top: 8px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, 0.45);
  z-index: 35;
}

.sidebar-backdrop.is-visible {
  display: block;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* เพิ่มพร้อมขยาย shell ไปทุกหน้า (2026-08-26) — ตัวห่อ #page-content เดิมของแต่ละหน้า (มี
   .dash-header/.dash-main หรือ .properties-main ฯลฯ ของตัวเองอยู่แล้ว) ไม่ใส่ padding/max-width
   ทับเอง ปล่อยให้ style เดิมของแต่ละหน้าคุมต่อเหมือนเดิมทุกประการ แค่ทำให้เต็มพื้นที่ที่เหลือ */
.app-main-content {
  flex: 1;
  min-width: 0;
}

.app-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  background: var(--bravi-card-bg);
  border-bottom: 1px solid var(--bravi-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-topbar-menu-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--bravi-border);
  background: #fff;
  color: var(--bravi-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.app-topbar-menu-btn svg {
  width: 19px;
  height: 19px;
}

.app-topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--bravi-navy);
}

@media (max-width: 1023px) {
  .app-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 268px !important;
    transform: translateX(-100%);
    box-shadow: 10px 0 28px rgba(15, 20, 35, 0.22);
    transition: transform 0.2s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  /* จอเล็กเป็น drawer เต็มความกว้างเสมอ ไม่สนสถานะ .is-collapsed ที่จำไว้จากจอใหญ่ (localStorage) —
     รีเซ็ตทุกจุดที่ .is-collapsed เคยซ่อน/บีบไว้กลับมาแสดงปกติหมด (รวม height/padding ของ
     section-label และโครง column ของ brand row ที่ไม่งั้นจะเหลือค้างจากสถานะพับ) */
  .sidebar .sidebar-section-label,
  .sidebar .sidebar-nav-label,
  .sidebar .sidebar-add-link,
  .sidebar .sidebar-user-text,
  .sidebar .sidebar-logout-btn span,
  .sidebar .sidebar-brand-text {
    display: revert !important;
    visibility: visible !important;
  }

  .sidebar .sidebar-section-label {
    height: auto !important;
    padding: 14px 10px 6px !important;
  }

  .sidebar .sidebar-brand {
    flex-direction: row !important;
    padding: 18px 16px !important;
  }

  .sidebar-collapse-btn {
    display: none;
  }

  .sidebar-close-btn {
    display: flex;
  }
}

@media (min-width: 1024px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* ---- เนื้อหา KPI dashboard (แทนที่ .dash-card เดิมของ 3 หน้านี้) ---- */
.dashboard-main {
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.dashboard-welcome {
  margin: 4px 0 22px;
  font-size: 21px;
  color: var(--bravi-navy);
}

.dashboard-welcome .muted {
  display: block;
  margin-top: 3px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--bravi-text-muted-strong);
}

.kpi-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  background: var(--bravi-card-bg);
  border-radius: 14px;
  padding: 24px 26px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(27, 42, 74, 0.08);
}

.kpi-hero-label {
  font-size: 13px;
  color: var(--bravi-text-muted);
  margin-bottom: 6px;
}

.kpi-hero-value {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--bravi-navy);
}

.kpi-hero-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--bravi-text-muted);
}

.kpi-hero-progress {
  flex: 1;
  min-width: 220px;
  max-width: 320px;
}

.kpi-hero-progress-track {
  height: 9px;
  border-radius: 999px;
  background: #eef0f4;
  overflow: hidden;
}

.kpi-hero-progress-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 999px;
  background: var(--bravi-gold);
}

.kpi-hero-progress-text {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--bravi-text-muted);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi-tile {
  background: var(--bravi-card-bg);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 4px 16px rgba(27, 42, 74, 0.06);
}

.kpi-tile .label {
  font-size: 12.5px;
  color: var(--bravi-text-muted);
}

.kpi-tile .value {
  margin-top: 5px;
  font-size: 21px;
  font-weight: 700;
  color: var(--bravi-navy);
}

.kpi-tile .sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--bravi-text-muted);
}

.dashboard-pipeline-card {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .kpi-hero {
    padding: 20px;
  }

  .kpi-hero-value {
    font-size: 28px;
  }

  .dashboard-main {
    padding: 20px 16px 40px;
  }
}
