/* BBS มีตารางกว้างตามธรรมชาติ (MARKS/REBAR/SHAPE/TOTAL LENGTH ต่อขนาดเหล็ก/REMARKS) —
   เหมือน Planner/BOQ Summary/Material Catalog ที่ขอ opt-out จากกรอบ 960px ของ .app-panel
   เดิม (css/feature-panels.css) ไปแล้ว ใช้ pattern เดียวกัน */
#panel-bbs { align-items: stretch !important; }
#panel-bbs .app-panel { width: 100%; max-width: none; }

:root {
  --bbs-navy: #1a3560;
  --bbs-blue: #e8eef7;
  --bbs-border: #d0d7e3;
  --bbs-alt: #fafbfd;
  --bbs-total: #fff3cd;
  --bbs-zero: #bbbbbb;
  --bbs-red: #c0392b;
  --bbs-blue-dark: #2b4c7e;
  --bbs-gray: #555555;
}

.bbs-engineering-shell {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
  padding: 18px;
  color: #1f2937;
  font-family: 'Sarabun', 'Segoe UI', Arial, sans-serif;
  background: #f6f8fb;
}

.bbs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: white;
  border: 1px solid var(--bbs-border);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.bbs-toolbar h1 {
  margin: 0;
  font-size: 20px;
  color: var(--bbs-navy);
}

.bbs-toolbar p {
  margin: 3px 0 0;
  color: #64748b;
  font-size: 12px;
}

.bbs-toolbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bbs-tab-switcher {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.bbs-tab-btn {
  border: 1px solid var(--bbs-border);
  background: white;
  color: #334155;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.bbs-tab-btn.is-active {
  background: var(--bbs-navy);
  color: white;
  border-color: var(--bbs-navy);
}

.bbs-tab-wrapper {
  display: flex;
  gap: 4px;
  align-items: center;
  position: relative;
}

.bbs-tab-delete-btn {
  display: none;
  border: none;
  background: transparent;
  color: #94a3b8;
  padding: 2px 4px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.bbs-tab-wrapper:hover .bbs-tab-delete-btn {
  display: inline-block;
}

.bbs-tab-delete-btn:hover {
  background: #fee2e2;
  color: var(--bbs-red);
}

.bbs-print-btn {
  border: none;
  background: var(--bbs-navy);
  color: white;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.bbs-summary-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--bbs-border);
  border-radius: 8px;
  background: white;
  font-size: 12px;
}

.bbs-summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #f8fafc;
  border: 1px solid var(--bbs-border);
  border-radius: 999px;
}

/* สรุปรูปร่างการดัดทั้งโครงการ */
.bbs-shape-summary {
  border: 1px solid var(--bbs-border);
  border-radius: 8px;
  background: white;
  font-size: 12px;
}

.bbs-shape-summary > summary {
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.bbs-shape-summary__table {
  width: 100%;
  border-collapse: collapse;
}

.bbs-shape-summary__table th,
.bbs-shape-summary__table td {
  padding: 8px 10px;
  border-top: 1px solid var(--bbs-border);
  text-align: left;
  vertical-align: middle;
}

.bbs-shape-summary__table th {
  background: #f8fafc;
  font-weight: 600;
  white-space: nowrap;
}

.bbs-shape-summary__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bbs-shape-summary__svg svg {
  display: block;
}

.bbs-shape-summary__code {
  display: block;
  color: #64748b;
  font-size: 11px;
}

.bbs-shape-assumed {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  font-size: 11px;
}

.bbs-shape-borrowed {
  display: inline-block;
  margin-top: 2px;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #ffedd5;
  border: 1px solid #f97316;
  color: #9a3412;
  font-size: 11px;
}

.bbs-shape-summary__dia .bbs-summary-pill {
  margin: 1px 2px 1px 0;
}

.bbs-shape-summary__members {
  color: #475569;
  max-width: 260px;
}

.bbs-shape-summary__warn td {
  background: #fef2f2;
  color: #991b1b;
}

.bbs-manual-import-panel {
  background: white;
  border: 1px solid var(--bbs-border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bbs-manual-import-panel h2 {
  margin: 0;
  font-size: 16px;
  color: var(--bbs-navy);
}

.bbs-manual-import-panel textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--bbs-border);
  border-radius: 10px;
  padding: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: #1f2937;
  resize: vertical;
}

.bbs-manual-import-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.bbs-manual-import-hint {
  margin: 0;
  color: #475569;
  font-size: 12px;
}

.bbs-manual-message {
  font-size: 13px;
  color: #1f2937;
}

.bbs-manual-error {
  color: #b91c1c;
}

/* แถบกรอง (ขนาดเหล็ก / ชนิด element) เหนือตารางหลัก — แทนที่ .bbs-manual-import-panel เดิม
   ที่ครอบครองพื้นที่นี้มาก่อน (ปุ่มอัปโหลด JSON ย้ายไป toolbar แล้ว) */
.bbs-filter-bar:empty {
  display: none;
}

.bbs-filter-bar__row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--bbs-border);
  border-radius: 8px;
  background: white;
  font-size: 12px;
}

.bbs-filter-bar__label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #475569;
  font-weight: 600;
}

.bbs-filter-bar__select {
  padding: 5px 8px;
  border: 1px solid var(--bbs-border);
  border-radius: 6px;
  font-size: 12px;
  color: #1f2937;
  background: white;
  cursor: pointer;
}

.bbs-manual-success {
  color: #166534;
}

/* กล่องเดียวคลุมตารางหลัก + หัวข้อของมัน — ให้แยกออกจากการ์ด "สรุปรูปร่างการดัด" /
   "Manual BBS Input" ด้านบนอย่างชัดเจน (เคยดูเหมือนตารางอยู่ "ข้างใน" การ์ดอื่น
   เพราะทั้งคู่เป็นกรอบขาวเหมือนกันและ gap แคบไป) เส้นคั่นด้านบน + ระยะห่างเพิ่ม
   ทำให้เห็นชัดว่านี่คือ section คนละอันจริงๆ */
.bbs-table-section {
  border-top: 2px solid var(--bbs-border);
  padding-top: 18px;
  margin-top: 4px;
}

.bbs-table-section__title {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--bbs-navy);
}

.bbs-table-frame {
  border-radius: 10px;
  border: 1px solid var(--bbs-border);
  overflow: hidden;
  background: white;
}

.bbs-table-scroll {
  overflow: auto;
  max-height: calc(100vh - 200px);
}

.bbs-engineering-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: white;
}

.bbs-engineering-table th,
.bbs-engineering-table td {
  border: 1px solid var(--bbs-border);
  padding: 8px 10px;
  vertical-align: middle;
  text-align: left;
}

.bbs-engineering-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bbs-navy);
  color: white;
  font-weight: 600;
}

.bbs-engineering-table thead th.subhead {
  background: var(--bbs-blue);
  color: #22364d;
  font-weight: 600;
}

.bbs-engineering-table tbody tr:nth-child(even) {
  background: var(--bbs-alt);
}

.bbs-engineering-table tbody tr:hover {
  background: #eef4ff;
}

.bbs-mark-cell {
  text-align: left;
  font-weight: 700;
  color: #0f172a;
}

.bbs-grid-cell {
  white-space: nowrap;
  color: #475569;
  font-variant-numeric: tabular-nums;
}

.bbs-dia-cell {
  font-weight: 700;
  white-space: nowrap;
}

.bbs-dia-cell--16,
.bbs-dia-cell--20,
.bbs-dia-cell--25,
.bbs-dia-cell--28,
.bbs-dia-cell--32 {
  color: var(--bbs-blue-dark);
}

.bbs-dia-cell--25,
.bbs-dia-cell--28,
.bbs-dia-cell--32 {
  color: var(--bbs-red);
}

.bbs-dia-cell--6,
.bbs-dia-cell--9 {
  color: var(--bbs-gray);
}

.bbs-spacing-cell,
.bbs-pin-cell,
.bbs-qty-cell {
  font-variant-numeric: tabular-nums;
}

.bbs-remark-cell {
  min-width: 260px;
  line-height: 1.5;
  color: #334155;
}

.bbs-cut-length,
.bbs-unit-weight,
.bbs-total-length,
.bbs-total-weight {
  font-family: 'JetBrains Mono', 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

.bbs-total-row {
  background: var(--bbs-total) !important;
  font-weight: 700;
}

.bbs-total-row td {
  border-top: 2px solid #d4a017;
}

.bbs-error-row {
  background: #fee2e2 !important;
}

.bbs-error-row td {
  border-left: 3px solid #dc2626;
  color: #7f1d1a;
}

.bbs-unverified-formula {
  background: #fefce8 !important;
}

.bbs-unverified-formula td {
  border-left: 3px solid #f59e0b;
  color: #92400e;
}

.bbs-warning-spacing {
  background: #fef3c7 !important;
}

.bbs-warning-spacing td {
  border-left: 3px solid #f59e0b;
  color: #b45309;
}

.bbs-zero {
  color: var(--bbs-zero);
}

.bbs-shape-cell {
  min-width: 110px;
  width: 110px;
  padding: 4px 6px;
}

.bbs-shape-cell svg {
  width: 100%;
  height: auto;
  max-height: 48px;
}

.bbs-section-title {
  background: #edf2f9;
  font-weight: 700;
  color: var(--bbs-navy);
  text-align: left;
  letter-spacing: 0.02em;
}

.bbs-section-title td {
  padding: 10px 8px;
}

@media print {
  body {
    background: white;
  }

  .bbs-engineering-shell {
    padding: 0;
    background: white;
  }

  .bbs-toolbar,
  .bbs-summary-strip {
    box-shadow: none;
  }

  .bbs-toolbar__actions,
  .bbs-tab-switcher,
  .bbs-print-btn {
    display: none !important;
  }

  .bbs-table-scroll {
    overflow: visible;
    max-height: none;
  }

  .bbs-engineering-table {
    min-width: 0;
  }

  .bbs-engineering-table thead {
    display: table-header-group;
  }

  .bbs-engineering-table th,
  .bbs-engineering-table td {
    break-inside: avoid;
  }

  .bbs-engineering-table tbody tr {
    page-break-inside: avoid;
  }

  .bbs-engineering-table thead th {
    position: static;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Multi-select tab controls */
.bbs-tab-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 8px;
}

.bbs-tab-mode-btn,
.bbs-tab-select-all-btn,
.bbs-tab-delete-selected-btn {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  background: white;
  color: #1f2937;
  transition: all 0.2s ease;
}

.bbs-tab-mode-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.bbs-tab-select-all-btn {
  background: #e0e7ff;
  border-color: #818cf8;
  color: #312e81;
}

.bbs-tab-select-all-btn:hover {
  background: #c7d2fe;
}

.bbs-tab-delete-selected-btn:hover {
  background: #b91c1c;
  border-color: #7f1d1d;
}

.bbs-tab-wrapper.select-mode {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bbs-tab-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #818cf8;
}
