:root {
  /* Modern Dark Theme Palette - "Verksted / Premium Technical" */
  --bg-dark: #0f0f0f;

  /* Glassmorphism variabler */
  --glass-bg: rgba(30, 35, 40, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);

  /* Kort og paneler */
  --card-bg: rgba(45, 50, 55, 0.6);
  --card-hover: rgba(60, 65, 70, 0.8);

  /* Tekst og input */
  --text-main: #ffffff;
  --text-muted: #a0a0a0;
  --bg-input: rgba(0, 0, 0, 0.3);

  --primary: #3498db;
  --accent: #ff9f43;
  /* Klar oransje for mørk bakgrunn */
  --accent-hover: #ffaf40;

  --border-light: rgba(255, 255, 255, 0.1);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-card: 0 4px 10px rgba(0, 0, 0, 0.2);
  --shadow-hover: 0 10px 25px rgba(0, 0, 0, 0.3);

  /* Kontrollpunkt-farger */
  --cp-wheel: #2ecc71;
  --cp-steering: #3498db;
  --cp-rake: #9b59b6;
  --cp-frame-top: #1abc9c;
  --cp-frame-bottom: #e74c3c;
  --cp-frame-angle: #c0392b;
  --cp-fork: #e67e22;
  --cp-image: #f1c40f;
  --cp-rotation: #8e44ad;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg-dark);
  background-image: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2)), url('verksted_bg.jpg');

  background-size: cover;
  background-attachment: fixed;
  background-position: center;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Container wrapper - Transparent now (Floating boxes) */
.container {
  width: 95%;
  max-width: 1400px;
  margin: 10px auto;
  /* Removed background/blur/border for floating look */
  padding: 10px;
}

/* Header styling */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  /* Mindre margin */
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  position: relative;
  z-index: 100;
  /* Ensure buttons are clickable */
}

h1 {
  font-weight: 800;
  color: var(--text-main);
  font-size: 1.5rem;
  /* Mindre tittel */
  margin: 0;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Språkvelger og knapper */
.lang-toggle {
  display: flex;
  gap: 8px;
}

.lang-toggle button,
.about-btn {
  padding: 6px 12px;
  /* Mindre knapper */
  cursor: pointer;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.8rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-muted);
}

.lang-toggle button:hover,
.about-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
  border-color: var(--accent);
}

.lang-toggle button.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(255, 159, 67, 0.4);
}

/* Hovedlayout */
.main-layout {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px;
  /* Mindre gap */
  width: 100%;
}

@media (min-width: 1600px) {
  .main-layout {
    flex-direction: row;
  }
}

/* Control Rows Layout */
.control-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  gap: 10px;
  width: 100%;
  margin-bottom: 10px;
}

.top-controls {
  align-items: stretch;
  flex-wrap: nowrap !important;
}

.top-controls .input-section {
  flex: 1 1 0;
  min-width: 0;
}

.bottom-controls {
  align-items: stretch;
}

/* Gjør inputs-panel full bredde */
.inputs-panel {
  width: 100%;
  max-width: 100%;
}

/* Gjør kortene mye mer kompakte - ULTRA COMPACT MODE */
.input-section {
  flex: 1 1 150px;
  /* Smalere basis */
  max-width: 100%;
  /* Allow stretching to fill available width */
  background: rgba(45, 50, 55, 0.95);
  /* Nesten solid bakgrunn for lesbarhet */
  padding: 8px 10px;
  /* Minimal padding */
  border-radius: 6px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-light);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s;
  display: flex;
  flex-direction: column;
}

.input-section:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
  background: #3a4046;
}

.input-section-title {
  font-size: 0.6rem;
  /* Veldig liten tittel */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 4px;
  min-height: 20px;
  /* Ensure equal height alignment */
}

/* Input layout inni kortene */
.input-section {
  display: flex;
  flex-direction: column;
  /* Force column layout inside cards */
  flex-wrap: nowrap;
  gap: 8px;
  /* Slightly larger gap */
  align-items: stretch;
  justify-content: flex-start;
  overflow: visible;
  /* Ensure content isn't clipped hidden */
  min-height: auto;
  /* Let content dictate height */
}

.input-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
  /* Don't shrink or grow weirdly */
  width: 100%;
}

.input-item label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 1px;
}

/* Range Wrapper Layout - Compact */
.range-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 24px;
  /* Ensure it has a minimum height */
}

.range-wrapper input[type="range"] {
  flex: 1;
  /* Slider takes available space */
  cursor: pointer;
  height: 6px;
  /* Tykkere spor for synlighet */
  background: rgba(255, 255, 255, 0.3);
  /* Mye lysere spor */
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-width: 50px;
  /* Ensure it never shrinks to 0 */
  display: block;
  /* Force block behavior */
}

.range-wrapper input[type="range"]:hover {
  background: rgba(255, 255, 255, 0.5);
  /* Enda lysere ved hover */
}

/* Custom Slider Thumb Styling - Compact */
.range-wrapper input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  /* Mindre knapp */
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid #2d3436;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s, background 0.2s;
  margin-top: -4px;
  /* Juster for å sentrere på tynn linje */
}

.range-wrapper input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: var(--accent-hover);
}

.range-wrapper input[type="number"] {
  width: 45px;
  /* Smalere input felt */
  text-align: center;
  font-weight: 600;
  padding: 2px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
  color: var(--accent);
  -moz-appearance: textfield;
  appearance: textfield;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  height: 20px;
}

/* Remove arrows in Chrome/Safari/Edge/Opera */
.range-wrapper input[type="number"]::-webkit-outer-spin-button,
.range-wrapper input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.range-wrapper input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
  background: rgba(0, 0, 0, 0.4);
}

.unit {
  display: none;
}

/* Lock button styling */
.lock-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0 2px;
  opacity: 0.4;
  transition: opacity 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.lock-btn:hover {
  opacity: 0.8;
}

.lock-btn.locked {
  opacity: 1;
}

.range-wrapper.locked input[type="range"] {
  opacity: 0.3;
  pointer-events: none;
}

.range-wrapper.locked input[type="number"] {
  opacity: 0.3;
  pointer-events: none;
}

/* Adjustment panel lock button */
.adjustment-row .lock-btn {
  font-size: 0.75rem;
  margin-left: 4px;
}

/* Resultater - spesialstyling */
.results-section {
  background: rgba(46, 204, 113, 0.15);
  /* Litt tydeligere grønn */
  border-left: 2px solid var(--cp-wheel);
}

.results-section .input-section-title {
  color: var(--cp-wheel);
}

.results-section input[type="text"],
.results-section input[readonly] {
  background: transparent;
  font-weight: 700;
  color: var(--cp-wheel);
  border: none;
  font-size: 0.9rem;
  padding: 0;
  text-align: left;
  height: auto;
}

/* Knapper */
.button-section {
  display: flex;
  gap: 10px;
  /* Match Results section growth */
  flex: 1 1 150px;
  min-width: 200px;
  flex-direction: column;
}

.button-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  /* Fill the height */
}

.action-btn {
  flex: 1;
  /* Each button takes 50% height */
  padding: 0;
  /* Let flex center content */
  display: flex;
  justify-content: center;
  align-items: center;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 45px;
  /* Minimum clickable area */
}

.download-pdf-btn {
  background: var(--cp-steering);
}

.download-pdf-btn:hover {
  background: #2980b9;
  box-shadow: 0 2px 10px rgba(52, 152, 219, 0.4);
}

.exterior-btn {
  background: #27ae60;
  /* Greenish */
}

.exterior-btn:hover {
  background: #2ecc71;
}

.exterior-btn.active {
  background: #2ecc71;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.2);
}

.snap-btn {
  background: #16a085;
}

.snap-btn:hover {
  background: #1abc9c;
}

.snap-btn.active {
  background: #1abc9c;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.2);
}

.grid-btn {
  background: #8e44ad;
}

.grid-btn:hover {
  background: #9b59b6;
}

.grid-btn.active {
  background: #9b59b6;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.2);
}

.measurements-btn {
  background: #d35400;
}

.measurements-btn:hover {
  background: #e67e22;
}

.measurements-btn.active {
  background: #e67e22;
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.2);
}

/* Canvas Container */
.canvas-panel {
  width: 100%;
  padding: 10px;
}

#canvas-container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  /* Handle overflow */
  /* Ensure canvas doesn't get clipped weirdly */
  /* max-width: 100%; Removed to allow zoom expansion */
  position: relative;
  overflow: hidden;
  /* Changed to hidden to clip the white box, but we will make the box grow */
  display: block;
  /* Standard block */
  transition: all 0.3s ease;
}

.canvas-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-top: 15px;
  padding: 12px 15px;
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  flex-wrap: wrap;
}

.canvas-results {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-item label {
  font-weight: 600;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
}

.result-item input {
  width: 65px;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

.result-item .unit {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

.canvas-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.canvas-buttons .action-btn {
  padding: 8px 16px;
  font-size: 0.8rem;
  min-height: auto;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.zoom-controls {
  position: absolute;
  top: 15px;
  left: 15px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.zoom-btn {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s, background 0.2s;
}

.zoom-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

.zoom-btn:active {
  transform: scale(0.95);
}

#test {
  border: none !important;
  background-color: #ffffff;
}

/* Modal Styling - FIXED */
.modal-overlay {
  display: none;
  /* Skjult som standard */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 99999;
  /* Super high z-index */
  justify-content: center;
  align-items: center;
}

/* This class is added by JS to show the modal */
.modal-overlay.visible {
  display: flex !important;
}

.modal-content {
  background: #1e272e;
  border-radius: var(--radius-lg);
  padding: 30px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  max-width: 450px;
  width: 90%;
  position: relative;
  text-align: center;
}

.modal-content h2 {
  color: var(--accent);
  margin-top: 5px;
  font-size: 1.4rem;
}

.modal-logo {
  max-height: 60px;
  /* Begrenset høyde for logo */
  width: auto;
  margin: 0 auto 15px auto;
  display: block;
}

.modal-content p {
  color: #d2dae2;
  line-height: 1.5;
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.modal-content a {
  color: var(--accent);
  text-decoration: none;
}

.modal-content a:hover {
  text-decoration: underline;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 24px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 5px;
}

.modal-close:hover {
  color: var(--accent);
}


/* Help Modal */
.help-modal-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}

.help-sections {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 0;
  font-size: 0.95rem;
  list-style: none;
}

.help-section summary::before {
  content: '▸ ';
}

.help-section[open] summary::before {
  content: '▾ ';
}

.help-body {
  padding: 4px 0 8px 12px;
}

.help-body p {
  margin: 0 0 8px 0;
}

.help-body ul {
  margin: 4px 0 0 0;
  padding-left: 18px;
}

.help-body li {
  color: #d2dae2;
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 4px;
}

/* Info Button Styling */
.info-btn {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  margin-left: auto;
  line-height: 1;
}

.info-btn:hover {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(255, 159, 67, 0.4);
}

/* Info Popup Styling */
.info-popup {
  display: none;
  position: fixed;
  z-index: 99999;
  background: linear-gradient(145deg, #1e272e 0%, #2c3e50 100%);
  border-radius: var(--radius-md);
  padding: 15px 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 159, 67, 0.3);
  color: white;
  max-width: 350px;
  width: max-content;
  text-align: left;
  animation: popupFadeIn 0.2s ease;
}

.info-popup.visible {
  display: block !important;
}

@keyframes popupFadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.info-popup h3 {
  color: var(--accent);
  margin: 0 0 10px 0;
  font-size: 0.95rem;
  padding-right: 20px;
}

.info-popup p {
  color: #d2dae2;
  line-height: 1.5;
  font-size: 0.8rem;
  margin-bottom: 8px;
}

.info-popup p:last-of-type {
  margin-bottom: 0;
}

.info-popup .info-highlight {
  color: var(--accent);
  font-weight: 600;
}

.info-popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 18px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

.info-popup-close:hover {
  color: var(--accent);
}

.site-footer {
  width: 100%;
  text-align: center;
  padding: 20px;
  color: #eeeeee;
  /* Brighter white for better visibility */
  font-size: 0.85rem;
  margin-top: 40px;
  /* Ensure spacing */
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  z-index: 10;
}