/* ============================================================
   Contractor Calculator — Theme & Component Styles
   ============================================================ */

/* --- Theme Custom Properties --- */

:root {
  --bg: #ffffff;
  --bg-secondary: #f9fafb;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --negative: #dc2626;
  --negative-light: #fef2f2;
  --net-highlight: #059669;
  --net-bg: #ecfdf5;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --input-bg: #ffffff;
  --modal-backdrop: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #60a5fa;
  --accent-light: #1e3a5f;
  --negative: #f87171;
  --negative-light: #450a0a;
  --net-highlight: #34d399;
  --net-bg: #064e3b;
  --warning-bg: #451a03;
  --warning-text: #fbbf24;
  --input-bg: #1e293b;
  --modal-backdrop: rgba(0, 0, 0, 0.7);
}

/* --- Base Reset & Body --- */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* --- Layout --- */

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.main-grid {
  display: grid;
  grid-template-columns: 35% 65%;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 768px) {
  .main-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

/* --- Header --- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

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

.btn-settings {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn-settings:hover {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--text-muted);
}

/* --- Input Panel --- */

.input-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.input-panel h2 {
  margin: 0 0 1.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input[type="number"],
.form-group input[type="text"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-suffix {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-suffix input {
  flex: 1;
}

.input-suffix .suffix-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* --- Day Rate (prominent input) --- */

.input-with-prefix {
  display: flex;
  align-items: center;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  background: var(--input-bg);
  overflow: hidden;
  transition: border-color 0.15s;
}

.input-with-prefix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-with-prefix .prefix {
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 1.25rem;
  user-select: none;
}

[data-theme="dark"] .input-with-prefix .prefix {
  background: var(--bg);
}

.input-with-prefix input {
  flex: 1;
  border: none;
  padding: 0.5rem 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.input-with-prefix input:focus {
  outline: none;
  box-shadow: none;
}

/* --- Contract Type Segmented Control --- */

.segmented-control {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.25rem;
  gap: 0.25rem;
}

[data-theme="dark"] .segmented-control {
  background: var(--bg);
}

.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background-color 0.15s, color 0.15s;
  user-select: none;
}

.segmented-control label:hover {
  color: var(--text);
}

.segmented-control input[type="radio"]:checked + label {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.segmented-control input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Results Panel --- */

.results-panel {
  min-width: 0;
}

.results-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

/* --- Results Matrix Table --- */

#results-matrix {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  margin-bottom: 1.5rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}

.results-table th,
.results-table td {
  padding: 0.625rem 1rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

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

.results-table thead th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
  position: sticky;
  top: 0;
}

.results-table tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

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

/* NET row highlight */
.results-table tr.row-net {
  background: var(--net-bg) !important;
  font-weight: 700;
}

.results-table tr.row-net td {
  color: var(--net-highlight);
  border-top: 2px solid var(--net-highlight);
}

.results-table tr.row-net td:first-child {
  color: var(--text);
}

/* Negative values */
.val-negative {
  color: var(--negative);
}

/* Warning rows */
.row-warning {
  background: var(--warning-bg) !important;
}

.row-warning td {
  color: var(--warning-text);
}

/* --- Salary/Dividends Slider --- */

#salary-slider-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

#salary-slider-container h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.slider-labels strong {
  color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  margin: 0.5rem 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.slider-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
}

#optimal-indicator {
  color: var(--net-highlight);
  font-weight: 500;
}

#btn-reset-optimal {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.8125rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: background-color 0.15s;
}

#btn-reset-optimal:hover {
  background: var(--accent-light);
}

/* --- Export Buttons --- */

.export-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.export-buttons button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.export-buttons button:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Toast Notification --- */

#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Settings Modal --- */

#settings-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 2rem;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-content .form-group {
  margin-bottom: 1rem;
}

.modal-content label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.modal-content input[type="number"],
.modal-content input[type="text"],
.modal-content select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.modal-content input:focus,
.modal-content select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

#btn-reset-defaults {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

#btn-reset-defaults:hover {
  background: var(--negative-light);
  color: var(--negative);
  border-color: var(--negative);
}

#btn-close-settings {
  background: var(--accent);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  transition: opacity 0.15s;
}

#btn-close-settings:hover {
  opacity: 0.9;
}

/* --- Hidden Utility --- */

.hidden {
  display: none !important;
}

/* --- Print Styles --- */

@media print {
  .input-panel,
  .app-header .btn-settings,
  .export-buttons,
  #salary-slider-container,
  #settings-modal,
  #toast {
    display: none !important;
  }

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

  body {
    background: #fff;
    color: #000;
  }

  .results-table th,
  .results-table td {
    border-color: #ccc;
  }
}

/* --- Validation Error --- */

.validation-error {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* --- Screen Reader Only --- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --- Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Responsive Adjustments --- */

@media (max-width: 768px) {
  .app-header h1 {
    font-size: 1.25rem;
  }

  .input-panel {
    padding: 1rem;
  }

  #results-matrix {
    margin-left: -1rem;
    margin-right: -1rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

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