/* ============================================================
   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; }

/* Manual-override marker on a linked rate chip */
.ra-chip-edited {
  color: #b45309;
  font-size: 10px;
  cursor: help;
}

/* 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); }

/* Rate Analysis Card */
.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;
}

/* ══════════════════════════════════════════════════════════════
   RIGHT PANE — TABS (MoRTH Rates / Rate Analysis)
   ══════════════════════════════════════════════════════════════ */

.right-tabs {
  display: flex;
  background: var(--navy-mid);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.rt-tab {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  color: rgba(255,255,255,0.65);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.rt-tab:hover { color: rgba(255,255,255,0.9); }

.rt-tab.active {
  color: #fff;
  border-bottom-color: var(--blue-light);
  background: rgba(255,255,255,0.06);
}

/* ══════════════════════════════════════════════════════════════
   MoRTH RATES PANEL
   ══════════════════════════════════════════════════════════════ */

.morth-size-toggle {
  display: flex;
  gap: 2px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 2px;
  flex-shrink: 0;
}

.msz-btn {
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--gray-500);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.msz-btn:hover { color: var(--gray-700); }

.msz-btn.active {
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.morth-search {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.morth-search:focus { border-color: var(--blue-light); }

/* Chapter accordion */

.morth-chapter {
  border-bottom: 1px solid var(--gray-200);
}

.morth-ch-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  background: var(--gray-50);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}

.morth-ch-header:hover { background: var(--gray-100); }

.morth-ch-arrow {
  font-size: 9px;
  color: var(--gray-400);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.morth-ch-arrow.open { transform: rotate(90deg); }

.morth-ch-no {
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-bdr);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.morth-ch-title {
  flex: 1;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gray-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.morth-ch-count {
  font-size: 10px;
  color: var(--gray-400);
  background: var(--gray-100);
  border-radius: 8px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.morth-ch-selected {
  font-size: 10px;
  font-weight: 700;
  color: var(--green);
  background: var(--green-bg);
  border-radius: 8px;
  padding: 1px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.morth-ch-body.collapsed { display: none; }

/* Items */

.morth-item {
  padding: 6px 10px 7px 14px;
  border-top: 1px dashed var(--gray-200);
}

.morth-item-head {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 4px;
}

.morth-item-sr {
  font-size: 10.5px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--teal);
  white-space: nowrap;
  flex-shrink: 0;
}

.morth-item-desc {
  font-size: 11px;
  color: var(--gray-700);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Rate option rows (radio) */

.morth-opt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  margin: 2px 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  cursor: grab;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

.morth-opt:hover {
  border-color: var(--blue-bdr);
  background: var(--blue-bg);
}

.morth-opt:active { cursor: grabbing; }

.morth-opt input[type="radio"] {
  accent-color: var(--blue);
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
}

.morth-opt.selected {
  border-color: var(--blue);
  background: var(--blue-bg);
  box-shadow: 0 0 0 1px var(--blue) inset;
}

.morth-opt-label {
  flex: 1;
  font-size: 10.5px;
  color: var(--gray-600);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.morth-opt.selected .morth-opt-label {
  color: var(--gray-800);
  font-weight: 600;
}

.morth-opt-rate {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--green);
  white-space: nowrap;
  flex-shrink: 0;
}

.morth-opt-rate em {
  font-style: normal;
  font-weight: 400;
  font-size: 9.5px;
  color: var(--gray-400);
}

.morth-rate-tbd {
  font-size: 9.5px;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-bg);
  border-radius: 4px;
  padding: 1px 5px;
}

/* MoRTH-linked chip in workspace subheads */

.ra-chip.morth {
  background: var(--blue-bg);
  border-color: var(--blue-bdr);
  color: var(--blue);
}

/* ══════════════════════════════════════════════════════════════
   AUTO-ESTIMATE ON DROP
   ══════════════════════════════════════════════════════════════ */

.ws-btn-accent {
  border-color: rgba(255,255,255,0.5) !important;
  font-weight: 700;
}

.auto-badge {
  display: inline-block;
  margin-top: 3px;
  margin-left: 4px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid #fcd34d;
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
  cursor: help;
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  padding: 0 0 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  position: sticky;
  top: 0;
}

.modal-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}

.modal-close:hover { color: #fff; }

.modal-hint {
  font-size: 11.5px;
  color: var(--gray-500);
  line-height: 1.5;
  padding: 12px 18px 4px;
  margin: 0;
}

.xs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  padding: 12px 18px;
}

.xs-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.xs-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.xs-input {
  padding: 6px 9px;
  font-size: 13px;
  font-family: var(--font-mono);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  outline: none;
}

.xs-input:focus { border-color: var(--blue); }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px 18px 0;
}

.modal-btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--gray-600);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.modal-btn:hover { border-color: var(--gray-400); background: var(--gray-50); }

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

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

/* ══════════════════════════════════════════════════════════════
   SECTION-LEVEL DRAG (add whole section at one shot)
   ══════════════════════════════════════════════════════════════ */

[data-boq-section-drag] { cursor: grab; }
[data-boq-section-drag]:active { cursor: grabbing; }

.section-drag-handle {
  font-size: 10px;
  color: var(--gray-400);
  margin-right: 2px;
  flex-shrink: 0;
}

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

.boq-section-addall {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font);
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-bdr);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.13s;
}

.boq-section-addall:hover {
  background: var(--blue);
  color: #fff;
}

.boq-section-header.all-added .boq-section-addall {
  color: var(--green);
  background: var(--green-bg);
  border-color: #a7f3d0;
  pointer-events: none;
}

.boq-section-header.all-added .boq-section-addall::before { content: '✓ '; }

/* ══════════════════════════════════════════════════════════════
   QTY CALC STRIP (measurement working under AUTO rows)
   ══════════════════════════════════════════════════════════════ */

.calc-row td {
  background: #fffdf4;
  border-top: none !important;
  padding: 2px 8px 7px !important;
}

.calc-fx-cell {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  font-style: italic;
  color: var(--amber);
  vertical-align: middle;
}

.calc-strip {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.calc-eq {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  padding-bottom: 5px;
}

.calc-times {
  font-size: 12px;
  font-weight: 700;
  color: var(--amber);
  padding-bottom: 5px;
}

.calc-factor {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.calc-factor-label {
  font-size: 8.5px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.calc-factor-input {
  width: 92px;
  padding: 3px 6px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  border: 1px solid #fcd34d;
  background: var(--white);
  border-radius: 5px;
  outline: none;
  transition: border-color 0.12s;
}

.calc-factor-input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.12);
}

.calc-result {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--green);
  padding-bottom: 4px;
  white-space: nowrap;
}

/* ══════════════════════════════════════════════════════════════
   BOQ ↔ RATES LINKAGE + BOQ-as-SUBHEAD DROP
   ══════════════════════════════════════════════════════════════ */

.boq-morth-link {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-bdr);
  border-radius: 4px;
  padding: 1px 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.13s;
}

.boq-morth-link:hover {
  background: var(--blue);
  color: #fff;
}

/* Flash highlight when a linked rate is revealed in the right pane */
@keyframes morthFlash {
  0%, 60% { background: #fef3c7; border-color: var(--amber); box-shadow: 0 0 0 2px rgba(217,119,6,0.25); }
  100%    { background: var(--white); }
}

.morth-opt.morth-flash { animation: morthFlash 1.8s ease-out; }

/* Estimation card highlighted while a BOQ item hovers over it */
.est-item-card.drag-over-card {
  outline: 2px dashed var(--blue);
  outline-offset: 2px;
  background: var(--blue-bg);
}

.ra-chip.morth { cursor: pointer; }
.ra-chip.morth:hover { box-shadow: 0 0 0 1px var(--blue) inset; }

/* ══════════════════════════════════════════════════════════════
   RATE ANALYSIS TAB — MoRTH BUILD-UP SECTION
   ══════════════════════════════════════════════════════════════ */

.rp-section-title {
  padding: 9px 12px 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  position: sticky;
  top: 0;
  z-index: 2;
}

.buildup-empty {
  margin: 10px 12px;
  padding: 14px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--gray-500);
  background: var(--blue-bg);
  border: 1px dashed var(--blue-bdr);
  border-radius: var(--radius);
  text-align: center;
}

.morth-buildup-card .ra-card-header { cursor: default; }

.bu-group-row td {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-600);
  background: var(--gray-100);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px !important;
}

.morth-ch-selected { cursor: pointer; }
.morth-ch-selected:hover { box-shadow: 0 0 0 1px var(--green) inset; }

.ra-card.morth-flash { animation: morthFlash 1.8s ease-out; }

/* Compact build-up table so all 5 columns fit the pane width */
.morth-buildup-card .ra-components-table {
  table-layout: fixed;
  width: 100%;
  font-size: 10px;
}
.morth-buildup-card .ra-components-table th:nth-child(1),
.morth-buildup-card .ra-components-table td:nth-child(1) { width: 38%; word-wrap: break-word; }
.morth-buildup-card .ra-components-table th:nth-child(2),
.morth-buildup-card .ra-components-table td:nth-child(2) { width: 12%; }
.morth-buildup-card .ra-components-table th:nth-child(3),
.morth-buildup-card .ra-components-table td:nth-child(3) { width: 14%; }
.morth-buildup-card .ra-components-table th:nth-child(4),
.morth-buildup-card .ra-components-table td:nth-child(4) { width: 16%; }
.morth-buildup-card .ra-components-table th:nth-child(5),
.morth-buildup-card .ra-components-table td:nth-child(5) { width: 20%; }
.morth-buildup-card .ra-components-table th,
.morth-buildup-card .ra-components-table td { padding: 3px 5px; }

/* ══════════════════════════════════════════════════════════════
   ESTIMATE AUDIT MODAL
   ══════════════════════════════════════════════════════════════ */

.audit-body { padding: 12px 18px 4px; max-height: 60vh; overflow-y: auto; }

.audit-summary { display: flex; gap: 8px; margin-bottom: 10px; }

.audit-pill {
  font-size: 11px; font-weight: 700; border-radius: 12px; padding: 3px 10px;
}
.audit-pill.err { color: var(--red);   background: var(--red-bg); }
.audit-pill.wrn { color: var(--amber); background: var(--amber-bg); }
.audit-pill.inf { color: var(--blue);  background: var(--blue-bg); }

.audit-clean {
  padding: 18px; text-align: center; font-size: 13px; font-weight: 600;
  color: var(--green); background: var(--green-bg); border-radius: var(--radius);
}

.audit-finding {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 7px 9px; margin-bottom: 4px;
  font-size: 11.5px; line-height: 1.45;
  border-radius: var(--radius); border: 1px solid var(--gray-200);
}
.audit-finding.error { background: var(--red-bg);   border-color: var(--red-bdr); }
.audit-finding.warn  { background: var(--amber-bg); border-color: #fcd34d; }
.audit-finding.info  { background: var(--gray-50); }
.audit-finding[data-goto-main] { cursor: pointer; }
.audit-finding[data-goto-main]:hover { filter: brightness(0.97); }
.audit-icon { flex-shrink: 0; }

.est-item-card.morth-flash { animation: morthFlash 1.8s ease-out; }

/* ══════════════════════════════════════════════════════════════
   PRINT — estimate only, full width
   ══════════════════════════════════════════════════════════════ */

@media print {
  .app-header, .pane-labels-bar, .pane-left, .pane-right,
  .toast-container, .modal-overlay, .drop-zone-bottom, .drop-zone-master,
  .table-footer-actions, .btn-del-row, .est-item-menu-btn, .template-bar,
  .meas-del, .meas-btn, .meas-hint, .abs-rowactions, .abs-actions { display: none !important; }
  /* The abstract panel prints — the estimate now carries its own totals page */
  .abstract-card { break-inside: avoid; box-shadow: none !important; border: 1px solid #999; }
  .workspace { display: block !important; height: auto !important; }
  .pane-center { width: 100% !important; overflow: visible !important; }
  .center-scroll { overflow: visible !important; height: auto !important; }
  .est-item-card { break-inside: avoid; box-shadow: none !important; border: 1px solid #999; }
  .est-item-body { max-height: none !important; }
  body { background: #fff; }
}

/* Build-up index strip — one chip per selection, newest first */
.buildup-index {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 12px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.buildup-index-chip {
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--blue);
  background: var(--blue-bg);
  border: 1px solid var(--blue-bdr);
  border-radius: 10px;
  padding: 2px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.13s;
}

.buildup-index-chip:hover {
  background: var(--blue);
  color: #fff;
}

.buildup-index-chip:first-child {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-bg);
}

.buildup-index-chip:first-child:hover {
  background: var(--green);
  color: #fff;
}

/* ══════════════════════════════════════════════════════════════
   BACKEND MODE — login, project home, modals, save status
   ══════════════════════════════════════════════════════════════ */

.save-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 10px;
  white-space: nowrap;
}
.ss-saving { background: #fef3c7; color: #92400e; }
.ss-saved  { background: #d1fae5; color: #065f46; }
.ss-error  { background: #fee2e2; color: #991b1b; }

.bk-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: linear-gradient(135deg, #0f2647 0%, #1a3a63 60%, #14532d 140%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.bk-card {
  background: #fff;
  border-radius: 14px;
  padding: 36px 40px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  text-align: center;
}

.bk-logo {
  width: 54px; height: 54px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1d4ed8, #059669);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.bk-logo-sm { width: 34px; height: 34px; font-size: 15px; border-radius: 8px; margin: 0; }

.bk-card h1 { margin: 4px 0 2px; font-size: 24px; color: #0f2647; }
.bk-sub { color: #64748b; font-size: 12px; margin-bottom: 22px; }

.bk-card form { text-align: left; }
.bk-card label, .bk-modal-box label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 12px;
}
.bk-card input, .bk-modal-box input, .bk-modal-box select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
}
.bk-card input:focus, .bk-modal-box input:focus, .bk-modal-box select:focus {
  outline: none;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(29,78,216,0.12);
}

.bk-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e293b;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.bk-btn:hover { background: #f1f5f9; }
.bk-btn-primary { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.bk-btn-primary:hover { background: #1e40af; }
.bk-btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.bk-btn-danger:hover { background: #b91c1c; }
.bk-btn-block { width: 100%; padding: 11px; margin-top: 4px; }

.bk-error { color: #dc2626; font-size: 12px; min-height: 16px; margin: 6px 0; }
.bk-hint { color: #64748b; font-size: 12px; }

/* Project home */
.bk-home { flex-direction: column; align-items: stretch; justify-content: flex-start; }
.bk-home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.bk-home-brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; font-weight: 700; font-size: 16px;
}
.bk-home-user { display: flex; align-items: center; gap: 8px; color: #e2e8f0; font-size: 13px; }
.bk-home-body { padding: 26px; max-width: 1100px; width: 100%; margin: 0 auto; box-sizing: border-box; }
.bk-home-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }

.bk-proj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}
.bk-proj-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  transition: transform 0.12s, box-shadow 0.12s;
}
.bk-proj-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,0.26); }
.bk-proj-name { font-weight: 700; font-size: 15px; color: #0f2647; margin-bottom: 6px; padding-right: 20px; }
.bk-proj-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: #64748b; margin-bottom: 8px; }
.bk-proj-total { font-size: 17px; font-weight: 800; color: #059669; margin-bottom: 4px; }
.bk-proj-when { font-size: 11px; color: #94a3b8; }
.bk-proj-actions {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s;
}
.bk-proj-card:hover .bk-proj-actions { opacity: 1; }
.bk-icon-btn {
  border: none; background: #f1f5f9; border-radius: 6px;
  width: 26px; height: 26px; cursor: pointer; font-size: 12px;
}
.bk-icon-btn:hover { background: #e2e8f0; }
.bk-icon-btn.bk-danger:hover { background: #fee2e2; }

.bk-empty { color: #cbd5e1; text-align: center; padding: 60px 0; font-size: 15px; }

/* Backend modals */
.bk-modal-overlay {
  position: fixed; inset: 0; z-index: 4000;
  background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
}
.bk-modal-box {
  background: #fff; border-radius: 12px;
  padding: 22px 26px;
  width: 440px; max-width: 94vw;
  max-height: 88vh; overflow: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  text-align: left;
}
.bk-modal-box.bk-modal-wide { width: 780px; }
.bk-modal-box h3 { margin: 0 0 14px; color: #0f2647; }
.bk-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.bk-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.bk-form-grid label:first-child { grid-column: 1 / -1; }
.bk-map-grid label:first-child { grid-column: auto; }

.bk-boq-choice { border-top: 1px solid #e2e8f0; margin-top: 8px; padding-top: 10px; }
.bk-boq-choice label { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; margin-bottom: 8px; }
.bk-boq-choice input[type="radio"] { width: auto; margin-top: 2px; }

.bk-preview-wrap { max-height: 260px; overflow: auto; border: 1px solid #e2e8f0; border-radius: 8px; margin-top: 8px; }
.bk-preview { border-collapse: collapse; font-size: 11px; width: 100%; }
.bk-preview td { border: 1px solid #f1f5f9; padding: 3px 6px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.bk-preview .bk-rowno { background: #f8fafc; color: #94a3b8; font-weight: 600; }
.bk-preview .bk-hdr-row td { background: #eff6ff; font-weight: 600; }

.bk-users-table { border-collapse: collapse; width: 100%; font-size: 13px; margin-bottom: 14px; }
.bk-users-table th, .bk-users-table td { border: 1px solid #e2e8f0; padding: 6px 10px; text-align: left; }
.bk-users-table th { background: #f8fafc; }

.bk-fatal p { color: #64748b; font-size: 13px; }

/* ══════════════════════════════════════════════════════════════
   MEASUREMENT SHEETS
   ══════════════════════════════════════════════════════════════ */

.meas-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 9px;
  border: 1px solid var(--gray-300);
  background: var(--gray-100);
  color: var(--gray-500);
  cursor: pointer;
  margin-left: 5px;
  user-select: none;
}
.meas-chip:hover { border-color: var(--teal); color: var(--teal); }
.meas-chip.has-meas {
  background: #ecfeff;
  border-color: #a5f3fc;
  color: #0e7490;
  font-weight: 700;
}

.cell-input.meas-locked {
  background: #ecfeff;
  color: #0e7490;
  font-weight: 700;
  cursor: not-allowed;
}

.meas-row > .meas-fx-cell {
  text-align: center;
  font-size: 12px;
  background: #ecfeff;
  border-right: 2px solid #a5f3fc !important;
  vertical-align: top;
  padding-top: 10px !important;
}
.meas-row > td { background: #f8feff; }

.meas-sheet { padding: 6px 4px 8px; }

.meas-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.meas-table th {
  text-align: left;
  font-size: 9px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #0e7490;
  padding: 2px 6px;
  border-bottom: 1px solid #a5f3fc;
}
.meas-table td { padding: 2px 4px; border-bottom: 1px solid #e0f7fa; }

.meas-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  background: transparent;
}
.meas-input:hover { border-color: var(--gray-300); background: #fff; }
.meas-input:focus { outline: none; border-color: var(--teal); background: #fff; box-shadow: 0 0 0 2px rgba(8,145,178,0.12); }
.meas-num { max-width: 76px; text-align: right; font-family: var(--font-mono); }

.meas-qty {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #0e7490;
  min-width: 70px;
}
.meas-qty.ded { color: var(--red); }
.meas-ded-line .meas-input { color: var(--red); }

.meas-del {
  border: none;
  background: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
}
.meas-del:hover { background: var(--red-bg); color: var(--red); }

.meas-empty { color: var(--gray-400); font-style: italic; padding: 8px 6px !important; }

.meas-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.meas-btn {
  border: 1px solid #a5f3fc;
  background: #fff;
  color: #0e7490;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.meas-btn:hover { background: #ecfeff; }
.meas-btn-ded { color: var(--red); border-color: var(--red-bdr); }
.meas-btn-ded:hover { background: var(--red-bg); }
.meas-total-wrap { font-size: 11px; color: var(--gray-600); margin-left: auto; }
.meas-total { font-family: var(--font-mono); color: #0e7490; font-size: 12px; }
.meas-hint { font-size: 9px; color: var(--gray-400); }

/* ══════════════════════════════════════════════════════════════
   ABSTRACT OF COST PANEL
   ══════════════════════════════════════════════════════════════ */

#abstract-panel { padding: 14px 16px 26px; }

.abstract-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.abs-header {
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 9px 16px;
}

.abs-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.abs-table td { padding: 7px 10px; border-bottom: 1px solid var(--gray-100); }

.abs-sl { width: 40px; color: var(--gray-500); font-weight: 700; font-size: 11px; }
.abs-works td { font-weight: 700; background: var(--gray-50); }

.abs-input {
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  background: transparent;
  width: 100%;
}
.abs-input:hover { border-color: var(--gray-300); background: #fff; }
.abs-input:focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }

.abs-valcell { display: flex; gap: 6px; align-items: center; width: 170px; }
.abs-val { max-width: 84px; text-align: right; font-family: var(--font-mono); }
.abs-type {
  border: 1px solid var(--gray-200);
  border-radius: 5px;
  font-size: 10px;
  padding: 3px 4px;
  background: var(--gray-50);
  color: var(--gray-600);
}

.abs-amount {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  width: 150px;
}

.abs-rowactions { width: 66px; text-align: right; white-space: nowrap; }
.abs-rowactions input[type="checkbox"] { cursor: pointer; }
.abs-del {
  border: none; background: none; color: var(--gray-400);
  cursor: pointer; font-size: 10px; padding: 2px 5px; border-radius: 4px;
}
.abs-del:hover { background: var(--red-bg); color: var(--red); }

.abs-off td { opacity: 0.45; }
.abs-off .abs-rowactions { opacity: 1; }

.abs-total-row td {
  font-weight: 700;
  border-top: 2px solid var(--gray-300);
  background: var(--gray-50);
}
.abs-sanction-row td {
  font-weight: 800;
  font-size: 13px;
  background: var(--green-bg);
  color: var(--green);
  border-bottom: none;
}
.abs-note { font-size: 9px; color: var(--gray-400); font-weight: 400; }

.abs-actions { padding: 8px 12px; }
.abs-add-btn {
  border: 1px dashed var(--gray-300);
  background: none;
  color: var(--gray-500);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 11px;
  cursor: pointer;
}
.abs-add-btn:hover { border-color: var(--blue); color: var(--blue); }
