/* Velocity Banking Calculator - Compact Two-Column Layout */

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --success-color: #059669;
  --success-light: #d1fae5;
  --warning-color: #d97706;
  --warning-light: #fef3c7;
  --error-color: #dc2626;
  --error-light: #fee2e2;
  --text-color: #1f2937;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --bg-color: #f3f4f6;
  --card-bg: #ffffff;
  --radius: 6px;
  --radius-lg: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  color: var(--text-color);
  background: var(--bg-color);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 16px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 4px 0;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0;
}

/* Main Two-Column Layout */
.main-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}

/* Left Panel - Inputs */
.input-panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: sticky;
  top: 16px;
  width: 100%;
  overflow: hidden;
}

/* Desktop only - constrain width */
@media (min-width: 801px) {
  .input-panel {
    max-width: 320px;
  }
}

#calculator-form {
  width: 100%;
  max-width: 100%;
}

.input-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  width: 100%;
  max-width: 100%;
}

.input-section:last-of-type {
  margin-bottom: 16px;
  padding-bottom: 0;
  border-bottom: none;
}

.input-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 0 0 10px 0;
}

/* Compact Input Grid */
.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 100%;
}

.compact-grid.single {
  grid-template-columns: 1fr;
}

.input-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-color);
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  height: 36px;
  width: 100%;
  max-width: 100%;
}

.input-wrapper:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.input-wrapper .prefix,
.input-wrapper .suffix {
  padding: 0 8px;
  background: #e5e7eb;
  color: var(--text-muted);
  font-size: 0.75rem;
  height: 100%;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  flex: 1;
  border: none;
  padding: 0 8px;
  font-size: 0.875rem;
  background: transparent;
  color: var(--text-color);
  min-width: 0;
  height: 100%;
}

.input-wrapper input:focus {
  outline: none;
}

.input-wrapper input[readonly] {
  background: #f9fafb;
  color: var(--text-muted);
}

.input-group.computed .input-wrapper {
  background: #f9fafb;
}

.input-group.highlight .input-wrapper {
  border-color: var(--success-color);
  background: var(--success-light);
}

.input-group.highlight input {
  font-weight: 600;
  color: var(--success-color);
}

.input-group.error .input-wrapper {
  border-color: var(--error-color);
  background: var(--error-light);
}

.help-text {
  font-size: 0.675rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Info Icon */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  font-size: 11px;
  color: var(--primary-color);
  cursor: pointer;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.1);
  transition: all 0.2s;
  user-select: none;
}

.info-icon:hover {
  background: rgba(37, 99, 235, 0.2);
  transform: scale(1.1);
}

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

.modal-overlay.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Modal Content */
.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.2s;
  position: relative;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-color);
}

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

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

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

.modal-body {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-color);
}

.modal-body h4 {
  font-size: 1rem;
  margin: 16px 0 8px 0;
  color: var(--primary-color);
}

.modal-body p {
  margin: 0 0 12px 0;
}

.modal-body strong {
  color: var(--text-color);
}

.modal-body .example-box {
  background: var(--bg-color);
  border-left: 3px solid var(--primary-color);
  padding: 12px;
  margin: 12px 0;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

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

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

.btn-full {
  width: 100%;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--bg-color);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

/* Right Panel - Results */
.results-panel {
  min-height: 400px;
  min-width: 0;
  overflow: visible;
}

/* Placeholder */
.results-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  color: var(--text-muted);
  text-align: center;
}

.results-placeholder.hidden {
  display: none;
}

.placeholder-icon {
  margin-bottom: 12px;
  opacity: 0.4;
}

.results-placeholder p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

/* Validation Messages */
.validation-messages {
  margin-bottom: 16px;
}

.validation-messages.hidden {
  display: none;
}

.validation-messages:empty {
  margin-bottom: 0;
}

.validation-error,
.validation-warning {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.validation-error {
  background: var(--error-light);
  border: 1px solid #fca5a5;
  color: var(--error-color);
}

.validation-warning {
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  color: var(--warning-color);
}

/* Results Section */
.results-section {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-top: 0;
  width: 100%;
  overflow: visible;
}

.results-section.hidden {
  display: none;
}

.results-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  width: 100%;
}

.results-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  padding: 0;
}

/* Summary Cards */
.results-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.result-card {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border: 2px solid var(--success-color);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.result-card.negative {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  border-color: var(--error-color);
}

.result-card.negative .result-label {
  color: #991b1b;
}

.result-card.negative .result-value {
  color: #7f1d1d;
}

.result-card.negative .result-detail {
  color: var(--error-color);
}

.result-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #047857;
  margin-bottom: 4px;
}

.result-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #065f46;
  line-height: 1.2;
}

.result-detail {
  display: block;
  font-size: 0.75rem;
  color: #059669;
  margin-top: 2px;
}

/* Comparison Table */
.comparison-table-wrapper {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: visible;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.comparison-table th,
.comparison-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  text-align: left;
}

.comparison-table th {
  background: var(--bg-color);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.comparison-table tbody tr:last-child td {
  border-bottom: none;
}

.comparison-table .positive {
  color: var(--success-color);
  font-weight: 600;
}

.comparison-table .negative {
  color: var(--error-color);
  font-weight: 600;
}

/* Three-column comparison table */
.comparison-table-full .strategy-col {
  text-align: center;
}

.comparison-table-full .strategy-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-color);
  margin-bottom: 2px;
}

.comparison-table-full .strategy-desc {
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
  text-transform: none;
}

/* Best strategy column highlighting (dynamically applied to winner) */
.comparison-table-full .best-strategy {
  background: #f0f9ff;
}

.comparison-table-full tbody .best-strategy {
  font-weight: 600;
  color: var(--primary-color);
}

.comparison-table-full .summary-row {
  border-top: 2px solid var(--border-color);
  font-size: 0.75rem;
}

.comparison-table-full .summary-row td {
  padding-top: 12px;
}

/* Emphasize Extra Payments column as baseline */
.comparison-table th:nth-child(2),
.comparison-table td:nth-child(2) {
  background: #f0f9ff;
  font-weight: 600;
}

.comparison-table th:nth-child(2) {
  color: var(--primary-color);
}

/* Velocity Details */
.velocity-details {
  background: var(--bg-color);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.8rem;
}

.detail-row:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.detail-row .detail-label {
  color: var(--text-muted);
}

.detail-row .detail-value {
  font-weight: 600;
}

/* Chunk Timeline */
.chunk-timeline {
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

.chunk-timeline summary {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-color);
}

.chunk-timeline summary:hover {
  background: #e5e7eb;
}

.chunk-timeline[open] summary {
  border-bottom: 1px solid var(--border-color);
}

.timeline-content {
  max-height: 300px;
  overflow-y: auto;
}

.timeline-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.timeline-table th,
.timeline-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.timeline-table th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}

.timeline-table th:first-child,
.timeline-table td:first-child {
  text-align: center;
  width: 40px;
}

.timeline-table tbody tr:last-child td {
  border-bottom: none;
}

/* Footer */
footer {
  margin-top: 24px;
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

footer p {
  margin: 0 0 8px 0;
}

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

/* Print Input Summary - hidden on screen */
.print-input-summary {
  display: none;
}

/* Responsive - Stack on smaller screens */
@media (max-width: 800px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

  .results-placeholder {
    min-height: 200px;
  }

  .modal-content {
    width: 95%;
    padding: 20px;
    max-height: 90vh;
  }

  .modal-header h3 {
    font-size: 1rem;
  }

  .modal-body {
    font-size: 0.8rem;
  }

  /* Make comparison table horizontally scrollable on mobile */
  .comparison-table-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .comparison-table {
    min-width: 600px;
    width: auto;
  }

  .comparison-table.comparison-table-full {
    min-width: 750px;
    width: auto;
  }

  /* Show scroll hint on mobile */
  .mobile-scroll-hint {
    display: block !important;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 4px;
    background: var(--warning-light);
    border-radius: 4px;
  }

  /* Ensure results section doesn't constrain width */
  .results-section {
    width: 100%;
    padding: 12px;
    overflow-x: visible;
  }
}

@media (max-width: 500px) {
  .compact-grid {
    grid-template-columns: 1fr;
  }

  .results-summary {
    grid-template-columns: 1fr;
  }

  .result-value {
    font-size: 1.25rem;
  }

  .input-panel {
    padding: 12px;
  }

  .results-section {
    padding: 8px;
  }

  /* Ensure table is scrollable on small mobile devices */
  .comparison-table {
    min-width: 650px;
    font-size: 0.75rem;
  }

  .comparison-table.comparison-table-full {
    min-width: 750px;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 6px 8px;
    font-size: 0.7rem;
  }

  .comparison-table-full .strategy-name {
    font-size: 0.75rem;
  }

  .comparison-table-full .strategy-desc {
    font-size: 0.65rem;
  }
}

/* Print Styles */
/* Print-only header (hidden on screen, visible in print) */
.print-only-header {
  display: none !important;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: white;
    font-size: 10pt;
  }

  .print-only-header {
    display: block !important;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  .main-layout {
    display: block;
  }

  .input-panel,
  .results-placeholder,
  .validation-messages,
  footer,
  .btn-icon,
  .modal-overlay {
    display: none !important;
  }

  .results-panel {
    min-height: auto;
  }

  .results-section {
    box-shadow: none;
    padding: 0;
  }

  .print-input-summary {
    display: block !important;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
  }

  .print-input-summary h3 {
    font-size: 11pt;
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
  }

  .print-params {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .print-param-group h4 {
    font-size: 9pt;
    margin: 0 0 6px 0;
    color: #495057;
  }

  .print-param-group p {
    margin: 0 0 3px 0;
    font-size: 8pt;
  }

  .result-card {
    border: 1px solid #059669;
    padding: 12px;
  }

  .comparison-table-wrapper,
  .velocity-details,
  .chunk-timeline {
    page-break-inside: avoid;
  }

  /* Comparison table - more compact for print */
  .comparison-table {
    font-size: 8pt;
    width: 100%;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 4px 6px;
  }

  .comparison-table-full th {
    font-size: 7pt;
  }

  .comparison-table-full .strategy-name {
    font-size: 9pt;
    margin-bottom: 2px;
  }

  .comparison-table-full .strategy-desc {
    font-size: 6.5pt;
  }

  /* Chunk timeline table */
  .chunk-timeline table {
    font-size: 7pt;
  }

  .chunk-timeline th,
  .chunk-timeline td {
    padding: 3px 4px;
  }

  /* Best strategy indicator */
  .best-strategy-indicator {
    font-size: 8pt;
    padding: 6px 10px;
    margin: 8px 0;
  }

  /* Velocity details */
  .velocity-details {
    font-size: 8pt;
  }

  .velocity-details h3 {
    font-size: 10pt;
  }

  /* Help text and notes - smaller */
  .help-text {
    font-size: 7pt;
    padding: 6px 8px;
    margin-bottom: 10px;
  }

  /* Section headings */
  h2 {
    font-size: 12pt;
    margin: 12px 0 8px 0;
  }

  h3 {
    font-size: 10pt;
    margin: 10px 0 6px 0;
  }

  /* Results header */
  .results-header {
    margin-bottom: 8px;
  }

  .results-header h2 {
    margin-bottom: 4px;
  }

  @page {
    margin: 0.4in 0.5in;
    size: letter landscape;
  }

  /* Ensure landscape mode is used */
  @page :first {
    size: letter landscape;
  }

  /* Force landscape orientation hint */
  body {
    width: 100%;
    height: 100%;
  }

  /* Additional print-specific adjustments */
  .result-card {
    page-break-inside: avoid;
  }

  .comparison-table-wrapper {
    overflow: visible;
  }

  table {
    table-layout: auto;
    width: 100%;
  }
}

/* Diagram Button */
.btn-diagram {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  margin-top: 12px;
  font-size: 0.875rem;
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.btn-diagram:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-diagram:active {
  transform: translateY(0);
}

/* Large Modal for Diagram */
.modal-large {
  max-width: 1200px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
}

/* Diagram SVG Styles */
.diagram-step-box {
  fill: white;
  stroke: #2563eb;
  stroke-width: 2;
}

.diagram-step-box-important {
  fill: #dbeafe;
  stroke: #2563eb;
  stroke-width: 3;
}

.diagram-step-box-warning {
  fill: #fef3c7;
  stroke: #f59e0b;
  stroke-width: 2;
}

.diagram-step-text {
  fill: #1e293b;
  font-size: 14px;
  font-weight: 600;
}

.diagram-step-detail {
  fill: #64748b;
  font-size: 12px;
}

.diagram-arrow {
  stroke: #2563eb;
  stroke-width: 2;
  fill: none;
  marker-end: url(#arrowhead);
}

.diagram-arrow-dashed {
  stroke: #94a3b8;
  stroke-width: 2;
  fill: none;
  stroke-dasharray: 5,5;
  marker-end: url(#arrowhead-gray);
}

.diagram-label {
  fill: #475569;
  font-size: 11px;
  font-style: italic;
}

.diagram-amount {
  fill: #16a34a;
  font-weight: 700;
  font-size: 14px;
}

.diagram-amount-negative {
  fill: #dc2626;
  font-weight: 700;
  font-size: 14px;
}

.diagram-cycle-label {
  fill: #2563eb;
  font-size: 16px;
  font-weight: 700;
}

/* Diagram Legend */
.diagram-legend {
  margin-top: 24px;
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
}

.diagram-legend h4 {
  margin-top: 0;
  margin-bottom: 12px;
  color: #1e293b;
  font-size: 0.95rem;
}

.diagram-legend-item {
  display: flex;
  align-items: center;
  margin: 8px 0;
  gap: 10px;
  font-size: 0.85rem;
}

.diagram-legend-box {
  width: 40px;
  height: 24px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Diagram Notes */
.diagram-notes {
  margin-top: 16px;
  padding: 16px;
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  border-radius: 4px;
}

.diagram-notes h4 {
  margin-top: 0;
  margin-bottom: 8px;
  color: #92400e;
  font-size: 0.95rem;
}

.diagram-notes ul {
  margin-bottom: 0;
  padding-left: 20px;
}

.diagram-notes li {
  color: #78350f;
  margin: 5px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
