/* ============================================================
   IntelliRoads — Estimation Platform Styles
   ============================================================ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #1a2332;
  --navy-mid:   #243044;
  --navy-light: #2e3f5c;
  --blue:       #2563eb;
  --blue-light: #3b82f6;
  --blue-bg:    #eff6ff;
  --blue-bdr:   #bfdbfe;
  --teal:       #0891b2;
  --green:      #059669;
  --green-bg:   #ecfdf5;
  --amber:      #d97706;
  --amber-bg:   #fffbeb;
  --red:        #dc2626;
  --red-bg:     #fef2f2;
  --red-bdr:    #fecaca;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-300:   #d1d5db;
  --gray-400:   #9ca3af;
  --gray-500:   #6b7280;
  --gray-600:   #4b5563;
  --gray-700:   #374151;
  --gray-800:   #1f2937;
  --white:      #ffffff;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);
  --radius:     8px;
  --radius-lg:  12px;
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:  'Consolas', 'Cascadia Code', monospace;
  --header-h:   56px;
  --labels-h:   40px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--gray-800);
  background: var(--gray-100);
  overflow: hidden;
}

/* ── App Header ── */
.app-header {
  height: var(--header-h);
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 100;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: var(--blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  display: block;
  line-height: 1.2;
}

.brand-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  display: block;
  line-height: 1;
}

.header-project {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 1px solid rgba(255,255,255,0.1);
  padding-left: 20px;
}

.proj-label {
  font-size: 9px;
  font-weight: 600;
  color: rgba(255,255,255,0.4);
  letter-spacing: 1px;
}

.proj-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.grand-total-pill {
  background: var(--navy-light);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 5px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gt-label {
  font-size: 9px;
  font-weight: 600;
  color: rgba(255,255,255,0.4);
  letter-spacing: 1px;
}

.gt-value {
  font-size: 14px;
  font-weight: 700;
  color: #34d399;
  font-family: var(--font-mono);
}

.hdr-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.hdr-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

.hdr-btn-primary {
  background: var(--blue);
  border-color: var(--blue-light);
  color: #fff;
}

.hdr-btn-primary:hover { background: var(--blue-light); }

/* ── Pane Labels Bar ── */
.pane-labels-bar {
  height: var(--labels-h);
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  background: var(--navy-mid);
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.pl-cell {
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 7px;
  border-right: 1px solid rgba(255,255,255,0.07);
}

.pl-cell:last-child { border-right: none; }

.pl-icon { font-size: 14px; }

.pl-text {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.65);
  letter-spacing: 0.3px;
  flex: 1;
}

.pl-badge {
  font-size: 10px;
  background: var(--blue);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-weight: 600;
}

.pl-center { justify-content: space-between; }

.workspace-actions { display: flex; gap: 5px; }

.ws-btn {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.ws-btn:hover { background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.9); }
.ws-btn-danger:hover { background: rgba(220,38,38,0.3); color: #fca5a5; border-color: #dc2626; }

/* ── Three Pane Workspace ── */
.workspace {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: calc(100vh - var(--header-h) - var(--labels-h));
  overflow: hidden;
  gap: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  overflow: hidden;
}

.pane:last-child { border-right: none; }

/* ── Shared Pane Components ── */
.pane-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.pane-scroll::-webkit-scrollbar { width: 4px; }
.pane-scroll::-webkit-scrollbar-track { background: transparent; }
.pane-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

.pane-footer {
  padding: 7px 14px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  font-size: 10px;
  color: var(--gray-500);
  text-align: center;
}

/* ── LEFT PANE ── */
.pane-left { background: var(--gray-50); }

.pane-search-bar {
  padding: 10px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}

.search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 12px;
  background: var(--gray-50);
  color: var(--gray-700);
  outline: none;
  transition: all 0.15s;
}

.search-input:focus {
  border-color: var(--blue);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* BOQ Section Group */
.boq-section {
  border-bottom: 1px solid var(--gray-200);
}

.boq-section-header {
  display: flex;
  align-items: center;
  padding: 8px 12px 8px 8px;
  background: var(--navy);
  cursor: pointer;
  user-select: none;
  gap: 6px;
  transition: background 0.15s;
}

.boq-section-header:hover { background: var(--navy-mid); }

.boq-section-toggle {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.boq-section-toggle.open { transform: rotate(90deg); }

.boq-section-code {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.boq-section-title {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  line-height: 1.3;
  flex: 1;
}

.boq-section-items {
  padding: 4px 0;
}

.boq-section-items.collapsed { display: none; }

/* BOQ Item */
.boq-item {
  display: flex;
  align-items: flex-start;
  padding: 7px 10px 7px 8px;
  gap: 7px;
  cursor: grab;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.12s;
  position: relative;
}

.boq-item:hover { background: var(--blue-bg); }
.boq-item:active { cursor: grabbing; }

.boq-item.added-to-workspace {
  background: var(--green-bg);
  opacity: 0.7;
}

.boq-item.added-to-workspace .boq-item-desc { color: var(--gray-500); }

.drag-handle {
  color: var(--gray-300);
  font-size: 12px;
  padding-top: 1px;
  flex-shrink: 0;
  line-height: 1;
}

.boq-item:hover .drag-handle { color: var(--blue); }

.boq-item-body { flex: 1; min-width: 0; }

.boq-item-sl {
  font-size: 9px;
  font-weight: 700;
  color: var(--blue);
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}

.boq-item-desc {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--gray-700);
  line-height: 1.35;
  margin-top: 1px;
}

.boq-item-meta {
  margin-top: 4px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.meta-chip {
  font-size: 10px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--gray-600);
  font-family: var(--font-mono);
}

.meta-chip.qty { color: var(--teal); border-color: #a5f3fc; background: #ecfeff; }
.meta-chip.unit { color: var(--gray-500); }

.added-badge {
  font-size: 9px;
  color: var(--green);
  background: var(--green-bg);
  border: 1px solid #6ee7b7;
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 600;
}

/* ── CENTER PANE ── */
.pane-center {
  background: #f0f2f5;
  border-right: 1px solid var(--gray-200);
}

.center-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}

.center-scroll::-webkit-scrollbar { width: 5px; }
.center-scroll::-webkit-scrollbar-track { background: transparent; }
.center-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

/* Master Drop Zone */
.drop-zone-master {
  text-align: center;
  padding: 60px 40px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-lg);
  background: var(--white);
  transition: all 0.2s;
  display: none;
}

.drop-zone-master.active {
  display: block;
}

.drop-zone-master.drag-over {
  border-color: var(--blue);
  background: var(--blue-bg);
}

.dz-icon {
  font-size: 40px;
  color: var(--gray-300);
  margin-bottom: 14px;
  line-height: 1;
}

.dz-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 6px;
}

.dz-hint {
  font-size: 12px;
  color: var(--gray-400);
  line-height: 1.5;
}

/* Bottom Drop Zone */
.drop-zone-bottom {
  margin-top: 12px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  color: var(--gray-400);
  font-size: 12px;
  transition: all 0.2s;
  background: var(--white);
}

.drop-zone-bottom.drag-over {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

/* ── ESTIMATION ITEM CARD ── */
.est-item-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  border: 1px solid var(--gray-200);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.est-item-card:hover {
  box-shadow: var(--shadow-md);
}

/* Estimation Item Header */
.est-item-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 100%);
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.est-item-header:hover { background: linear-gradient(135deg, var(--navy-mid) 0%, var(--navy-light) 100%); }

.est-toggle {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  width: 18px;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.est-toggle.open { transform: rotate(90deg); }

.est-item-code {
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 2px 7px;
  flex-shrink: 0;
}

.est-item-desc {
  flex: 1;
  font-size: 12.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  line-height: 1.3;
}

.est-item-boq-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.boq-qty-tag {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  font-family: var(--font-mono);
}

.boq-qty-val {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 2px 8px;
}

.est-item-total-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(52,211,153,0.15);
  border: 1px solid rgba(52,211,153,0.3);
  border-radius: 6px;
  padding: 4px 10px;
}

.total-label-sm { font-size: 9px; color: rgba(255,255,255,0.4); letter-spacing: 0.5px; }

.total-value-sm {
  font-size: 13px;
  font-weight: 700;
  color: #34d399;
  font-family: var(--font-mono);
  min-width: 80px;
  text-align: right;
}

.est-item-menu-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  border-radius: 5px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.est-item-menu-btn:hover { background: rgba(220,38,38,0.3); color: #fca5a5; border-color: rgba(220,38,38,0.5); }

/* Estimation Item Body (subheads) */
.est-item-body {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.est-item-body.collapsed { max-height: 0 !important; }

/* Template Suggestion Bar */
.template-bar {
  background: var(--amber-bg);
  border-bottom: 1px solid #fde68a;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.template-bar-text {
  font-size: 11px;
  color: var(--amber);
  font-weight: 500;
  flex: 1;
}

.btn-use-template {
  background: var(--amber);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-use-template:hover { opacity: 0.85; }

.btn-dismiss-template {
  background: transparent;
  border: none;
  color: var(--amber);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

/* Rate Link Bar */
.rate-link-bar {
  background: var(--blue-bg);
  border-bottom: 1px solid var(--blue-bdr);
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rate-link-icon { font-size: 11px; }
.rate-link-text { font-size: 10.5px; color: var(--blue); font-weight: 500; flex: 1; }
.btn-unlink-rate { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 11px; opacity: 0.6; }
.btn-unlink-rate:hover { opacity: 1; }

/* Subheads Table */
.subheads-table-wrap {
  overflow-x: auto;
}

.subheads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.subheads-table thead tr {
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
}

.subheads-table th {
  padding: 7px 8px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  white-space: nowrap;
  border-right: 1px solid var(--gray-200);
}

.subheads-table th:last-child { border-right: none; }

.subheads-table td {
  padding: 0;
  border-bottom: 1px solid var(--gray-100);
  border-right: 1px solid var(--gray-100);
  vertical-align: middle;
}

.subheads-table td:last-child { border-right: none; }

.subheads-table tbody tr:hover { background: #fafbff; }

.subheads-table tbody tr.drag-over-row { background: var(--blue-bg); }

/* Table Cell Input */
.cell-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 6px 8px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--gray-700);
  transition: background 0.15s;
}

.cell-input:focus {
  background: #fffbeb;
  box-shadow: inset 0 -2px 0 var(--blue);
}

.cell-input.num { font-family: var(--font-mono); text-align: right; }
.cell-input.rate-input.linked { color: var(--blue); font-weight: 600; }

/* Amount display cell */
.amount-cell {
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  text-align: right;
  white-space: nowrap;
  min-width: 100px;
}

.amount-cell.zero { color: var(--gray-400); font-weight: 400; }

/* Sr No cell */
.sr-cell {
  padding: 6px 8px;
  text-align: center;
  font-size: 11px;
  color: var(--gray-400);
  font-family: var(--font-mono);
  width: 36px;
}

/* Unit select */
.unit-select {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12px;
  font-family: var(--font);
  color: var(--gray-600);
  padding: 6px 4px;
  width: 100%;
  cursor: pointer;
}

/* Delete row button */
.btn-del-row {
  background: none;
  border: none;
  color: var(--gray-300);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  width: 32px;
}

.btn-del-row:hover { color: var(--red); }

/* RA Link chip on row */
.ra-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--blue-bg);
  border: 1px solid var(--blue-bdr);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 600;
  color: var(--blue);
  margin: 4px 8px;
  cursor: default;
}

.ra-chip-remove {
  cursor: pointer;
  color: var(--blue);
  opacity: 0.6;
  font-size: 10px;
}

.ra-chip-remove:hover { opacity: 1; }

/* Subtotal row */
.subtotal-row td {
  background: var(--gray-50) !important;
  border-top: 2px solid var(--gray-200) !important;
  border-bottom: none !important;
}

.subtotal-label {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-700);
  text-align: right;
  letter-spacing: 0.3px;
}

.subtotal-amount {
  padding: 8px 8px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
  text-align: right;
}

/* Table Footer Actions */
.table-footer-actions {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

.btn-add-subhead {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  background: var(--white);
  border: 1.5px dashed var(--blue);
  color: var(--blue);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-add-subhead:hover { background: var(--blue-bg); }

.drop-subhead-hint {
  font-size: 10px;
  color: var(--gray-400);
  margin-left: auto;
}

/* Empty subheads state */
.empty-subheads {
  padding: 24px;
  text-align: center;
  color: var(--gray-400);
  border: 2px dashed var(--gray-200);
  margin: 12px 14px;
  border-radius: 8px;
  font-size: 12px;
  transition: all 0.2s;
}

.empty-subheads.drag-over {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

/* ── RIGHT PANE ── */
.pane-right { background: var(--gray-50); }

.ra-settings-bar {
  padding: 8px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 14px;
}

.ra-setting-chip {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ra-chip-label { font-size: 9px; color: var(--gray-500); font-weight: 600; letter-spacing: 0.5px; }
.ra-chip-value { font-size: 11px; font-weight: 700; color: var(--navy); font-family: var(--font-mono); }

/* ── Right Pane Search Bar ── */
.ra-search-bar {
  padding: 8px 10px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}

/* ── Rate Chapter Group ── */
.rate-chapter { border-bottom: 1px solid var(--gray-200); }

.rate-chapter-header {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  background: var(--navy);
  cursor: pointer;
  user-select: none;
  gap: 6px;
  transition: background 0.15s;
}
.rate-chapter-header:hover { background: var(--navy-mid); }

.rate-chapter-toggle { font-size: 10px; color: rgba(255,255,255,0.5); transition: transform 0.2s; flex-shrink: 0; }
.rate-chapter-toggle.open { transform: rotate(90deg); }

.rate-chapter-num {
  font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.12); border-radius: 4px; padding: 1px 6px;
  flex-shrink: 0; font-family: var(--font-mono);
}
.rate-chapter-title { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.75); flex: 1; line-height: 1.3; }
.rate-chapter-count { font-size: 9px; color: rgba(255,255,255,0.4); flex-shrink: 0; }

.rate-chapter-items { padding: 3px 0; }
.rate-chapter-items.collapsed { display: none; }

/* ── Rate Group Header (unrated parent, e.g. "3.8 Excavation in Hard Rock…") ── */
.rate-group-header {
  display: flex; align-items: baseline; gap: 5px;
  padding: 6px 8px 4px 10px;
  background: rgba(14,165,233,0.07);
  border-left: 3px solid var(--teal);
  border-bottom: 1px solid rgba(14,165,233,0.15);
  cursor: default; user-select: none;
}
.rate-group-header-no {
  font-size: 9px; font-weight: 800; color: var(--teal);
  font-family: var(--font-mono); flex-shrink: 0;
}
.rate-group-header-desc {
  font-size: 10px; font-weight: 600; color: var(--gray-700);
  line-height: 1.3;
}

/* ── Rate Item Row ── */
.rate-item {
  display: flex; align-items: center;
  padding: 5px 8px 5px 6px; gap: 6px;
  cursor: grab; border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.1s;
}
.rate-item:hover { background: var(--blue-bg); }
.rate-item:active { cursor: grabbing; }
.rate-item-drag { color: var(--gray-300); font-size: 11px; flex-shrink: 0; }
.rate-item:hover .rate-item-drag { color: var(--blue); }
.rate-item-body { flex: 1; min-width: 0; overflow: hidden; }
.rate-item-no { font-size: 9px; font-weight: 700; color: var(--teal); font-family: var(--font-mono); }
.rate-item-desc {
  font-size: 11px; font-weight: 500; color: var(--gray-700);
  line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rate-item-right { flex-shrink: 0; text-align: right; min-width: 54px; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.rate-item-value { font-size: 12px; font-weight: 700; color: var(--green); font-family: var(--font-mono); }
.rate-item-unit { font-size: 9px; color: var(--gray-500); }

/* Breakdown toggle arrow */
.bd-toggle {
  font-size: 9px; color: var(--gray-400); cursor: pointer; line-height: 1;
  transition: transform 0.18s; user-select: none; padding: 1px 0;
}
.bd-toggle:hover { color: var(--blue); }
.bd-toggle.open { transform: rotate(180deg); }

/* Breakdown panel */
.rate-breakdown {
  background: #f8fafc;
  border-left: 3px solid var(--teal);
  border-bottom: 1px solid var(--gray-200);
  padding: 6px 8px;
  overflow-x: auto;
}
.rate-breakdown.collapsed { display: none; }

/* Breakdown table */
.bd-table {
  width: 100%; border-collapse: collapse;
  font-size: 10px; color: var(--gray-700);
}
.bd-table th {
  font-size: 9px; font-weight: 600; color: var(--gray-500);
  text-align: left; padding: 2px 4px; border-bottom: 1px solid var(--gray-200);
}
.bd-table th:nth-child(n+3) { text-align: right; }
.bd-table td { padding: 2px 4px; vertical-align: top; }
.bd-desc { max-width: 140px; }
.bd-unit { color: var(--gray-500); white-space: nowrap; }
.bd-num { text-align: right !important; font-family: var(--font-mono); white-space: nowrap; }
.bd-cat-row td {
  font-size: 9px; font-weight: 700; color: var(--navy);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding-top: 5px; padding-bottom: 1px;
  border-top: 1px solid var(--gray-200);
}
.bd-summary-row td { color: var(--gray-600); font-style: italic; }
.bd-total-row td {
  border-top: 1px solid var(--gray-300);
  padding-top: 4px; margin-top: 2px;
}

/* Rate Analysis Card (legacy R_A.xlsx cards) */
.ra-card {
  margin: 8px 8px 0 8px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: grab;
}

.ra-card:last-child { margin-bottom: 8px; }

.ra-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.ra-card:active { cursor: grabbing; transform: translateY(0); }

.ra-card-header {
  padding: 9px 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-bottom: 1px solid #bae6fd;
}

.ra-drag-handle {
  color: var(--gray-400);
  font-size: 12px;
  padding-top: 1px;
  flex-shrink: 0;
}

.ra-card:hover .ra-drag-handle { color: var(--blue); }

.ra-card-info { flex: 1; min-width: 0; }

.ra-item-no {
  font-size: 9px;
  font-weight: 700;
  color: var(--teal);
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.ra-item-desc {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-700);
  line-height: 1.35;
}

.ra-rate-badge {
  flex-shrink: 0;
  text-align: right;
}

.ra-rate-value {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--green);
  display: block;
}

.ra-rate-unit {
  font-size: 9px;
  color: var(--gray-500);
  display: block;
  text-align: right;
}

.ra-rate-tbd {
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-400);
  font-style: italic;
}

/* RA Card Expandable Body */
.ra-card-toggle {
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-size: 10px;
  color: var(--gray-500);
  font-weight: 500;
  user-select: none;
}

.ra-card-toggle:hover { background: var(--gray-100); }

.ra-toggle-arrow { font-size: 9px; transition: transform 0.2s; }
.ra-toggle-arrow.open { transform: rotate(90deg); }

.ra-card-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.ra-components-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
}

.ra-components-table th {
  padding: 5px 8px;
  text-align: left;
  font-size: 9px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: 0.3px;
  text-transform: uppercase;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.ra-components-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-600);
  vertical-align: top;
}

.ra-comp-type {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.ra-comp-type.machinery { background: #dbeafe; color: var(--blue); }
.ra-comp-type.labour { background: #d1fae5; color: var(--green); }
.ra-comp-type.overheads { background: #fef3c7; color: var(--amber); }
.ra-comp-type.profit { background: #f3e8ff; color: #7c3aed; }

.ra-amount-cell { font-family: var(--font-mono); text-align: right; font-weight: 600; color: var(--gray-700); }

.ra-card-footer {
  padding: 6px 12px;
  background: var(--gray-50);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--gray-500);
  border-top: 1px solid var(--gray-200);
}

.ra-output-note { font-style: italic; }
.ra-total-note { font-weight: 700; color: var(--navy); font-family: var(--font-mono); }

/* ── TOAST NOTIFICATIONS ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--gray-800);
  color: var(--white);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s ease;
  max-width: 320px;
}

.toast.success { background: #065f46; border-left: 3px solid var(--green); }
.toast.warning { background: #78350f; border-left: 3px solid var(--amber); }
.toast.error { background: #7f1d1d; border-left: 3px solid var(--red); }
.toast.info { background: var(--navy); border-left: 3px solid var(--blue); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── CONTEXT MENU ── */
.context-menu {
  position: fixed;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 9000;
  min-width: 180px;
  overflow: hidden;
  animation: cm-in 0.15s ease;
}

@keyframes cm-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.cm-item {
  padding: 9px 14px;
  font-size: 12px;
  color: var(--gray-700);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 7px;
}

.cm-item:hover { background: var(--gray-50); }
.cm-danger { color: var(--red); }
.cm-danger:hover { background: var(--red-bg); }

/* ── DRAG GHOST ── */
.drag-ghost {
  position: fixed;
  background: var(--navy);
  color: white;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  z-index: 9999;
  opacity: 0.9;
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none;
}

.drag-ghost.rate-ghost { background: var(--teal); }

/* ── UTILITY ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ── Column widths for subheads table ── */
.col-sr    { width: 36px; }
.col-desc  { min-width: 180px; }
.col-size  { min-width: 100px; }
.col-qty   { width: 75px; }
.col-unit  { width: 65px; }
.col-rate  { width: 90px; }
.col-amt   { width: 110px; }
.col-rem   { min-width: 100px; }
.col-act   { width: 32px; }

/* ── No items placeholder ── */
.workspace-empty-hint {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
  font-size: 12px;
}

/* ── Scrollbar for right pane ── */
.pane-right .pane-scroll::-webkit-scrollbar { width: 4px; }
.pane-right .pane-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

/* ── Highlight on drag over (drop targets) ── */
[data-drop-target]:not(.drag-ghost) {
  transition: background 0.15s, border-color 0.15s;
}

/* ============================================================
   Edit Rates Modal
   ============================================================ */

/* ── Edit Rates header button ── */
.hdr-btn-edit {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}
.hdr-btn-edit:hover { background: #6d28d9; border-color: #6d28d9; }

/* ── Overlay ── */
.er-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Modal box ── */
.er-modal {
  background: var(--navy-mid);
  border: 1px solid var(--navy-light);
  border-radius: 10px;
  width: 820px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* ── Modal header ── */
.er-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--navy);
  border-bottom: 1px solid var(--navy-light);
  flex-shrink: 0;
}
.er-title {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.3px;
}
.er-close {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.er-close:hover { background: var(--navy-light); color: #fff; }

/* ── Tabs ── */
.er-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 14px 0;
  background: var(--navy);
  flex-shrink: 0;
}
.er-tab {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--gray-400);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  letter-spacing: 0.3px;
}
.er-tab:hover { color: #e2e8f0; background: var(--navy-light); }
.er-tab.active {
  color: #e2e8f0;
  background: var(--navy-mid);
  border-color: var(--navy-light);
}

/* ── Search ── */
.er-search-bar {
  padding: 10px 14px;
  background: var(--navy-mid);
  border-bottom: 1px solid var(--navy-light);
  flex-shrink: 0;
}

/* ── Scrollable body ── */
.er-body {
  overflow-y: auto;
  flex: 1;
  padding: 0;
}

/* ── Table ── */
.er-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.er-table thead th {
  position: sticky;
  top: 0;
  background: var(--navy);
  color: var(--gray-400);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--navy-light);
  z-index: 1;
}
.er-table tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.er-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.er-table td {
  padding: 7px 12px;
  color: #cbd5e1;
  vertical-align: middle;
}
.er-td-id    { width: 80px; color: var(--teal); font-weight: 600; font-size: 11px; }
.er-td-desc  { color: #e2e8f0; }
.er-td-unit  { width: 70px; color: var(--gray-400); text-align: center; }
.er-td-rate  { width: 130px; }

/* ── Inline rate input ── */
.er-rate-input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--navy-light);
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 12px;
  padding: 4px 8px;
  text-align: right;
  font-family: inherit;
}
.er-rate-input:focus {
  outline: none;
  border-color: var(--blue-light);
  background: rgba(59,130,246,0.1);
}
.er-rate-input.saving {
  border-color: var(--amber);
  color: var(--amber);
}
.er-rate-input.saved {
  border-color: var(--green);
  color: var(--green);
}
.er-rate-input.error {
  border-color: #ef4444;
  color: #ef4444;
}

/* ── Footer ── */
.er-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--navy);
  border-top: 1px solid var(--navy-light);
  flex-shrink: 0;
}
.er-status {
  font-size: 11px;
  color: var(--gray-400);
}
.er-btn-regenerate {
  background: none;
  border: 1px solid var(--teal);
  color: var(--teal);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
}
.er-btn-regenerate:hover { background: rgba(8,145,178,0.15); }
