/* Camino Equalizer - Main Styles */

/* CSS Variables */
:root {
  --color-bg: #f3f4f6;
  --color-card: white;
  --color-text: #1f2937;
  --color-text-light: #6b7280;
  --color-border: #e5e7eb;
  --color-primary: #3b82f6;
  --color-danger: #dc2626;
  --color-success: #15803d;
  --color-negative: #dc2626;

  --color-assets: #dbeafe;
  --color-adjustments: #f5f3ff;
  --color-offsets: #ede9fe;
  --color-equalization: #dcfce7;

  --radius: 0.5rem;
  --radius-lg: 1rem;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

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

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Card */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

/* Section Colors */
.section-assets {
  background: var(--color-assets);
}
.section-debts {
  background: #fee2e2; /* Light red for debts */
}
.section-adjustments {
  background: var(--color-adjustments);
}
.section-offsets {
  background: var(--color-offsets);
}

/* Typography */
h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.125rem;
  font-weight: 600;
}

h3 {
  margin: 0 0 1rem 0;
  font-size: 1rem;
  font-weight: 600;
}

/* Header */
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.header-buttons {
  display: flex;
  gap: 0.5rem;
}

.header-content {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.header-parties {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.party-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.party-row label {
  width: 4rem;
  font-size: 0.875rem;
}

/* Case type and name - side by side layout */
.case-type-and-name {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.case-type-radios {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.case-name-input {
  flex: 1;
  max-width: 250px;
}

.report-purpose-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.report-purpose-select {
  width: auto;
  min-width: 10rem;
}

.report-notes-input {
  flex: 1;
}

.report-purpose-print {
  display: none;
}

/* Legacy support */
.case-type-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.family-name-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Case field rows - group fields side by side */
.case-field-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.family-name-field label {
  font-size: 0.875rem;
  white-space: nowrap;
}

.family-name-field .input {
  width: auto;
  min-width: 12rem;
}

.header-case-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.case-field {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
}

.case-field label {
  white-space: nowrap;
  color: var(--color-text-light);
}

.case-field .input {
  width: auto;
  max-width: 8rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

/* Inputs */
.input {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem;
  font-size: 0.875rem;
  font-family: inherit;
}

.input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

textarea.input {
  resize: vertical;
  min-height: 3rem;
}

select.input {
  cursor: pointer;
}

.pct-input {
  width: 4rem;
  text-align: right;
}

/* Buttons */
.btn {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  background: var(--color-card);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: background 0.15s;
}

.btn:hover {
  background: #f9fafb;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 0.2rem 0.4rem;
  font-size: 1rem;
  line-height: 1;
  min-width: auto;
  background: transparent;
  border: 1px solid var(--color-border);
}

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

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

.btn-primary:hover {
  background: #2563eb;
}

.btn-danger {
  color: var(--color-danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--color-border);
}

thead th {
  background: inherit;
}

th, td {
  padding: 0.5rem;
  text-align: left;
}

th {
  font-weight: 600;
  white-space: nowrap;
}

tr.data-row {
  border-bottom: 1px solid var(--color-border);
}

tr.category-row {
  background: rgba(0,0,0,0.05);
}

tr.category-row td {
  font-weight: 600;
  padding-top: 0.75rem;
}

td.category-label {
  text-decoration: underline;
}

tr.subtotal-row {
  background: rgba(0,0,0,0.03);
  border-top: 2px solid var(--color-border);
}

/* Vertical line separating totals from item details - applies to ALL rows */
th.col-party-a,
td.cell-party-a {
  border-left: 3px solid #9ca3af;
}

/* Minimum widths for party columns - JS syncPartyColumnWidths() will set final width */
th.col-party-a,
th.col-party-b,
td.cell-party-a,
td.cell-party-b {
  min-width: 0;
}

/* Narrower actions column */
.col-actions,
.cell-actions {
  width: 2.5rem;
  padding: 0.25rem !important;
}

/* Spacer columns for debt table alignment with asset table */
.spacer-col {
  min-width: 4rem;
  width: 4rem;
}

/* Minimum widths for adjustment/offset columns - JS will sync dynamically */
.col-adj-party,
.cell-adj-party {
  min-width: 0;
}

.col-adj-amount,
.cell-adj-amount {
  min-width: 0;
}

.line-num {
  width: 2rem;
  color: var(--color-text-light);
  font-family: monospace;
  vertical-align: top;
}

/* Reorder arrows in line-num cell */
.reorder-arrows {
  display: block;
  line-height: 1;
}

.btn-reorder {
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font-size: 0.55rem;
  line-height: 1;
  color: var(--color-text-light);
  opacity: 0.5;
}

.btn-reorder:hover {
  opacity: 1;
  color: var(--color-primary);
}

/* Mobile edit button in line-num cell */
.mobile-edit-btn {
  display: none;
}

.helper-info {
  margin-top: 0.25rem;
}

/* Helper rows - full-width rows below data rows */
tr.helper-row {
  background: rgba(0,0,0,0.02);
}

tr.helper-row td {
  padding: 0.25rem 0.5rem;
  border-bottom: none;
}

.helper-content {
  padding-left: 0.5rem;
  border-left: 2px solid var(--color-border);
  font-size: 0.75rem !important; /* Smaller than main data rows */
  color: var(--color-text-light); /* Grey text for all helper rows */
}

/* Section Header - sticky within card while scrolling */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
  background: inherit;
  padding: 0.5rem 0;
}

/* Totals Section */
.totals-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  align-items: start;
}

.totals-table {
  width: auto;
}

.totals-table th,
.totals-table td {
  padding: 0.5rem 1rem;
}

.totals-row-assets {
  background: var(--color-assets);
}

.totals-row-debts {
  background: #fee2e2; /* Light red for debts */
  border-bottom: 1px solid #333;
}

.totals-row-assets-debts {
  background: #f3f4f6; /* Light gray for subtotal */
  border-top: 1px solid var(--color-border);
}

.totals-row-adjustments {
  background: var(--color-adjustments);
}

.totals-row-offsets {
  background: var(--color-offsets);
  border-bottom: 1px solid #333;
}

.totals-row-total {
  background: var(--color-equalization);
  border-bottom: 3px double #333;
}

.equalization-box {
  padding: 1rem;
  background: var(--color-equalization);
  border-radius: var(--radius);
  border: 3px solid #1f2937; /* Thick dark border */
  text-align: center;
}

.eq-grand {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.eq-target {
  font-size: 0.875rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.eq-result {
  font-size: 1.125rem;
}

.eq-amount {
  font-weight: 600;
}

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

.modal-content {
  background: var(--color-card);
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.modal-content-wide {
  max-width: 600px;
}

/* Settings sections */
.settings-section {
  margin-bottom: 0.5rem;
}

.settings-section h4 {
  margin: 0 0 0.75rem 0;
  font-size: 0.95rem;
  color: var(--color-text);
}

.settings-section-secondary {
  opacity: 0.7;
}

.settings-section-secondary:hover {
  opacity: 1;
}

/* Sub-options (indented) */
.sub-option {
  margin-left: 1.5rem;
  margin-top: 0.25rem;
}

/* Secondary/greyed input */
.input-secondary {
  opacity: 0.8;
}

.modal-body {
  margin-bottom: 1rem;
}

.form-field {
  margin-bottom: 0.75rem;
}

.form-field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-field .input {
  width: 100%;
}

.allocation-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  margin-right: 1rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  margin-bottom: 0.25rem;
}

.allocation-type-radios {
  display: flex;
  flex-direction: column;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

/* Category Selection Modal */
#category-modal-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.category-btn {
  text-align: left;
  width: 100%;
  justify-content: flex-start;
}

/* Utility Classes */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-gray { color: var(--color-text-light); }
.text-italic { font-style: italic; }
.text-negative { color: var(--color-negative); }
.text-warning { color: #b45309; } /* Amber/orange warning color */
.text-nowrap { white-space: nowrap; }

/* Floating Print Button */
.floating-print-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
  transition: transform 0.2s, box-shadow 0.2s;
}

.floating-print-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.floating-print-btn:active {
  transform: scale(0.95);
}
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: monospace; }
.hidden { display: none !important; }

.helper-text {
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* Validation error display */
.validation-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid var(--color-danger);
  color: var(--color-danger);
  padding: 0.75rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.validation-error ul {
  margin: 0.5rem 0 0 1rem;
  padding: 0;
}

.validation-error li {
  margin-bottom: 0.25rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  color: var(--color-text-light);
  font-size: 0.75rem;
}

/* Mobile responsive helpers - hidden on desktop, shown on mobile */
.show-mobile-only {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }

  .card {
    padding: 1rem;
  }

  .header-top {
    flex-direction: column;
    align-items: stretch;
  }

  .header-buttons {
    justify-content: center;
  }

  .header-content {
    flex-direction: column;
  }

  .header-case-info {
    flex-direction: column;
    align-items: stretch;
  }

  /* Keep case fields horizontal with label next to input */
  .case-field {
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
  }

  .case-field .input {
    flex: 1;
    max-width: none;
  }

  .totals-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .section-header .btn {
    width: 100%;
  }

  /* Hide desktop-only columns on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Show mobile-only columns */
  .show-mobile-only {
    display: table-cell !important;
  }

  /* Mobile stacked cell styling */
  .mobile-stacked {
    font-size: 0.75rem;
    line-height: 1.4;
    vertical-align: top;
    padding: 0.4rem !important;
  }

  .mobile-label {
    color: var(--color-text-light);
    font-size: 0.65rem;
  }

  .mobile-underline {
    text-decoration: underline;
  }

  /* Case type radios stack on mobile */
  .case-type-row {
    flex-direction: column;
    gap: 0.25rem;
  }

  /* Case type and name stack on mobile */
  .case-type-and-name {
    flex-direction: column;
    gap: 0.5rem;
  }

  .case-name-input {
    max-width: 100%;
  }

  .report-purpose-row {
    flex-direction: column;
  }

  .report-purpose-select {
    min-width: 100%;
  }

  /* Case field rows stay horizontal on mobile but with tighter spacing */
  .case-field-row {
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  /* Duration field wraps below DOM/DOS on mobile */
  .duration-field {
    flex: 1 0 100%;
    margin-top: 0.25rem;
  }

  .case-field .input {
    max-width: 6rem;
  }

  /* Date inputs need more width for mm/dd/yyyy + calendar button on mobile */
  .case-field .input[type="date"] {
    min-width: 8.5rem;
    max-width: 9rem;
  }

  /* Narrower # column on mobile */
  .line-num {
    width: auto;
    min-width: 1rem;
    max-width: 2.5rem;
    padding: 0.2rem !important;
    font-size: 0.65rem;
  }

  /* Smaller description text on mobile */
  .cell-description {
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem !important;
  }

  .cell-description .helper-info {
    font-size: 0.65rem;
  }

  /* Show edit button in # cell on mobile */
  .mobile-edit-btn {
    display: block;
    margin-top: 0.25rem;
    padding: 0.15rem 0.3rem;
    font-size: 0.6rem;
    white-space: nowrap;
  }

  /* Smaller party columns on mobile */
  .cell-party-a,
  .cell-party-b {
    font-size: 0.7rem;
    padding: 0.25rem !important;
  }
}

/* No Print */
@media print {
  .no-print {
    display: none !important;
  }
}
