:root {
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --border-subtle: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --success: #10b981;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text-main);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Utility */
.cf-number,
.metric-value,
.table-input {
  font-family: "Inter", monospace;
  font-variant-numeric: tabular-nums;
}

.mt8 {
  margin-top: 8px;
}

.neg {
  color: var(--danger);
}

/* Sensitivity Table */
.sensitivity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: "Inter", monospace;
}

.sensitivity-table th,
.sensitivity-table td {
  padding: 8px;
  text-align: center;
  border: 1px solid var(--border-subtle);
}

.sensitivity-table th {
  background: #f8fafc;
  font-weight: 600;
}

.sens-cell-good {
  background-color: #dcfce7;
  color: #166534;
}

.sens-cell-ok {
  background-color: #f0fdf4;
  color: #166534;
}

@media print {
  @page {
    margin: 0.5cm;
    size: landscape;
  }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    width: 100% !important;
    min-width: 100% !important;
    /* Scale down slightly to ensure everything fits */
    zoom: 0.9;
  }

  /* Hide sticky headers and navigation */
  .app-header,
  .sticky-kpi-bar,
  .section-nav,
  .btn,
  header button,
  .field-hint,
  .section-kicker,
  .section-header-sub,
  .toggle-icon,
  .app-header-sub {
    display: none !important;
  }

  body.no-print-cashflow #cashflow {
    display: none !important;
  }

  .app-shell {
    display: block;
    min-height: auto;
  }

  main.page {
    padding: 0 !important;
    display: block !important;
  }

  .page-inner {
    max-width: none !important;
    width: 100% !important;
    gap: 10px !important;
  }

  .app-section {
    break-inside: avoid;
    page-break-inside: avoid;
    border: none !important;
    padding: 0 !important;
    margin-bottom: 20px !important;
    box-shadow: none !important;
  }

  .section-header {
    border-bottom: 2px solid #000 !important;
    margin-bottom: 10px !important;
    padding-bottom: 5px !important;
  }

  /* Ensure charts fit */
  .chart-container,
  canvas {
    break-inside: avoid;
    page-break-inside: avoid;
    max-width: 100% !important;
    max-height: 300px !important;
    width: 100% !important;
  }

  /* Force flex containers to wrap or stack if needed, but for side-by-side charts try to keep them */
  #summary .section-body>div:first-child {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 10px !important;
  }

  #summary .section-body>div:first-child>div {
    flex: 1 1 50% !important;
    border: 1px solid #ccc !important;
    padding: 5px !important;
  }

  /* Adjust font sizes for print */
  body,
  td,
  th,
  input,
  .metric-value {
    font-size: 9pt !important;
  }

  h2 {
    font-size: 14pt !important;
  }

  h3 {
    font-size: 12pt !important;
  }

  /* Ensure tables print nicely */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    table-layout: fixed;
    /* Help fit columns */
  }

  th,
  td {
    border: 1px solid #ddd !important;
    padding: 4px !important;
    word-wrap: break-word;
  }

  /* Hide scrollbars */
  .table-wrapper,
  .cashflow-wrapper {
    overflow: visible !important;
    max-height: none !important;
    border: none !important;
    display: block !important;
  }

  /* Specific fix for cashflow table to allow horizontal scrolling if absolutely needed, 
     but preferably fit. Zoom helps. */
  .cashflow-wrapper table {
    table-layout: auto !important;
    /* Allow cashflow to expand */
    font-size: 8pt !important;
    /* Smaller font for cashflow */
  }
}

.sens-cell-bad {
  background-color: #fee2e2;
  color: #991b1b;
}

.sens-cell-neutral {
  background-color: #fff;
}

.sens-header-row {
  background-color: #f1f5f9;
}

.sens-header-col {
  background-color: #f1f5f9;
  font-weight: 600;
}

/* Inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

/* Layout */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 12px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.app-header-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.app-header h1 {
  font-size: 18px;
}

.app-header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* Navigation */
.section-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.section-nav button {
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.section-nav button:hover {
  border-color: var(--text-muted);
  color: var(--text-main);
}

/* KPI Bar */
.sticky-kpi-bar {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 8px 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 8px;
  background-color: #f1f5f9;
  border-radius: 6px;
  max-width: 100vw;
  /* Ensure it doesn't overflow viewport width */
  white-space: nowrap;
  /* Prevent wrapping */
}

.sticky-kpi-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 16px;
  border-right: 1px solid var(--border-subtle);
}

.sticky-kpi-chip:last-child {
  border-right: none;
}

.sticky-kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.sticky-kpi-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

/* Waterfall Container */
.waterfall-container {
  background-color: #f1f5f9;
  /* Slate 100 - Neutral */
  border: 1px solid #cbd5e1;
  /* Slate 300 */
  border-radius: 8px;
  padding: 16px;
}

/* Ensure cards inside have white background - increased specificity */
#equityWaterfall .waterfall-container .card {
  background-color: #ffffff !important;
  border: 1px solid var(--border-subtle);
}

/* Waterfall Table Row Height */
#equityWaterfall table td {
  padding: 12px 16px;
}

/* Main Content */
main.page {
  padding: 24px;
  display: flex;
  justify-content: center;
}

.page-inner {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Sections */
section.app-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 24px;
  scroll-margin-top: 140px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 16px;
  cursor: pointer;
  /* Make header clickable */
}

.section-header .toggle-icon {
  transition: transform 0.2s;
}

.section-header.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.section-body {
  transition: opacity 0.2s;
}

.section-body.collapsed {
  display: none;
}

.dev-subsection-title {
  font-size: 12px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 8px;
  color: var(--text-main);
}

.section-kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.section-header h2 {
  font-size: 18px;
  color: var(--text-main);
}

.section-header-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Grid & Fields */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

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

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  min-height: 28px;
  /* Force 2 lines for alignment */
  line-height: 1.2;
  display: flex;
  align-items: flex-end;
  /* Align text to bottom near input */
}

.field-hint {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field select {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  font-size: 13px;
  color: var(--text-main);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.field input[readonly] {
  background: #f8fafc;
  color: var(--text-muted);
  border-color: transparent;
}

/* Tables */
.table-wrapper {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow-x: auto;
  margin-top: 12px;
}

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

thead th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

thead th:first-child {
  text-align: left;
}

td {
  padding: 0;
  border-bottom: 1px solid var(--border-subtle);
  text-align: center;
}

td:first-child {
  text-align: left;
}

.table-input {
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-size: 12px;
  text-align: center;
  color: var(--text-main);
}

td:first-child .table-input {
  text-align: left;
}

.table-input:focus {
  outline: none;
  background: #f0f9ff;
  box-shadow: inset 0 0 0 2px var(--border-focus);
}

.table-input:hover {
  background: #f8fafc;
}

/* Date inputs in tables - make wider and easier to use */
.table-input[type="date"] {
  min-width: 130px;
  cursor: pointer;
}

.table-input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  padding: 4px;
  margin-left: 4px;
  opacity: 0.6;
}

.table-input[type="date"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--text-main);
  transition: all 0.15s;
}

.btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

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

.btn-delete {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.btn-delete:hover {
  background: var(--danger-bg);
}

.btn-save {
  background: #059669;
  /* Emerald 600 */
  color: #ffffff;
  border-color: #059669;
}

.btn-save:hover {
  background: #047857;
  /* Emerald 700 */
  border-color: #047857;
}

/* Enhanced card styles for sales costs */
.card {
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-subtle);
}

.sticky-kpi-value {
  font-weight: 600;
  color: var(--text-main);
  font-family: "Outfit", sans-serif;
}



.metric-group-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 12px;
  margin-top: 24px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.metric-group-title:first-child {
  margin-top: 0;
}

/* Returns Section Redesign */
.returns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.returns-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  transition: all 0.2s ease;
}

.returns-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transform: translateY(-2px);
}

.returns-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.returns-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-main);
  font-family: "Outfit", sans-serif;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.returns-hint {
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.4;
}

.returns-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-subtle);
  display: inline-block;
}

.returns-card.highlight {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.returns-card.highlight .returns-value {
  color: var(--primary);
}

/* Distinct colors for each sales cost card */
.card:nth-child(1) {
  background: #f0f9ff;
  border-color: #bae6fd;
}

.card:nth-child(1) .card-title {
  border-bottom-color: #7dd3fc;
}

.card:nth-child(2) {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.card:nth-child(2) .card-title {
  border-bottom-color: #86efac;
}

.card:nth-child(3) {
  background: #faf5ff;
  border-color: #e9d5ff;
}

.card:nth-child(3) .card-title {
  border-bottom-color: #d8b4fe;
}

/* Special Sections */
#returns .section-body {
  background: #f8fafc;
  border-radius: 6px;
  padding: 16px;
  border: 1px solid var(--border-subtle);
}

.metrics-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  font-family: "Outfit", sans-serif;
}

.metric-value-primary {
  font-size: 20px;
  color: var(--primary);
  font-family: "Outfit", sans-serif;
}

.metric-hint {
  font-size: 10px;
  color: #94a3b8;
}

.negative-value {
  color: #dc2626 !important;
}

/* Cashflow Table Specifics */
.cashflow-wrapper {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: auto;
  max-height: 600px;
}

.cashflow-wrapper th,
.cashflow-wrapper td {
  padding: 8px 12px;
  text-align: right;
  min-width: 110px;
}

.cashflow-wrapper th:first-child,
.cashflow-wrapper td:first-child {
  position: sticky;
  left: 0;
  background: #ffffff;
  z-index: 10;
  border-right: 2px solid var(--border-subtle);
  min-width: 250px;
  max-width: 250px;
  white-space: normal;
  text-align: left;
}

.cashflow-wrapper thead th {
  position: sticky;
  z-index: 20;
  background: #f8fafc;
  text-align: center;
}

/* First header row (Month/Year) sticks at top */
.cashflow-wrapper thead tr:first-child th {
  top: 0;
}

/* Second header row (Month Numbers) sticks below first row */
.cashflow-wrapper thead tr:nth-child(2) th {
  top: 36px;
  /* Height of first row */
  border-top: 1px solid var(--border-subtle);
}

.cashflow-wrapper thead th:first-child {
  z-index: 30;
  text-align: center;
}

/* Special styling for month 0 (purchase month) */
.month-zero-header {
  background: #fef3c7 !important;
  font-weight: 600;
}

.row-helper {
  background: #fffbeb;
}

.row-net {
  background: #eff6ff;
  font-weight: 600;
}

.row-separator td {
  background: #f1f5f9;
  color: var(--text-main);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 12px;
  border-top: 2px solid #cbd5e1;
  text-align: left;
}

.row-income {
  background: #f0fdf4;
}

.row-equity-split {
  background: #f5f3ff;
  font-style: italic;
}

.row-marin {
  background-color: #eef2ff !important;
  /* Light Indigo 50 */
}

.row-contingency {
  border-top: 1px solid #cbd5e1;
  background-color: #f8fafc;
  font-style: italic;
}

/* Sticky columns for commercial table */
#commercial .table-wrapper th:first-child,
#commercial .table-wrapper td:first-child {
  position: sticky;
  left: 0;
  background: #ffffff;
  z-index: 10;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
  min-width: 140px;
}

#commercial .table-wrapper thead th:first-child {
  background: #f8fafc;
  z-index: 20;
}

#commercial .table-wrapper th:last-child,
#commercial .table-wrapper td:last-child {
  position: sticky;
  right: 0;
  background: #ffffff;
  z-index: 10;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
  min-width: 50px;
}

#commercial .table-wrapper thead th:last-child {
  background: #f8fafc;
  z-index: 20;
}

/* Wider Net sale £ column (12th column, 2nd to last) */
#commercial .table-wrapper th:nth-child(12),
#commercial .table-wrapper td:nth-child(12) {
  min-width: 140px;
}

/* Commercial Units column widths - optimized by content type */
#commercial .table-wrapper th:nth-child(2),
/* Area sq ft */
#commercial .table-wrapper td:nth-child(2) {
  min-width: 90px;
}

#commercial .table-wrapper th:nth-child(3),
/* Lease start date */
#commercial .table-wrapper td:nth-child(3),
#commercial .table-wrapper th:nth-child(5),
/* Lease expiry */
#commercial .table-wrapper td:nth-child(5),
#commercial .table-wrapper th:nth-child(8),
/* Next review date */
#commercial .table-wrapper td:nth-child(8) {
  min-width: 100px;
}

#commercial .table-wrapper th:nth-child(4),
/* Lease length yrs */
#commercial .table-wrapper td:nth-child(4),
#commercial .table-wrapper th:nth-child(9),
/* Rent free m */
#commercial .table-wrapper td:nth-child(9),
#commercial .table-wrapper th:nth-child(10),
/* Sale month */
#commercial .table-wrapper td:nth-child(10) {
  min-width: 65px;
}

#commercial .table-wrapper th:nth-child(6),
/* Contracted rent pa */
#commercial .table-wrapper td:nth-child(6) {
  min-width: 110px;
}

#commercial .table-wrapper th:nth-child(7),
/* ERV pa */
#commercial .table-wrapper td:nth-child(7) {
  min-width: 120px;
}

#commercial .table-wrapper th:nth-child(11),
/* Exit NIY % */
#commercial .table-wrapper td:nth-child(11) {
  min-width: 70px;
}

/* Residential Units column widths */
#residential .table-wrapper th:nth-child(2),
/* Area sq ft */
#residential .table-wrapper td:nth-child(2) {
  min-width: 90px;
}

#residential .table-wrapper th:nth-child(3),
/* Let before sale */
#residential .table-wrapper td:nth-child(3) {
  min-width: 60px;
}

#residential .table-wrapper th:nth-child(4),
/* Monthly rent */
#residential .table-wrapper td:nth-child(4) {
  min-width: 110px;
}

#residential .table-wrapper th:nth-child(5),
/* Let start m */
#residential .table-wrapper td:nth-child(5),
#residential .table-wrapper th:nth-child(6),
/* Sale m */
#residential .table-wrapper td:nth-child(6) {
  min-width: 65px;
}

#residential .table-wrapper th:nth-child(7),
/* Exit basis */
#residential .table-wrapper td:nth-child(7) {
  min-width: 90px;
}

#residential .table-wrapper th:nth-child(8),
/* £ per sq ft */
#residential .table-wrapper td:nth-child(8) {
  min-width: 80px;
}

#residential .table-wrapper th:nth-child(9),
/* Exit NIY % */
#residential .table-wrapper td:nth-child(9) {
  min-width: 70px;
}

#residential .table-wrapper th:nth-child(10),
/* Sale value £ */
#residential .table-wrapper td:nth-child(10) {
  min-width: 120px;
}

/* Holding Costs column widths */
#holding .table-wrapper th:nth-child(2),
/* Monthly £ */
#holding .table-wrapper td:nth-child(2) {
  min-width: 110px;
}

#holding .table-wrapper th:nth-child(3),
/* Start month */
#holding .table-wrapper td:nth-child(3) {
  min-width: 65px;
}

#holding .table-wrapper th:nth-child(4),
/* Duration mths */
#holding .table-wrapper td:nth-child(4) {
  min-width: 70px;
}

/* Development Costs column widths (applies to all dev cost tables) */
#development .table-wrapper th:nth-child(2),
/* Total £ or Area sq ft */
#development .table-wrapper td:nth-child(2) {
  min-width: 110px;
}

#development .table-wrapper th:nth-child(3),
/* Start month or Rate £ psf */
#development .table-wrapper td:nth-child(3) {
  min-width: 80px;
}

#development .table-wrapper th:nth-child(4),
/* Duration mths or Total £ */
#development .table-wrapper td:nth-child(4) {
  min-width: 90px;
}

#development .table-wrapper th:nth-child(5),
/* Start month (for main construction) */
#development .table-wrapper td:nth-child(5),
#development .table-wrapper th:nth-child(6),
/* End month (for main construction) */
#development .table-wrapper td:nth-child(6) {
  min-width: 65px;
}

/* Miscellaneous Income column widths */
#misc-income .table-wrapper th:nth-child(2),
/* Amount £ */
#misc-income .table-wrapper td:nth-child(2) {
  min-width: 110px;
}

#misc-income .table-wrapper th:nth-child(3),
/* Month */
#misc-income .table-wrapper td:nth-child(3) {
  min-width: 65px;
}

/* Sticky columns for residential table */
#residential .table-wrapper th:first-child,
#residential .table-wrapper td:first-child {
  position: sticky;
  left: 0;
  background: #ffffff;
  z-index: 10;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
  min-width: 120px;
}

#residential .table-wrapper thead th:first-child {
  background: #f8fafc;
  z-index: 20;
}

#residential .table-wrapper th:last-child,
#residential .table-wrapper td:last-child {
  position: sticky;
  right: 0;
  background: #ffffff;
  z-index: 10;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
  min-width: 50px;
}

#residential .table-wrapper thead th:last-child {
  background: #f8fafc;
  z-index: 20;
}

/* Delete button icon styling */
.btn-delete {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  font-size: 18px;
  font-weight: bold;
  padding: 4px 8px;
  min-width: 32px;
}

.btn-delete:hover {
  background: var(--danger-bg);
}

/* Compact input fields for percentages */
#saleResiAgentPct,
#saleCommAgentPct,
#saleResiLegalsPct,
#saleCommLegalsPct {
  max-width: 80px;
}

/* Always visible scrollbars for tables */
.table-wrapper::-webkit-scrollbar {
  -webkit-appearance: none;
  height: 12px;
}

.table-wrapper::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, .3);
  border-radius: 6px;
  border: 2px solid #ffffff;
}

.table-wrapper::-webkit-scrollbar-track {
  background-color: rgba(0, 0, 0, .08);
  border-radius: 6px;
}

.cashflow-wrapper::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
}

.cashflow-wrapper::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, .3);
  border-radius: 6px;
  border: 2px solid #ffffff;
}

.cashflow-wrapper::-webkit-scrollbar-track {
  background-color: rgba(0, 0, 0, .08);
  border-radius: 6px;
}

.dev-subsection-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.field-input-small {
  max-width: 120px;
}

/* Metrics Grid Layout */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.highlight-red-box {
  border: 2px solid #ef4444;
  background-color: #fef2f2;
  border-radius: 8px;
  padding: 16px;
}

/* Chart */
#cashflowChart {
  width: 100%;
  display: none;
  /* Hidden by default, shown by JS if data exists */
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .app-header {
    padding: 12px;
  }

  main.page {
    padding: 12px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}

.text-negative {
  color: #ef4444 !important;
}

.row-over-budget td:first-child {
  background-color: #fee2e2 !important;
  color: #991b1b !important;
  font-weight: 600;
  border-left: 4px solid #ef4444;
}

.row-over-budget td:first-child::after {
  content: " ⚠️";
  font-size: 12px;
  margin-left: 6px;
}

.input-mismatch {
  color: #c2410c !important;
  /* Dark Orange/Red */
  font-weight: bold;
}

.input-mismatch::after {
  content: " (Mismatch)";
  font-size: 0.8em;
  color: #ea580c;
}

/* Over budget warning - actuals exceed budget in Live Mode */
.input-over-budget {
  background-color: #fee2e2 !important;
  color: #991b1b !important;
  font-weight: bold;
  border: 2px solid #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.input-over-budget::placeholder {
  color: #991b1b;
}

/* Design Demo Overrides */
.page-inner {
  gap: 48px;
}

section.app-section {
  border: 1px solid #cbd5e1;
  border-top: 5px solid var(--primary);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
}

.section-header {
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.section-kicker {
  font-size: 12px;
  background: #eff6ff;
  color: var(--primary);
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 8px;
}

#acquisition {
  border-top-color: #059669;
}

#acquisition .section-kicker {
  color: #059669;
  background: #ecfdf5;
}

#commercial {
  border-top-color: #7c3aed;
}

#commercial .section-kicker {
  color: #7c3aed;
  background: #f5f3ff;
}

#holding {
  border-top-color: #ea580c;
}

#holding .section-kicker {
  color: #ea580c;
  background: #fff7ed;
}