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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
}

header {
  background-color: #2c3e50;
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
  margin-bottom: 0.25rem;
}

header p {
  font-size: 0.9rem;
  color: #ecf0f1;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

section {
  background: white;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.input-section label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.input-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#wms-url {
  flex: 1;
  max-width: 70%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

#load-btn, #load-file-btn {
  flex: 0 0 auto;
}

@media (max-width: 700px) {
  .input-group {
    flex-direction: column;
  }
  
  #wms-url {
    width: 100%;
    max-width: none;
  }
  
  #load-btn, #load-file-btn {
    width: 100%;
  }
}

#wms-url:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

button {
  padding: 0.75rem 1.5rem;
  background-color: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

button:hover {
  background-color: #2980b9;
}

button:active {
  background-color: #21618c;
}

.service-info h2 {
  margin-bottom: 1rem;
  color: #2c3e50;
}

#service-details {
  font-size: 0.95rem;
}

#service-details h3 {
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  color: #2c3e50;
}

#service-details p {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#service-details a {
  word-break: break-all;
  overflow-wrap: break-word;
}

.layers-list {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.layer-item {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1rem;
  background-color: #fafafa;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.layer-controls {
  flex: 0 0 300px;
  min-width: 300px;
  max-width: 300px;
  overflow: hidden;
}

.layer-viewer-container {
  flex: 1 1 300px;
  min-height: 300px;
  min-width: 300px;
}

/* 
  Responsive layout: switch to vertical when viewer would be < 50% width
  Breakpoint: 300px (controls) + 16px (gap) + 300px (min viewer) = 616px content
  Plus padding/margins: ~776px viewport width
*/
@media (max-width: 800px) {
  .layer-item {
    flex-direction: column;
    align-items: stretch;
  }
  
  .layer-controls {
    flex: 1 1 auto;
    min-width: 100%;
    max-width: 100%;
  }
  
  .layer-viewer-container {
    flex: 1 1 auto;
    width: 100%;
    min-width: 100%;
  }
}

.layer-viewer-container mapml-viewer {
  width: 100%;
  height: 300px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.layer-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.layer-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.layer-header label {
  cursor: pointer;
  margin: 0;
}

.query-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin-left: auto;
}

.query-label {
  font-size: 0.85rem;
  font-weight: normal;
  color: #666;
  cursor: pointer;
}

.bounds-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  justify-content: flex-start;
}

.bounds-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.bounds-label {
  font-size: 0.85rem;
  font-weight: normal;
  color: #666;
  cursor: pointer;
  margin: 0;
}

.query-format-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  justify-content: flex-start;
}

.query-format-selector label {
  color: #666;
  font-weight: normal;
  margin: 0;
}

.query-format-selector .query-checkbox {
  margin-left: 0;
  margin-right: 0.25rem;
}

.style-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.style-selector label {
  color: #666;
  font-weight: normal;
  margin: 0;
}

.style-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.85rem;
  background-color: white;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.style-select:focus {
  outline: none;
  border-color: #3498db;
}

.dimension-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.dimension-selector label {
  color: #666;
  font-weight: normal;
  margin: 0;
  min-width: 100px;
}

.dimension-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.dimension-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.85rem;
  background-color: white;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dimension-select:focus {
  outline: none;
  border-color: #3498db;
}

.format-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.85rem;
  background-color: white;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.format-select:focus {
  outline: none;
  border-color: #3498db;
}

.projection-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.projection-selector label {
  color: #666;
  font-weight: normal;
  margin: 0;
}

.projection-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.85rem;
  background-color: white;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.projection-select:focus {
  outline: none;
  border-color: #3498db;
}

.format-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.format-selector label {
  color: #666;
  font-weight: normal;
  margin: 0;
}

.layer-name {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.75rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.layer-preview {
  width: 100px;
  height: 100px;
  border: 1px solid #ddd;
  border-radius: 4px;
  display: block;
  object-fit: cover;
}

.hidden {
  display: none;
}

.map-section h2 {
  margin-bottom: 1rem;
  color: #2c3e50;
}

mapml-viewer {
  display: block;
  width: 100%;
  height: 500px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

/* Source code controls */
.source-code-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.source-toggle-btn,
.source-copy-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid #ddd;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
}

.source-toggle-btn {
  background-color: #ecf0f1;
  color: #2c3e50;
}

.source-toggle-btn:hover {
  background-color: #d5dbdb;
}

.source-copy-btn {
  background-color: #3498db;
  color: white;
  border-color: #3498db;
}

.source-copy-btn:hover {
  background-color: #2980b9;
}

.source-code-textarea {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.75rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f8f9fa;
  color: #2c3e50;
  resize: none;
  white-space: pre;
  overflow-y: hidden;
  overflow-x: auto;
  tab-size: 2;
}
