/* === Cost-Benefit Analysis Plugin === */
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Inter:wght@300;400;500;600&display=swap');

.cest-wrap {
  --ce-bg:       #f0f9ff;
  --ce-card:     #ffffff;
  --ce-card2:    #e0f2fe;
  --ce-border:   #bae6fd;
  --ce-blue:     #03a9f4;
  --ce-navy:     #0a1a2e;
  --ce-text:     #1a2e3d;
  --ce-muted:    #5a7a8a;
  --ce-success:  #1b5e20;
  --ce-amber:    #e65100;
  --ce-red:      #b71c1c;
  --ce-radius:   10px;
  --ce-font:     'Inter', sans-serif;
  --ce-mono:     'DM Mono', monospace;

  font-family: var(--ce-font);
  background: var(--ce-bg);
  color: var(--ce-text);
  border-radius: 14px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
  box-sizing: border-box;
}
.cest-wrap *, .cest-wrap *::before, .cest-wrap *::after { box-sizing: border-box; }

/* Header — no icon */
.cest-header { display:flex; align-items:center; gap:14px; margin-bottom:18px; }
.cest-title { font-size:20px; font-weight:600; margin:0 0 2px; color:var(--ce-navy); }

/* Instructions */
.cest-instructions {
  display:flex; align-items:center; flex-wrap:wrap; gap:8px;
  background:var(--ce-card2); border:1px solid var(--ce-border);
  border-radius:var(--ce-radius); padding:10px 16px;
  font-size:13px; color:var(--ce-text); margin-bottom:18px;
}
.cest-step-pill {
  display:inline-flex; align-items:center; justify-content:center;
  width:22px; height:22px; background:var(--ce-blue); color:#fff;
  border-radius:50%; font-size:12px; font-weight:600; flex-shrink:0;
}
.cest-arrow { color:var(--ce-muted); font-size:16px; }

/* Top panels row — panels 1 & 2 side by side at 1/2 each */
.cest-top-panels {
  display:grid; grid-template-columns:1fr 1fr; gap:14px;
  margin-bottom:14px;
}
@media (max-width:768px) { .cest-top-panels { grid-template-columns:1fr; } }

/* Panel 3 — full width */
.cest-panel3-wrap {
  margin-bottom:16px;
}

.cest-dropdown-panel {
  background:var(--ce-card); border:1px solid var(--ce-border);
  border-radius:var(--ce-radius); overflow:hidden;
  display:flex; flex-direction:column;
}

.cest-panel-header {
  background:var(--ce-blue); color:#fff;
  padding:8px 12px; font-size:12px; font-weight:600;
  display:flex; align-items:center; gap:8px; letter-spacing:0.02em;
  text-transform:uppercase;
}

.cest-level-badge {
  display: none;  /* badge ovals removed per requirements */
}
.cest-l2-badge { display: none; }
.cest-l3-badge { display: none; }

/* .cest-select-all rules removed in v15 — buttons removed */

.cest-panel-body {
  flex:1; overflow-y:auto; max-height:280px; padding:6px 0;
  min-height:80px;
  position: relative;
}
.cest-panel-body-l3 { max-height:400px; padding:0; } /* Fix 4: +25% height (320→400px) */

/* Hint text below panel 3 */
.cest-panel3-hint {
  padding:6px 14px 8px;
  font-size:11px; color:var(--ce-muted);
  font-style:italic; border-top:1px solid var(--ce-border);
  background:var(--ce-card);
  text-align:right;
}

.cest-loading, .cest-empty-msg {
  font-size:13px; color:var(--ce-muted); padding:20px 16px;
  text-align:center; font-style:italic;
}

/* Checkbox rows — L1 and L2 */
.cest-check-row {
  display:flex; align-items:center; gap:10px;
  padding:4px 14px; cursor:pointer;
  transition:background 0.1s; border-bottom:1px solid #f0f9ff;
}
.cest-check-row:hover { background:var(--ce-card2); }
.cest-check-row input[type=checkbox] { width:15px; height:15px; cursor:pointer; accent-color:var(--ce-blue); }
.cest-check-label { font-size:13px; color:var(--ce-text); flex:1; }

/* L3 rows — wider with editable inputs */
.cest-l3-row {
  display:grid;
  grid-template-columns:20px 1fr 90px 110px 110px;
  align-items:center; gap:8px;
  padding:3px 14px; cursor:pointer;
  transition:background 0.1s; border-bottom:1px solid #f0f9ff;
}
.cest-l3-row:hover { background:var(--ce-card2); }
.cest-l3-row.checked { background:#e8f5e9; }
.cest-l3-row input[type=checkbox] { width:15px; height:15px; cursor:pointer; accent-color:var(--ce-blue); }
.cest-l3-name { font-size:13px; color:var(--ce-text); font-weight:500; }

/* Editable inputs in Panel 3 */
.cest-l3-input {
  width:100%; text-align:right;
  border:1px solid var(--ce-border); border-radius:5px;
  padding:4px 6px; font-size:12px; font-family:var(--ce-mono);
  background:#fff; color:var(--ce-text);
  transition:border-color 0.15s, color 0.15s;
  -moz-appearance:textfield;
}
.cest-l3-input::-webkit-outer-spin-button,
.cest-l3-input::-webkit-inner-spin-button { -webkit-appearance:none; margin:0; }
.cest-l3-input:focus {
  outline:none; border-color:var(--ce-blue);
  background:#f0f9ff;
}
.cest-l3-input-risk { color:var(--ce-text); }

/* L3 header row — sticky at top of scrolling panel */
.cest-l3-header {
  display:grid;
  grid-template-columns:20px 1fr 90px 110px 110px;
  gap:8px; padding:4px 14px;
  background:#e0f2fe; border-bottom:1px solid var(--ce-border);
}
.cest-l3-header-sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e0f2fe;
}
.cest-l3-header span { font-size:10px; font-weight:600; color:var(--ce-muted); text-transform:uppercase; letter-spacing:0.06em; }
.cest-l3-header .r { text-align:right; }

/* Results appear directly below panel 3 with tight spacing */
/* Results */
.cest-results { margin-top:4px; }

.cest-results-header {
  background:var(--ce-blue); color:#fff;
  border-radius:var(--ce-radius) var(--ce-radius) 0 0;
  padding:12px 18px; display:flex; align-items:center;
  justify-content:space-between;
}
.cest-results-title { font-size:15px; font-weight:600; }

.cest-print-btn {
  background:rgba(255,255,255,0.2); color:#fff;
  border:none; border-radius:6px; padding:6px 14px;
  font-size:12px; font-weight:500; font-family:var(--ce-font); cursor:pointer;
  transition:opacity 0.15s; display:flex; align-items:center;
}
.cest-print-btn:hover { opacity:0.8; }

/* Summary cards */
.cest-summary-cards {
  display:grid; grid-template-columns:repeat(4,1fr); gap:10px;
  background:var(--ce-card2); padding:14px;
  border-left:1px solid var(--ce-border); border-right:1px solid var(--ce-border);
}
@media (max-width:600px) { .cest-summary-cards { grid-template-columns:1fr 1fr; } }

.cest-summary-card {
  background:var(--ce-card); border:1px solid var(--ce-border);
  border-radius:8px; padding:12px 14px; text-align:center;
}
.cest-summary-label { font-size:10px; text-transform:uppercase; letter-spacing:0.08em; color:var(--ce-muted); margin-bottom:6px; }
.cest-summary-value { font-size:18px; font-weight:600; font-family:var(--ce-mono); color:var(--ce-navy); }
.cest-summary-value.total { color: #2e7d32; }   /* green for positive */
.cest-summary-value.total.negative { color: #b71c1c; }  /* red for negative */

/* Results table */
.cest-table-wrap { overflow-x:auto; border:1px solid var(--ce-border); }

.cest-results-table {
  width:100%; border-collapse:collapse; font-size:13px;
}
.cest-results-table th {
  background:var(--ce-navy); color:#fff;
  padding:9px 12px; text-align:left; font-size:11px;
  font-weight:600; letter-spacing:0.04em; text-transform:uppercase;
  white-space:nowrap;
}
.cest-results-table th.num { text-align:right; }
.cest-results-table td {
  padding:9px 12px; border-bottom:1px solid #e0f2fe; color:var(--ce-text);
}
.cest-results-table td.num { text-align:right; font-family:var(--ce-mono); }
.cest-results-table tbody tr:hover { background:var(--ce-card2); }
.cest-results-table tbody tr:nth-child(even) { background:#f8fcff; }
.cest-results-table tfoot td {
  background:var(--ce-navy); color:#fff; font-weight:600;
  padding:10px 12px; font-family:var(--ce-mono);
  border-top:2px solid var(--ce-blue);
}
.cest-results-table tfoot td.num { text-align:right; }
/* tfoot total colours are set inline based on sign (see calculateSilent) */

/* No path column in results table */

/* Print styles */
@media print {
  .cest-instructions, .cest-top-panels, .cest-panel3-wrap,
  .cest-print-btn { display:none !important; }
  .cest-wrap { background:#fff !important; padding:0 !important; }
  .cest-results { display:block !important; }
  .cest-results-header { background:#03a9f4 !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  .cest-results-table th { background:#0a1a2e !important; -webkit-print-color-adjust:exact; print-color-adjust:exact; }
}

/* Branch nodes in Panel 3 */
.cest-l3-branch {
  grid-template-columns: 20px 1fr auto !important;
  opacity: 0.75;
}
.cest-l3-branch-note {
  font-size: 11px;
  color: var(--ce-muted);
  font-style: italic;
  padding-left: 4px;
}


/* ═══════════════════════════════════════════════════════════════
   Cost-Benefit Modal Bridge (opened from NPV Calculator)
═══════════════════════════════════════════════════════════════ */

.cest-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.62);
  z-index: 1000000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.cest-modal-shell {
  background: #f0f9ff;
  border-radius: 16px;
  width: 100%;
  max-width: 1060px;
  margin-top: 80px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 14px 60px rgba(0,0,0,0.38);
}

/* Titlebar */
.cest-modal-titlebar {
  background: #03a9f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  gap: 12px;
  flex-shrink: 0;
}
.cest-modal-titlebar-left  { display:flex; flex-direction:column; gap:2px; }
.cest-modal-titlebar-right { display:flex; align-items:center; gap:10px; }
.cest-modal-title    { font-size:17px; font-weight:600; color:#fff; font-family:var(--ce-font,'Inter',sans-serif); }
.cest-modal-subtitle { font-size:11px; color:rgba(255,255,255,0.8); font-family:var(--ce-mono,'DM Mono',monospace); }

.cest-modal-close-btn {
  background:none; border:none; color:#fff;
  font-size:26px; cursor:pointer; line-height:1; padding:0 4px; opacity:0.85;
}
.cest-modal-close-btn:hover { opacity:1; }

/* Status bar */
.cest-modal-statusbar {
  background: rgba(3,169,244,0.1);
  border-bottom: 1px solid #bae6fd;
  padding: 5px 18px;
  flex-shrink: 0;
}
.cest-modal-statusmsg {
  font-size: 12px;
  font-family: var(--ce-mono,'DM Mono',monospace);
  color: #1a2e3d;
}
.cest-modal-statusmsg.ok     { color: #1b5e20; }
.cest-modal-statusmsg.error  { color: #b71c1c; }
.cest-modal-statusmsg.info   { color: #0d47a1; }
.cest-modal-statusmsg.saving { color: #e65100; }

/* Body */
.cest-modal-body {
  overflow-y: auto;
  padding: 14px 16px 8px;
  flex: 1;
}

/* Remove outer padding/radius on the inner cest-wrap inside modal */
.cest-modal-body .cest-wrap {
  background: transparent;
  padding: 0;
  border-radius: 0;
  max-width: 100%;
}

/* Footer */
.cest-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  background: rgba(3,169,244,0.08);
  border-top: 1px solid #bae6fd;
  flex-shrink: 0;
  gap: 10px;
}
.cest-modal-footer-left  { display:flex; align-items:center; }
.cest-modal-footer-right { display:flex; gap:8px; }

.cest-modal-ida-label {
  font-size: 12px;
  font-family: var(--ce-mono,'DM Mono',monospace);
  color: #5a7a8a;
}

.cest-modal-footer-btn {
  border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 13px; font-weight: 500;
  font-family: var(--ce-font,'Inter',sans-serif);
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.cest-modal-footer-btn:active { transform: scale(0.98); }

.cest-modal-btn-save {
  background: #0a1a2e;
  color: #5DCBFD;
}
.cest-modal-btn-save:hover { opacity: 0.85; }

/* .cest-modal-btn-update removed — Update Calculator footer button replaced by always-visible panel */

.cest-modal-btn-close {
  background: rgba(3,169,244,0.15);
  color: #0a1a2e;
}
.cest-modal-btn-close:hover { background: rgba(3,169,244,0.28); }

@media (max-width:600px) {
  .cest-modal-overlay { padding:0; align-items:flex-start; }
  .cest-modal-shell   { border-radius:0; min-height:100vh; margin-top:0; }
}

@media print {
  .cest-modal-titlebar,
  .cest-modal-statusbar,
  .cest-modal-footer,
  .cest-top-panels,
  .cest-panel3-wrap,
  .cest-action-bar { display:none !important; }
  .cest-modal-overlay { position:static !important; background:none !important; padding:0 !important; }
  .cest-modal-shell   { box-shadow:none !important; border-radius:0 !important; }
  .cest-modal-body    { overflow:visible !important; padding:0 !important; }
  .cest-results       { display:block !important; }
}

/* ═══════════════════════════════════════════════════════════════
   Project Life & Cash Flow Settings
   Always-visible panel — no open/close button needed.
═══════════════════════════════════════════════════════════════ */
.cest-project-life-panel {
  margin-top: 12px;
  border: 2px solid var(--ce-blue, #03a9f4);
  border-radius: var(--ce-radius, 8px);
  background: #f0f9ff;
  overflow: hidden;
}
.cest-project-life-header {
  padding: 12px 16px; background: var(--ce-navy, #0a1a2e); color: #fff;
}
.cest-project-life-title {
  font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
}
.cest-project-life-body {
  padding: 16px 20px;
}
.cest-project-life-fields {
  display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start;
  margin-bottom: 14px;
}
.cest-project-life-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px;
}
.cest-dialog-desc {
  font-size: 13px;
  color: var(--ce-muted, #5a7a8a);
  margin: 0 0 16px;
  line-height: 1.5;
}

.cest-dialog-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}
.cest-dialog-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cest-dialog-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ce-text, #1a2e3d);
  letter-spacing: 0.02em;
}
.cest-dialog-field input[type=number] {
  border: 1px solid var(--ce-border, #bae6fd);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--ce-mono,'DM Mono',monospace);
  color: var(--ce-text, #1a2e3d);
  background: #f0f9ff;
  width: 120px;
  -moz-appearance: textfield;
  text-align: center;
}
.cest-dialog-field input[type=number]::-webkit-outer-spin-button,
.cest-dialog-field input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cest-dialog-field input[type=number]:focus {
  outline: none;
  border-color: #03a9f4;
  background: #fff;
}

/* Spinner row for Project Life */
.cest-dialog-spinner {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cest-spinner-btn {
  width: 32px;
  height: 36px;
  border: 1px solid var(--ce-border, #bae6fd);
  border-radius: 7px;
  background: #e0f2fe;
  color: var(--ce-navy, #0a1a2e);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  flex-shrink: 0;
}
.cest-spinner-btn:hover { background: #bae6fd; }
.cest-spinner-btn:active { background: #93d4f5; }
.cest-dialog-hint {
  font-size: 11px;
  color: var(--ce-muted, #5a7a8a);
  font-style: italic;
}

/* Preview table inside dialog */
.cest-dialog-preview {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: var(--ce-mono,'DM Mono',monospace);
  color: #1a2e3d;
  line-height: 1.8;
  min-height: 36px;
}
.cest-dialog-preview-row { display: flex; justify-content: space-between; }
.cest-dialog-preview-row.preview-initial { color: #0d47a1; font-weight: 600; margin-bottom: 4px; border-bottom: 1px solid #bae6fd; padding-bottom: 4px; }
.cest-dialog-preview-neg { color: #b71c1c; }

.cest-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  background: #f8fcff;
  border-top: 1px solid #bae6fd;
}
.cest-dialog-btn {
  border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 13px; font-weight: 500;
  font-family: var(--ce-font,'Inter',sans-serif);
  cursor: pointer; transition: opacity 0.15s;
}
.cest-dialog-btn-cancel {
  background: rgba(3,169,244,0.12);
  color: #0a1a2e;
}
.cest-dialog-btn-cancel:hover { background: rgba(3,169,244,0.22); }

.cest-dialog-btn-apply {
  background: #0a1a2e;
  color: #5DCBFD;
}
.cest-dialog-btn-apply:hover { opacity: 0.85; }

/* ── Ghost rows (checked items from other sub-categories) ─── */
.cest-l3-ghost-section {
  background: #f0f9ff;
  border-bottom: 2px solid var(--ce-border);
  padding-bottom: 2px;
}
.cest-l3-ghost-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ce-blue);
  padding: 4px 14px 2px;
}
.cest-l3-ghost {
  background: #e8f5ff;
  opacity: 0.92;
}
.cest-l3-ghost:hover { background: #d4ecff; }

/* ── Life preview rows in Update Calculator dialog ─────────── */
.cest-dialog-preview-row.preview-life {
  color: #0d47a1;
  font-size: 11px;
  border-top: 1px solid #bae6fd;
  margin-top: 2px;
  padding-top: 2px;
}

/* ── Add Item button below Panel 3 ─────────────────────────── */
.cest-panel3-add-row {
  padding: 6px 14px 8px;
  background: var(--ce-card);
  border-top: 1px solid var(--ce-border);
  display: flex;
  align-items: center;
}

.cest-add-item-btn {
  display: inline-flex;
  align-items: center;
  background: #03a9f4;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--ce-font, 'Inter', sans-serif);
  cursor: pointer;
  transition: opacity 0.15s;
}
.cest-add-item-btn:hover { opacity: 0.82; }

/* ── Custom row section header ──────────────────────────────── */
.cest-custom-section {
  background: #f0f9ff;
  border-bottom: 2px solid #03a9f4;
}
.cest-custom-section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #03a9f4;
  padding: 4px 14px 2px;
}

/* ── Custom row (name is editable input) ────────────────────── */
.cest-l3-row.cest-l3-custom {
  background: #e8f5ff;
  grid-template-columns: 20px 1fr 90px 110px 110px 28px;
}
.cest-l3-row.cest-l3-custom:hover { background: #d4ecff; }

.cest-l3-name-input {
  width: 100%;
  border: 1px solid #bae6fd;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--ce-font, 'Inter', sans-serif);
  background: #fff;
  color: #1a2e3d;
}
.cest-l3-name-input:focus {
  outline: none;
  border-color: #03a9f4;
}
.cest-l3-name-input[readonly] {
  background: transparent;
  border-color: transparent;
  cursor: default;
  padding-left: 0;
}

/* Delete button inside a custom row */
.cest-l3-delete-btn {
  background: none;
  border: none;
  color: #b71c1c;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
  flex-shrink: 0;
}
.cest-l3-delete-btn:hover { opacity: 1; }

/* ── Dynamically-loaded child groups (v6e) ────────────────────── */
.cest-l3-child-group {
  border-left: 3px solid var(--ce-blue, #03a9f4);
  margin-left: 18px;
  margin-bottom: 2px;
  background: #f0f9ff;
}
.cest-l3-child-header {
  padding: 4px 10px 4px 10px;
  background: #bae6fd;
  font-size: 11px;
  font-weight: 700;
  color: var(--ce-navy, #0a1a2e);
  border-bottom: 1px solid #93c5fd;
}
.cest-l3-child-label {
  font-family: var(--ce-font, Arial, sans-serif);
  letter-spacing: 0.02em;
}
/* Indent child rows slightly to visually nest them */
.cest-l3-child-row {
  padding-left: 22px !important;
}
.cest-l3-child-row:hover  { background: #e0f2fe; }
.cest-l3-child-row.checked { background: #dcfce7; }
