:root {
  --bg: #0b1320;
  --card: #111a2d;
  --text: #e6eefc;
  --muted: #9fb2d8;
  --accent: #4f8cff;
  --emph: #00d68f;
  --negative: #ff4757;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }

.container { max-width: 1400px; margin: 16px auto; padding: 0 12px; }
h1 { font-size: 28px; margin: 0 0 20px; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
fieldset { border: 1px solid #20304d; background: var(--card); padding: 16px; border-radius: 10px; }
legend { padding: 0 8px; color: var(--muted); }
label { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 8px; }
label span { color: var(--muted); font-size: 12px; }
input, select { background: #0e1730; color: var(--text); border: 1px solid #2b3d63; border-radius: 8px; padding: 10px 12px; }

.actions { margin-top: 12px; }
button, .button { background: var(--accent); color: white; border: none; padding: 10px 16px; border-radius: 8px; text-decoration: none; display: inline-block; }
button:hover, .button:hover { filter: brightness(1.05); }

.results table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
.results th, .results td { padding: 10px 12px; border-bottom: 1px solid #1f2a46; }
.results th { text-align: left; color: var(--muted); width: 45%; }
.results td.emph { color: var(--emph); font-weight: 600; }


/* Excel-like single-sheet layout */
.sheet-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid #20304d; border-radius: 10px; overflow: hidden; }
.sheet-table thead th { background: #15223d; color: var(--muted); padding: 12px; border-bottom: 1px solid #1f2a46; text-align: left; }
.sheet-table td, .sheet-table th { padding: 5px 6px; border-bottom: 1px solid #1f2a46; border-right: 1px solid #1f2a46; }
.sheet-table tr:last-child td { border-bottom: 0; }
.sheet-table td:last-child, .sheet-table th:last-child { border-right: 0; }
.sheet-table td.spacer, .sheet-table th.spacer { width: 24px; background: #101b33; border-right: 0; border-left: 0; }
.sheet-table input, .sheet-table select { width: 100%; }
.sheet-table td[data-field] { text-align: right; white-space: nowrap; }
.sheet-table td.emph, .sheet-table th.emph { color: var(--emph); font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }



/* Pair grid density & labels */
/* Deal table to mirror provided image */
.deal-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; border: 1px solid #20304d; }
.deal-table .head-row th { background: #0f1a31; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.deal-table td, .deal-table th { padding: 6px 8px; border-bottom: 1px solid #1f2a46; border-right: 1px solid #1f2a46; }
.deal-table tr:last-child td { border-bottom: 0; }
.deal-table td:last-child, .deal-table th:last-child { border-right: 0; }
.deal-table .divider { width: 10px; background: #101b33; border-right: 0; }
.deal-table .section-row td { background: #122041; color: var(--muted); font-weight: 600; border-top: 1px solid #20304d; }
.deal-table .money input, .deal-table .pct input { width: 100%; padding: 5px 6px; border-radius: 6px; }
.deal-table .pct-only input { width: 100%; }
.deal-table .value { text-align: right; white-space: nowrap; }
.deal-table .highlight-row td { background: #182a56; }
.deal-table .summary-row td { background: #0f1a31; font-weight: 600; }
.deal-table .emph { color: var(--emph); font-weight: 700; }

/* KPI bar */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.kpi { background: var(--card); border: 1px solid #20304d; border-radius: 10px; padding: 10px 12px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi strong { display: block; font-size: 18px; color: var(--text); }
.kpi strong[data-field="net_profit"], .kpi strong[data-field="cash_on_cash_return"], .kpi strong[data-field="total_cash_needed"] { color: var(--emph); }

/* Negative values styling */
.negative { color: var(--negative) !important; }
.kpi .negative { color: var(--negative) !important; }

/* Tooltip styling */
.tooltip {
  position: relative;
  display: inline-block;
  color: var(--accent);
  cursor: help;
  font-weight: bold;
  margin-left: 4px;
  font-size: 12px;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 280px;
  background-color: var(--card);
  color: var(--text);
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  position: fixed;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
  border: 1px solid #20304d;
  font-size: 12px;
  font-weight: normal;
  line-height: 1.4;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
  max-width: 90vw;
}

/* Removed arrow for better dynamic positioning */

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

/* Fit in one page: compact typography */
html, body { font-size: 13.5px; }
h1 { font-size: 20px; margin-bottom: 10px; }

/* Small screens or limited height -> further compact */
@media (max-height: 850px) {
  html, body { font-size: 12.5px; }
  .sheet-table td, .sheet-table th { padding: 4px 5px; }
  .kpi { padding: 8px 10px; }
  .kpi strong { font-size: 16px; }
}

/* Mobile phone optimizations */
@media (max-width: 768px) {
  .container { 
    max-width: 100%; 
    margin: 8px auto; 
    padding: 0 8px; 
  }
  
  h1 { 
    font-size: 18px; 
    margin-bottom: 8px; 
    text-align: center;
  }
  
  /* Stack KPIs vertically on mobile */
  .kpis { 
    grid-template-columns: repeat(2, 1fr); 
    gap: 6px; 
    margin-bottom: 8px; 
  }
  
  .kpi { 
    padding: 6px 8px; 
  }
  
  .kpi span { 
    font-size: 10px; 
  }
  
  .kpi strong { 
    font-size: 14px; 
  }
  
  /* Mobile table styling */
  .deal-table { 
    font-size: 11px; 
    table-layout: auto;
    min-width: 100%;
  }
  
  /* Make table scrollable horizontally on mobile if needed */
  .sheet { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
  }
  
  /* Ensure input columns have minimum width */
  .deal-table .money, .deal-table .pct { 
    min-width: 90px; 
  }
  
  .deal-table .value { 
    min-width: 100px; 
  }
  
  .deal-table td, .deal-table th { 
    padding: 6px 4px; 
    vertical-align: middle;
  }
  
  .deal-table input, .deal-table select { 
    padding: 8px 6px; 
    font-size: 14px; 
    min-width: 80px;
    height: 36px;
    box-sizing: border-box;
    border-radius: 6px;
    -webkit-appearance: none;
  }
  
  .deal-table .head-row th { 
    font-size: 10px; 
    padding: 6px 4px; 
  }
  
  .deal-table .section-row td { 
    font-size: 10px; 
    font-weight: 600; 
  }
  
  /* Adjust divider width for mobile */
  .deal-table .divider { 
    width: 6px; 
  }
  
  /* Mobile tooltip adjustments */
  .tooltip { 
    font-size: 10px; 
  }
  
  .tooltip .tooltiptext { 
    width: 250px; 
    font-size: 10px; 
    padding: 6px 8px; 
    max-width: 85vw; 
  }
  
  .hint { 
    font-size: 10px; 
    margin-top: 6px; 
    text-align: center; 
  }
}

/* Very small phones */
@media (max-width: 480px) {
  .container { 
    padding: 0 4px; 
  }
  
  /* Single column KPIs for very small screens */
  .kpis { 
    grid-template-columns: 1fr; 
    gap: 4px; 
  }
  
  .deal-table { 
    font-size: 10px; 
  }
  
  .deal-table td, .deal-table th { 
    padding: 8px 4px; 
    vertical-align: middle;
  }
  
  .deal-table input, .deal-table select { 
    padding: 10px 8px; 
    font-size: 16px; 
    min-width: 90px;
    height: 44px;
    box-sizing: border-box;
    border-radius: 8px;
    -webkit-appearance: none;
  }
  
  .tooltip .tooltiptext { 
    width: 200px; 
    font-size: 9px; 
    max-width: 90vw; 
  }
  
  .kpi strong { 
    font-size: 12px; 
  }
}

/* Header section with actions */
.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Button styles */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  text-align: center;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-danger {
  background: var(--negative);
  color: white;
}

.btn-danger:hover {
  filter: brightness(1.1);
}

.btn-success {
  background: var(--emph);
  color: white;
}

.btn-success:hover {
  filter: brightness(1.1);
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--card);
  border-radius: 10px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid #20304d;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 0 20px;
  border-bottom: 1px solid #20304d;
  margin-bottom: 20px;
}

.modal-header h3 {
  margin: 0;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 0 20px 20px 20px;
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid #20304d;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Form styles */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: #0e1730;
  color: var(--text);
  border: 1px solid #2b3d63;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

/* Error styling */
.error {
  background: rgba(255, 71, 87, 0.1);
  color: var(--negative);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 71, 87, 0.3);
  font-size: 13px;
}

/* Message styling */
.message {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 500;
}

.message-success {
  background: rgba(0, 214, 143, 0.1);
  color: var(--emph);
  border: 1px solid rgba(0, 214, 143, 0.3);
}

.message-error {
  background: rgba(255, 71, 87, 0.1);
  color: var(--negative);
  border: 1px solid rgba(255, 71, 87, 0.3);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .header-section {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  
  .header-actions {
    justify-content: center;
  }
  
  .modal-content {
    width: 95%;
    margin: 20px auto;
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 15px;
    padding-right: 15px;
  }
}

/* Authentication styling */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.user-info strong {
  color: var(--text);
}

.logout-link {
  color: var(--accent) !important;
  text-decoration: none;
}

.logout-link:hover {
  text-decoration: underline;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .user-info {
    order: -1;
    width: 100%;
    justify-content: center;
    padding-bottom: 10px;
    border-bottom: 1px solid #20304d;
    margin-bottom: 10px;
  }
}

