/* ─── 3-COLUMN LAYOUT ─── */
.he-wrap {
  --he-col1: 340px;
  --he-col3: 380px;
  display: grid;
  grid-template-columns: var(--he-col1) 6px minmax(0, 1fr) 6px var(--he-col3);
  gap: 0;
  background: #e5e7eb;
  height: calc(100vh - 200px);
  min-height: 600px;
}
.he-col { background: #fff; overflow-y: auto; min-width: 0; }
.he-resizer {
  background: #e5e7eb;
  cursor: col-resize;
  position: relative;
  user-select: none;
  transition: background 0.15s;
}
.he-resizer:hover,
.he-resizer.dragging { background: #16a34a; }
.he-resizer::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  background: #9ca3af;
  border-radius: 1px;
  opacity: 0.5;
}
.he-resizer:hover::after,
.he-resizer.dragging::after { background: #fff; opacity: 1; }
body.he-resizing,
body.he-resizing * { cursor: col-resize !important; user-select: none !important; }

/* ─── LEFT: AI Chat sidebar ─── */
.he-chat { display: flex; flex-direction: column; background: #f9fafb; }
.he-chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  display: flex; align-items: center; gap: 10px;
}
.he-chat-icon {
  width: 28px; height: 28px;
  background: #16a34a; border-radius: 6px;
  display: grid; place-items: center;
  color: #fff; font-size: 14px;
}
.he-chat-prompt {
  flex: 1; font-size: 13px; color: #1f2937; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.he-chat-prompt-icons { display: flex; gap: 4px; color: #9ca3af; }
.he-chat-body { flex: 1; padding: 16px; overflow-y: auto; }
.he-chat-scope-item {
  padding: 6px 0; font-size: 13px; color: #374151; line-height: 1.5;
  border-bottom: 1px solid #f3f4f6;
  display: flex; gap: 8px;
}
.he-chat-scope-item::before { content: "•"; color: #16a34a; font-weight: bold; }
.he-chat-note {
  margin-top: 16px; padding: 12px; background: #fff;
  border: 1px solid #e5e7eb; border-radius: 8px;
  font-size: 12px; color: #6b7280; line-height: 1.6;
}
.he-chat-input-wrap {
  padding: 12px; border-top: 1px solid #e5e7eb; background: #fff;
}
.he-chat-input {
  width: 100%; border: 1px solid #d1d5db; border-radius: 8px;
  padding: 10px 12px; font-size: 13px; resize: none; font-family: inherit;
  box-sizing: border-box;
}
.he-chat-input:focus { outline: 2px solid #16a34a; border-color: #16a34a; }
.he-chat-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px; border-bottom: 1px solid #e5e7eb; background: #fff;
}
.he-chat-nav-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 13px; color: #374151;
  background: transparent; border: none; cursor: pointer;
  border-radius: 6px; text-align: left;
}
.he-chat-nav-btn:hover { background: #f3f4f6; }
.he-chat-nav-btn.active { background: #ecfdf5; color: #16a34a; font-weight: 600; }

/* ─── CENTER: Estimate table ─── */
.he-estimate { display: flex; flex-direction: column; }
.he-est-header {
  padding: 18px 24px; border-bottom: 1px solid #e5e7eb; background: #fff;
  position: sticky; top: 0; z-index: 5;
}
.he-est-toolbar {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: #6b7280; margin-bottom: 6px;
}
.he-est-toolbar .spacer { flex: 1; }
.he-est-tool-btn {
  background: none; border: none; cursor: pointer; padding: 6px 8px;
  color: #6b7280; font-size: 13px; border-radius: 4px;
  display: inline-flex; align-items: center; gap: 4px;
}
.he-est-tool-btn:hover { background: #f3f4f6; color: #111827; }
.he-est-id {
  font-size: 11px; color: #9ca3af; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.he-est-title {
  font-size: 22px; font-weight: 700; color: #111827; margin: 4px 0 10px;
}
.he-est-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.he-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f3f4f6; padding: 4px 10px; border-radius: 12px;
  font-size: 12px; color: #374151;
}
.he-chip-icons { display: flex; gap: 4px; }

/* ─── Tabs (slim, under title) ─── */
.he-tabs {
  display: flex; border-bottom: 1px solid #e5e7eb;
  background: #fff; padding: 0 24px;
}
.he-tab {
  padding: 12px 18px; background: transparent; border: none; cursor: pointer;
  font-size: 13px; color: #6b7280; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.he-tab.active { color: #16a34a; border-bottom-color: #16a34a; font-weight: 600; }

/* ─── Estimate table ─── */
.he-est-body { flex: 1; overflow-y: auto; padding: 0; background: #fff; }
.he-table-head {
  display: grid;
  grid-template-columns: 32px 1fr 90px 60px 100px 100px;
  gap: 12px; padding: 10px 24px;
  background: #f9fafb; border-bottom: 1px solid #e5e7eb;
  font-size: 11px; color: #6b7280; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  position: sticky; top: 0;
}
.he-table-head .num { text-align: right; }
.he-group { border-bottom: 1px solid #f3f4f6; }
.he-group-head {
  display: grid;
  grid-template-columns: 32px 1fr 90px 60px 100px 100px;
  gap: 12px; align-items: center; padding: 12px 24px;
  cursor: pointer; font-size: 13px; font-weight: 600; color: #111827; background: #fff;
}
.he-group-head:hover { background: #f9fafb; }
.he-group-chevron { transition: transform 0.15s; color: #9ca3af; display: inline-block; }
.he-group.expanded .he-group-chevron { transform: rotate(90deg); }
.he-group-count { color: #6b7280; font-size: 12px; font-weight: 400; }
.he-group-items { display: none; }
.he-group.expanded .he-group-items { display: block; }
.he-row {
  display: grid;
  grid-template-columns: 32px 1fr 90px 60px 100px 100px;
  gap: 12px; align-items: center; padding: 8px 24px;
  font-size: 13px; color: #1f2937;
  border-top: 1px solid #f3f4f6; cursor: pointer; background: #fff;
}
.he-row:hover { background: #f9fafb; }
.he-row.selected { background: #ecfdf5; border-left: 3px solid #16a34a; padding-left: 21px; }
.he-row-lineno { color: #9ca3af; font-size: 12px; }
.he-row-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.he-row-thumb {
  width: 36px; height: 36px; border-radius: 4px;
  background: #f3f4f6; flex-shrink: 0; object-fit: cover;
}
.he-row-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.he-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.he-row-type {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-align: center;
}
.he-type-material { background: #e0f2fe; color: #0369a1; }
.he-type-labor    { background: #fef3c7; color: #92400e; }

/* ─── RIGHT: Product detail panel ─── */
.he-product { background: #fff; display: flex; flex-direction: column; }
.he-product-empty {
  padding: 40px 20px; text-align: center; color: #9ca3af; font-size: 13px;
}
.he-product-head {
  padding: 14px 18px; border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; gap: 10px;
}
.he-product-back {
  background: none; border: none; cursor: pointer; color: #6b7280; padding: 4px;
}
.he-product-source { font-size: 12px; color: #6b7280; margin-left: auto; }
.he-product-body { padding: 18px; }
.he-product-title { font-size: 15px; font-weight: 600; color: #111827; line-height: 1.4; }
.he-product-supplier { font-size: 12px; color: #6b7280; margin-top: 2px; }
.he-product-img {
  width: 100%; aspect-ratio: 1; background: #f3f4f6; border-radius: 8px;
  margin: 14px 0; object-fit: cover;
}
.he-product-price { font-size: 24px; font-weight: 700; color: #111827; }
.he-product-price-unit { font-size: 14px; font-weight: 400; color: #6b7280; }
.he-product-note {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px;
  padding: 10px; font-size: 11px; color: #92400e; margin: 12px 0; line-height: 1.5;
}
.he-product-section-title {
  font-size: 11px; font-weight: 600; color: #374151;
  text-transform: uppercase; letter-spacing: 0.5px; margin: 18px 0 8px;
}
.he-product-details { font-size: 12px; color: #374151; line-height: 1.6; }
.he-spec-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid #f3f4f6; font-size: 12px;
}
.he-spec-label { color: #6b7280; }
.he-spec-value { color: #111827; font-weight: 500; }
.he-product-action {
  display: block; width: 100%; background: #16a34a; color: #fff;
  padding: 12px; border-radius: 8px; border: none; font-weight: 600;
  cursor: pointer; text-align: center; text-decoration: none; margin-top: 16px;
  box-sizing: border-box;
}
.he-product-action:hover { background: #15803d; }

/* ─── TOP BAR ─── */
.he-topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; background: #fff; border-bottom: 1px solid #e5e7eb;
}
.he-topbar-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 18px; font-weight: 700; color: #111827;
  flex: 1 1 0; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.he-topbar-spacer { display: none; }
.he-totals { display: flex; flex-direction: column; text-align: right; gap: 2px; }
.he-total-val { font-size: 18px; font-weight: 700; color: #111827; }
.he-total-sub { font-size: 11px; color: #6b7280; }
.he-btn {
  background: #fff; border: 1px solid #d1d5db; padding: 8px 14px;
  border-radius: 6px; font-size: 13px; font-weight: 500;
  color: #374151; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.he-btn:hover { background: #f9fafb; }
.he-btn-primary { background: #16a34a; color: #fff; border-color: #16a34a; }
.he-btn-primary:hover { background: #15803d; }
.he-btn-orange { background: #16a34a; color: #fff; border-color: #16a34a; }
.he-btn-orange:hover { background: #15803d; }

/* ─── Warnings ─── */
.he-warnings {
  margin: 16px 24px; background: #fffbeb; border-left: 4px solid #f59e0b;
  border-radius: 6px; padding: 14px 18px;
}
.he-warnings-title {
  font-size: 13px; font-weight: 700; color: #92400e;
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.he-warning-row {
  font-size: 12px; padding: 6px 0; line-height: 1.5;
  border-bottom: 1px dotted #fde68a;
}
.he-warning-row:last-child { border-bottom: none; }
.he-warn-tag {
  font-weight: 700; padding: 2px 6px; border-radius: 3px;
  font-size: 10px; margin-right: 6px; letter-spacing: 0.5px;
}
.he-warn-CRITICAL { background: #fee2e2; color: #b91c1c; }
.he-warn-WARN     { background: #fef3c7; color: #92400e; }
.he-warn-INFO     { background: #dbeafe; color: #1e40af; }

/* ─── Mobile / narrow ─── */
@media (max-width: 1100px) {
  .he-wrap { grid-template-columns: 1fr; height: auto; }
  .he-resizer { display: none; }
}
