/* CSS Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base Styles */
html {
  font-size: 10px; /* 1rem = 10px */
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Arial', sans-serif;
}
html, body {
  height: 100vh;
  margin: 0;
  padding: 0;
  /* background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); */

}
/* Layout */
.container {
  max-width: 800px;
  margin: 0.5rem auto 0;
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  border-radius: 0.8rem;
  box-shadow: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.1);
  color: black;
  background: white;

}

.main-container {
  display: flex;
  flex-direction: column;
}

/* Header Styles */
.modern-header {
  background: linear-gradient(to right, #3b82f6, #8b5cf6);
  color: white;
  padding: 2rem;
  box-shadow: 0 1rem 1.5rem -0.3rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.6rem -0.2rem rgba(0, 0, 0, 0.05);
}

.modern-header-container {
  max-width: 120rem;
  margin: 0 auto;
}

/* Icons removed - no icon styling needed */

.modern-header-container .chev-icon{
  margin-left:0.4rem;
}

.header-content {
  text-align: center;
  margin-bottom: 2rem;
}

.header-content h1 {
  font-size: 3.6rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.header-content p {
  font-size: 2rem;
}

.button-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

/* Button Styles */
.upload-button, .url-button {
  border: transparent;
  background-color: white;
  color: #3b82f6;
  font-weight: 600;
  padding: 1rem 1.5rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
  font-size: 1.6rem;
  width: 180px;
  justify-content: center;
  box-sizing: border-box;
}

.upload-button:hover, .url-button:hover {
  background-color: #e6f0ff;
}

.hidden-input {
  display: none;
}

/* Form Styles */
.url-input-container {
  position: relative;
}

.url-form {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.5rem;
  width: 25rem;
  background-color: white;
  border-radius: 0.8rem;
  box-shadow: 0 1rem 1.5rem -0.3rem rgba(0, 0, 0, 0.1), 0 0.4rem 0.6rem -0.2rem rgba(0, 0, 0, 0.05);
  padding: 1rem;
  z-index: 10;
}

.hidden {
  display: none !important;
}

.hidden-inline {
  display: none;
}

.hidden-image {
  display: none;
}

.url-input {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 0.4rem;
  border: 1px solid #e5e7eb;
  color: #1f2937;
  font-size: 1.4rem;
}

.url-input:focus {
  outline: none;
  border-color: #3b82f6;
}

.submit-button {
  margin-top: 1rem;
  width: 100%;
  background-color: #3b82f6;
  color: white;
  font-weight: 600;
  padding: 0.8rem 1rem;
  border-radius: 0.4rem;
  border: none;
  cursor: pointer;
  transition: background-color 0.3s;
  font-size: 1.4rem;
}

.submit-button:hover {
  background-color: #2563eb;
}

/* Explanation Container */
.explenation-container {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 1.6rem;
  border-radius: 0.8rem;
  box-shadow: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.1);
  font-size: 1.4rem;
  line-height: 1.6;
  color: #333;
  margin-bottom: 2rem;
}

.explenation-container h2 {
  font-size: 1.8rem;
  margin-bottom: 1.2rem;
}

.explenation-container p,
.explenation-container ol {
  margin-bottom: 1.2rem;
}

.explenation-container ol {
  padding-left: 2rem;
}

.explenation-container li {
  margin-bottom: 0.8rem;
}

/* Calculator Container */
.calc-container {
  display: none; /* Hide by default */
  background: linear-gradient(135deg, #ffffff 0%, #e0e0e0 100%);
  padding: 1.6rem;
  border-radius: 0.8rem;
  box-shadow: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.1);
  font-size: 1.4rem;
  line-height: 1.6;
  color: #333;
  margin-bottom: 2rem;
}

.calc-header {
  margin-bottom: 0.5rem;
}

.calc-header h2 {
  margin: 0;
  margin-bottom: 0.5rem;
}

.calc-header .grade-legend {
  margin: 0;
  flex-shrink: 0;
  margin-bottom: 0;
}


.calc-container:not(.hidden) {
  display: block; /* Show when visible class is added */
}

.calc-container input[type="file"] {
  margin-bottom: 1.6rem;
  width: 100%;
  padding: 1rem;
  border: 2px dashed #ccc;
  border-radius: 5px;
  font-size: 1.4rem;
}

/* Results Container */
.results-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-top: 2rem;
}

.image-preview, .size-selector {
  background-color: #f8fafc;
  border-radius: 0.8rem;
  padding: 1.6rem;
  box-shadow: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.1);
}

.image-preview h3, .size-selector h3 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  color: #1e293b;
}

.analysis-info-icon {
  display: inline-block;
  width: 1.4em;
  height: 1.4em;
  line-height: 1.4em;
  text-align: center;
  border-radius: 50%;
  background-color: #3b82f6;
  color: white;
  font-size: 0.9em;
  font-weight: bold;
  cursor: help;
  margin-left: 0.5em;
  position: relative;
  vertical-align: middle;
  font-style: normal;
}

.analysis-tooltip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #1e293b;
  color: white;
  padding: 1rem 1.2rem;
  border-radius: 0.4rem;
  font-size: 1.2rem;
  white-space: normal;
  width: 300px;
  text-align: left;
  z-index: 1000;
  margin-bottom: 0.5rem;
  box-shadow: 0 0.2rem 0.4rem rgba(0, 0, 0, 0.2);
  line-height: 1.5;
}

.analysis-info-icon:hover .analysis-tooltip {
  display: block;
}

.analysis-info-icon:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 0.5rem solid transparent;
  border-top-color: #1e293b;
  margin-bottom: -0.5rem;
  z-index: 1001;
}

.image-display {
  width: 100%;
  height: 250px;
  border-radius: 0.4rem;
  position: relative;
  overflow: hidden;
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

.image-display img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

#quality-canvas {
  position: absolute;
  border-radius: 0.4rem;
  display: block; /* Always visible as primary display */
  pointer-events: none; /* Don't interfere with interactions */
  /* Width, height, top, and left will be set dynamically via JavaScript */
}

.preview-frame {
  position: absolute;
  border: 2px solid #000000;
  background-color: transparent;
  pointer-events: none;
  z-index: 10;
  box-sizing: border-box;
}

.fitting-controls {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.fitting-buttons-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.fitting-button {
  padding: 0.8rem 1.6rem;
  border: 2px solid #3b82f6;
  background-color: white;
  color: #3b82f6;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.fitting-button:hover {
  background-color: #eff6ff;
}

.fitting-button.active {
  background-color: #3b82f6;
  color: white;
}

.fitting-button.active:hover {
  background-color: #2563eb;
}


.image-analysis {
  margin-top: 10px;
  text-align: center;
  font-size: 1.2rem;
  color: #374151;
}

.analysis-text {
  background-color: rgba(255, 255, 255, 0.9);
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  line-height: 1.5;
}

.analysis-text strong {
  color: #1f2937;
}

.analysis-summary {
  text-align: left;
  max-width: 300px;
  margin: 0 auto;
}


.image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  transition: background-color 0.3s ease;
}

.image-overlay h4 {
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
}

.image-overlay p {
  font-size: 1.4rem;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 1rem;
}

.size-option {
  padding: 0.8rem 0.4rem;
  border: none;
  border-radius: 0.4rem;
  font-size: 1.2rem;
  color: white;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.size-option::after {
  content: attr(data-unit);
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 0.8rem;
  opacity: 0.7;
}

.delete-custom-size {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background-color: rgba(239, 68, 68, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background-color 0.2s;
}

.delete-custom-size:hover {
  background-color: rgba(239, 68, 68, 1);
}

.size-option {
  position: relative;
}

.size-option:hover, .size-option.selected {
  transform: translateY(-2px);
  box-shadow: 0 0.4rem 0.6rem rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
  .container {
    margin-top: 1rem;
    padding: 2.4rem;
  }

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

  .image-display {
    margin-right: 0;
    margin-bottom: 1.5rem;
  }

}

@media (min-width: 1000px) {
  .main-container {
    flex-direction: column;
  }

  .calc-container, .explenation-container {
    width: 100%;
  }

}

.calc-header .grade-legend {
  margin: 0;
}

.summary-text {
  margin-top: 1rem;
  font-size: 1.6rem;
  color: #4b5563;
  line-height: 1.6;
}

.summary-text p {
  margin: 0.5rem 0;
}

.summary-text strong {
  color: #1e293b;
  font-weight: 600;
}

.summary-text .measurement-with-tooltip {
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: help;
  position: relative;
}

.summary-text .measurement-with-tooltip:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #1e293b;
  color: white;
  padding: 0.5rem 0.8rem;
  border-radius: 0.4rem;
  font-size: 1.2rem;
  white-space: nowrap;
  z-index: 1000;
  margin-bottom: 0.5rem;
  box-shadow: 0 0.2rem 0.4rem rgba(0, 0, 0, 0.2);
}

.summary-text .measurement-with-tooltip:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 0.5rem solid transparent;
  border-top-color: #1e293b;
  margin-bottom: -0.5rem;
  z-index: 1001;
}

.legend-items {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: flex-start;
  font-size: 1.1rem;
}

.legend-text {
  display: flex;
  flex-direction: column;
  margin-left: 6px;
}

.legend-text .quality {
  font-weight: bold;
  line-height: 1.2;
}

.legend-text .range {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.1;
}

.color-swatch {
  width: 16px;
  height: 16px;
  display: inline-block;
  margin-top: 2px;
  border-radius: 3px;
  flex-shrink: 0;
}

.color-excellent {
  background-color: #10B981;
}

.color-good {
  background-color: #F59E0B;
}

.color-fair {
  background-color: #F97316;
}

.color-poor {
  background-color: #EF4444;
}

.custom-size-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.custom-size-form input {
  padding: 8px 12px;
  border: 1px solid #D1D5DB;
  border-radius: 4px;
  width: 90px;
}

.width-field, .height-field {
  width: 70px !important;
}

.ratio-field {
  width: 120px !important;
}

.custom-size-form input:disabled {
  background-color: #f9f9f9;
  cursor: not-allowed;
}

.field-label {
  position: absolute;
  top: -8px;
  left: 8px;
  background: white;
  padding: 0 4px;
  font-size: 1rem;
  color: #6B7280;
  font-weight: 500;
}

.input-wrapper {
  position: relative;
  display: inline-block;
}

.unit-toggle {
  padding: 8px 12px;
  background-color: #E5E7EB;
  color: #374151;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-weight: bold;
}

.unit-toggle:hover {
  background-color: #D1D5DB;
}

.custom-size-form button[type="submit"],
.custom-size-form button[type="button"]:not(.unit-toggle) {
  padding: 8px 16px;
  background-color: #4F46E5;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.custom-size-form button[type="submit"]:hover,
.custom-size-form button[type="button"]:not(.unit-toggle):hover {
  background-color: #4338CA;
}

.custom-size-form button[type="button"]:not(.unit-toggle) {
  background-color: #9CA3AF;
}

.custom-size-form button[type="button"]:not(.unit-toggle):hover {
  background-color: #6B7280;
}

.add-custom-size {
  font-size: 1.2rem !important;
  font-weight: bold;
  color: white;
  background-color: #6B7280 !important;
  padding: 0.8rem 0.4rem !important;
}

.add-custom-size:hover {
  background-color: #4B5563 !important;
  transform: translateY(-2px);
}

.custom-size-form-container {
  margin-top: 20px;
}
