/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #8b9099;
  --primary-hover: #6b7280;
  --secondary-color: #d1d5db;
  --success-color: #9ca3af;
  --warning-color: #9ca3af;
  --danger-color: #6b7280;
  --text-primary: #000000;
  --text-secondary: #000000;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;
  --border-color: #d4d4d4;
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 6px 0 rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px 0 rgba(0, 0, 0, 0.12);
}

@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&display=swap');

body {
  font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #fafafa;
  min-height: 100vh;
  padding: 1.5rem;
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Container */
.container {
  max-width: 900px;
  margin: 0 auto;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
  background: var(--bg-primary);
  padding: 2rem 1.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
}

/* Main Content */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Cards */
.calculator-card,
.risk-table-card {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

/* Section Title */
.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color);
}

/* Input Groups */
.input-group {
  margin-bottom: 1.25rem;
}

.input-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.input-select,
.input-number {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.2s;
  background: white;
  color: var(--text-primary);
  font-family: 'Lato', sans-serif;
}

.input-select:focus,
.input-number:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.input-select option[disabled] {
  color: var(--secondary-color);
}

.input-number {
  -moz-appearance: textfield;
}

.input-number::-webkit-inner-spin-button,
.input-number::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Button Link */
.btn-link {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: underline;
  margin-left: 0.5rem;
  padding: 0;
  transition: color 0.2s;
  font-weight: 600;
}

.btn-link:hover {
  color: var(--primary-hover);
}

/* Checkbox Group */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border-color);
}

.checkbox-label:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary-color);
}

.checkbox-input {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: 0.75rem;
  cursor: pointer;
  accent-color: var(--primary-color);
}

.checkbox-label span:nth-child(2) {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 400;
}

.points-badge {
  padding: 0.25rem 0.75rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
}

.points-badge.negative {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border-color);
  margin: 2rem 0;
}

/* Buttons */
.button-group {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.btn {
  flex: 1;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: 'Lato', sans-serif;
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
  border: 2px solid var(--text-primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--primary-color);
}

/* Result Section */
.result-section {
  margin-top: 2rem;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-card {
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
  border: 2px solid var(--border-color);
}

.result-label {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-primary);
  font-weight: 600;
}

.result-value {
  font-size: 3.5rem;
  font-weight: 900;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.result-risk {
  font-size: 1.125rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  background: var(--bg-primary);
  border-radius: 20px;
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

/* Warning Message */
.warning-message {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-left: 4px solid var(--text-primary);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 600;
}

/* Risk Table */
.table-responsive {
  overflow-x: auto;
}

.risk-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.risk-table thead {
  background: var(--bg-secondary);
}

.risk-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-color);
}

.risk-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 400;
}

.risk-table tbody tr {
  transition: background 0.2s;
}

.risk-table tbody tr:hover {
  background: var(--bg-secondary);
}

.risk-low td:nth-child(2),
.risk-moderate td:nth-child(2),
.risk-high td:nth-child(2),
.risk-very-high td:nth-child(2) {
  color: var(--text-primary);
  font-weight: 700;
}

/* Footer */
.footer {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 2rem;
  margin-top: 2rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
  border: 1px solid var(--border-color);
}

.reference {
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.reference strong {
  color: var(--text-primary);
  font-weight: 700;
}

.reference a {
  color: var(--text-primary);
  text-decoration: underline;
  font-weight: 600;
}

.reference a:hover {
  color: var(--primary-hover);
}

.author-info {
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.875rem;
  color: var(--text-primary);
}

.author-info p {
  margin: 0.25rem 0;
  font-weight: 400;
}

.author-info strong {
  font-weight: 700;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s;
  border: 1px solid var(--border-color);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
  line-height: 1;
}

.modal-close:hover {
  background: var(--bg-secondary);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.sofa-result {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  text-align: center;
  font-size: 1.125rem;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.sofa-result span {
  color: var(--text-primary);
  font-weight: 900;
  font-size: 1.5rem;
  margin-left: 0.5rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }

  .title {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.875rem;
  }

  .header {
    padding: 1.5rem 1rem;
  }

  .calculator-card,
  .risk-table-card {
    padding: 1.25rem;
  }

  .section-title {
    font-size: 1.125rem;
  }

  .button-group {
    flex-direction: column;
  }

  .btn {
    padding: 1rem 1.5rem;
  }

  .result-value {
    font-size: 2.5rem;
  }

  .risk-table th,
  .risk-table td {
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
  }

  .footer {
    padding: 1.25rem;
  }

  .modal-content {
    margin: 0.5rem;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 1rem;
  }

  .checkbox-label {
    padding: 0.875rem;
  }

  .input-select,
  .input-number {
    padding: 0.875rem;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0.75rem;
  }

  .title {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .header {
    padding: 1.25rem 0.875rem;
  }

  .calculator-card,
  .risk-table-card {
    padding: 1rem;
  }

  .checkbox-label {
    padding: 0.75rem;
    font-size: 0.875rem;
  }

  .checkbox-input {
    width: 1.125rem;
    height: 1.125rem;
  }

  .points-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }

  .result-value {
    font-size: 2rem;
  }

  .result-risk {
    font-size: 1rem;
  }

  .risk-table th,
  .risk-table td {
    padding: 0.5rem 0.25rem;
    font-size: 0.8rem;
  }

  .modal-header h2 {
    font-size: 1.25rem;
  }
}

/* iOS and Android Specific Optimizations */
/* Remove tap highlight on mobile */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Ensure touch targets are at least 44px (iOS guideline) */
.btn,
.checkbox-input,
.input-select,
.input-number,
.modal-close {
  min-height: 44px;
}

/* Smooth scrolling for iOS */
body,
.modal-content {
  -webkit-overflow-scrolling: touch;
}

/* Better focus states for accessibility */
.input-select:focus,
.input-number:focus,
.btn:focus,
.checkbox-input:focus {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* Prevent text size adjustment on orientation change (iOS) */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Safe area insets for notched devices (iOS) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
    padding: 0;
  }

  .calculator-card,
  .risk-table-card,
  .footer {
    box-shadow: none;
    page-break-inside: avoid;
  }

  .btn,
  .modal {
    display: none;
  }
}
