/* --- Loading Spinner & Overlay --- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: none; /* ซ่อนไว้เริ่มต้น */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-soft);
    border-top: 5px solid var(--purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-weight: 600;
    color: var(--purple);
    font-size: 1.1rem;
}

/* --- Voice Record Button --- */
.btn-record {
    background: #ef4444;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
    transition: all 0.2s;
}

.btn-record.recording {
    background: #b91c1c;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* --- Utility --- */
.flex-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

:root {
  --purple: #5b2c83;
  --purple-dark: #3f1f5c;
  --cream: #f7f1e9;
  --bg-light: #fafafa;
  --border-soft: #e0d6f2;
  --text-main: #222;
  --text-muted: #666;
  --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.06);
}

/* บังคับดาวให้ใหญ่ยักษ์ */
.star-rating {
    display: flex !important;
    flex-direction: row-reverse !important;
    justify-content: center !important;
    gap: 10px !important;
    margin: 20px 0 !important;
}

/* เน้นที่ตัว label เพราะ ★ คือตัวอักษรใน label */
.star-rating label {
    font-size: 80px !important; /* ปรับเลขนี้ได้เลย 80, 100, 120 ตามชอบ */
    color: #ddd !important;
    cursor: pointer !important;
    line-height: 1 !important;
    transition: transform 0.2s, color 0.2s !important;
}

/* ซ่อนจุดวงกลม radio */
.star-rating input {
    display: none !important;
}

/* สีทองเมื่อเลือกหรือวางเมาส์ */
.star-rating input:checked ~ label,
.star-rating label:hover,
.star-rating label:hover ~ label {
    color: #f39c12 !important;
    text-shadow: 0 0 10px rgba(243, 156, 18, 0.4) !important;
}

/* เอฟเฟกต์ตอนจิ้ม */
.star-rating label:active {
    transform: scale(0.9);
}

/* ปรับตัวหนังสือด้านล่างดาว */
#rating-text {
    display: block !important;
    text-align: center !important;
    font-size: 1.5rem !important;
    font-weight: bold !important;
    color: #5b2c83 !important;
    margin-top: 10px !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(to bottom, #ffffff, var(--cream));
  color: var(--text-main);
}

/* Header */
.main-header {
  background: linear-gradient(to right, var(--purple), var(--purple-dark));
  color: #fff;
  padding: 12px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.logo-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-img {
  width: 150px;
  height: auto;
  border-radius: 8px;
  margin-bottom: 4px;
  object-fit: contain;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.org-name {
  font-size: 1.4rem;
  font-weight: 700;
}

.system-name {
  font-size: 0.95rem;
  opacity: 0.9;
}

/* Main layout */
/* ควบคุม Container หลักไม่ให้ขยับ */
.main-container {
    max-width: 1200px; /* ปรับให้กว้างขึ้นเล็กน้อยเพื่อรองรับตาราง */
    margin: 24px auto 40px;
    padding: 0 16px;
    overflow-x: hidden; 
}

/* สร้างแถบเลื่อนเฉพาะส่วนตารางเมื่อดูในมือถือ */
.bmc-canvas-wrapper {
    width: 100%;
    overflow-x: auto; /* เปิดแถบเลื่อนแนวนอน */
    -webkit-overflow-scrolling: touch; /* ให้เลื่อนลื่นบน iOS */
    margin-bottom: 20px;
    padding-bottom: 10px;
}

/* Card */
.card {
  background: #fff;
  border-radius: 14px;
  padding: 20px 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-soft);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.08);
  border-color: var(--purple);
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.3rem;
}

.card-subtitle {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px 20px;
  margin-bottom: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

label {
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--text-main);
}

input,
textarea,
select {
  border-radius: 8px;
  border: 1px solid #d3cbe8;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(91, 44, 131, 0.15);
  background: #fdfbff;
}

/* Buttons */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.btn {
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.btn.primary {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 4px 10px rgba(91, 44, 131, 0.35);
}

.btn.primary:hover {
  background: var(--purple-dark);
  transform: translateY(-1px);
}

.btn.secondary {
  background: #d8a75d;
  border: 1px solid var(--purple);
  color: var(--purple-dark);
}

.btn.secondary:hover {
  background: #e5d7ff;
}

.btn.outline {
  background: #ea9846;
  border: 1px solid var(--purple);
  color: var(--purple-dark);
}

.btn.outline:hover {
  background: #f7f0ff;
}

/* Status message */
.status-message {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Suggestions */
.suggestion-box {
  width: 100%;
  min-height: 120px;
}

/* เพิ่มส่วนนี้เข้าไปครับ */
.bmc-canvas {
    /* ล็อกขนาดให้ใกล้เคียง A4 Landscape (แนวนอน) */
    width: 1050px; 
    min-width: 1050px; 
    min-height: 740px; 
    
    padding: 30px; 
    margin: 0 auto; /* จัดกลางในหน้าจอที่กว้างกว่า 1050px */
    background: #f3f6f6;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
}

.bmc-title {
  text-align: center;
  font-size: 1.4rem;
  font-weight: bold;
  margin-bottom: 10px;
}

.bmc-title span {
  font-size: 1.1rem;
  color: #5b2c83;
}

.bmc-header {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  justify-content: center;
}

.bmc-header div {
  flex: 1;
  min-width: 200px;
}

.bmc-header label {
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
}

.bmc-header input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #aaa;
  width: 100%;
}

/* ปุ่มลอยด้านข้างซ้าย */
.side-controls {
    position: fixed;
    left: 2px;
    top: 20%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 1000;
}

.side-controls .btn {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    white-space: nowrap;
    padding: 12px 20px;
}

/* ปรับแต่ง Footer Profile */
.profile-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 20px 0;
}

.profile-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid #fff;
    object-fit: cover;
}

.profile-info {
    text-align: left;
    line-height: 1.4;
}

.btn-portfolio {
    background: #ea9846;
    color: var(--purple-dark);
    padding: 2px 8px;
    font-size: 0.7rem;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
    display: inline-block;
    border: 1px solid var(--purple);
    margin-left: 8px;
    vertical-align: middle;
    transition: all 0.2s ease;
}

.btn-portfolio:hover {
    background: #f7f0ff;
    transform: translateY(-1px);
    color: var(--purple);
}

/* --- แก้ไขปัญหา PDF ให้สมบูรณ์แบบ --- */
@media print {
    @page {
        size: A4 landscape; /* บังคับพิมพ์เป็นแนวนอน */
        margin: 5mm;
    }

    body {
        background: none !important;
    }


    .bmc-box textarea {
        overflow: visible !important;
        height: auto !important;
        font-size: 10px !important; /* ขนาดตัวอักษรใน PDF ตามที่คุณต้องการ */
        line-height: 1.2;
        border: none !important;
    }

    /* ซ่อนส่วนที่ไม่เกี่ยวข้อง */
    .side-controls, .main-header, .card:not(.bmc-canvas), .main-footer, .button-row {
        display: none !important;
    }
}

/* จัด Layout ตารางแบบ 3 แถว */
.bmc-grid {
    flex: 1;
    display: grid;
    gap: 0; 
    border: 2px solid #000;
    grid-template-areas:
        "partners activities value relationships segments"
        "partners resources  value channels      segments"
        "cost     cost       revenue revenue     revenue";
    grid-template-columns: 1fr 1fr 1.2fr 1fr 1fr;
    grid-template-rows: 230px 230px 190px; /* เพิ่มพื้นที่ให้ช่องต้นทุนและรายรับตอน export */
}

/* ตั้งค่าช่องย่อย (Box) */
.bmc-box {
    border: 1px solid #000;
    padding: 8px;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.bmc-box h3 {
    font-size: 0.85rem; /* ลดขนาดหัวข้อลงเล็กน้อย */
    margin: 0 0 5px 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 3px;
}

/* ปรับขนาดตัวอักษรเพื่อให้จุข้อมูลได้ครบในหน้าเดียว */
.bmc-box textarea {
    flex: 1;
    width: 100%;
    min-height: 0;
    border: none;
    resize: none;
    font-size: 13px; /* ขนาดที่แนะนำสำหรับ A4 */
    line-height: 1.4;
    outline: none;
}

.bmc-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 0.9rem;
  color: #333;
}

/* Footer */
.main-footer {
  background: linear-gradient(to right, var(--purple-dark), var(--purple));
  color: #fff;
  padding: 10px 0;
  margin-top: 20px;
}
/* ปรับแต่งพิเศษสำหรับส่วนท้าย (Footer ในตาราง) */
.bmc-footer-text {
  grid-column: 1 / -1; /* ลากยาวเต็มแถว */
  text-align: center;
  padding: 10px;
  font-size: 0.9rem;
  border-top: 2px solid #000;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  font-size: 0.85rem;
  text-align: center;
}

/* Responsive */
@media (max-width: 600px) {
  .org-name {
    font-size: 1.1rem;
  }
  .system-name {
    font-size: 0.8rem;
  }
}

/* สไตล์สำหรับข้อความชั่วคราวตอน Export PDF */
.pdf-temp-text {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: #333;
    padding: 2px;
    min-height: 20px;
}

/* ปรับให้ textarea ในหน้าจอปกติเห็นขอบชัดเจนแต่ใน PDF ไม่เอาขอบ */
.bmc-box textarea {
    border: none !important;
    background: transparent !important;
}
