/* Universal Scales - Styles */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --accent-color: #007bff;
    --hover-bg: #e9ecef;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);
    
    /* Z-index scale - organized by layer */
    --z-base: 1;
    --z-sticky-header: 5;
    --z-sticky-section: 5;
    --z-editor-header: 10;
    --z-editor-save: 10;
    --z-zoom-controls: 1100;
    --z-zoom-controls-floating: 1300;
    --z-modal: 2000;
    --z-tooltip: 3000;
    --z-tooltip-pinned: 4000;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #adb5bd;
    --border-color: #495057;
    --accent-color: #0d6efd;
    --hover-bg: #343a40;
    --shadow: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header Styles */
.header {
    text-align: center;
    padding: 2rem 0;
    margin-bottom: 0.5rem; /* Reduced from 2rem to decrease space after header */
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: var(--text-secondary);
}

select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

select:hover {
    border-color: var(--accent-color);
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.notation-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 70px; /* Fixed width to prevent layout shift */
    height: 40px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary); /* Use theme-aware text color */
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    margin-left: 10px;
    font-family: inherit;
    overflow: hidden; /* Prevent text overflow */
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1;
}

.notation-toggle sup {
    font-size: 0.7em;
    vertical-align: super;
    line-height: 0;
    position: relative;
    top: -0.4em;
}

.notation-toggle:hover {
    background-color: var(--hover-bg);
    transform: scale(1.05);
}

.dark-mode-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dark-mode-toggle:hover {
    background-color: var(--hover-bg);
    transform: scale(1.05);
}

.music-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.music-toggle:hover {
    background-color: var(--hover-bg);
    transform: scale(1.05);
}

.music-toggle.playing {
    background-color: var(--accent-color);
    color: white;
}

/* Description Styles */
.dimension-description {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 0.75rem;
    margin-bottom: 0.25rem; /* Reduced from 0.5rem to decrease space before graph */
    font-style: italic;
    min-height: 0; /* Allow element to collapse when empty */
}

.dimension-description:empty {
    display: none; /* Hide completely when empty to remove spacing */
    margin: 0;
}

.unit-description {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem; /* Reduced from 1rem to decrease space before footer */
    min-height: 0; /* Allow element to collapse when empty */
}

.unit-description:empty {
    display: none; /* Hide completely when empty to remove spacing */
    margin: 0;
}

/* Editor Panel Styles */
.editor-panel {
    margin: 1.5rem 0 0.5rem 0; /* Reduced bottom margin to decrease space before footer */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    overflow: hidden;
}

.editor-toggle {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-primary);
    border: none;
    border-bottom: 1px solid var(--border-color);
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
}

.editor-toggle-text {
    font-size: 1rem;
    font-weight: 500; /* Not bold, same as section headers */
}

.editor-toggle:hover {
    background-color: var(--bg-secondary);
}

.editor-toggle-icon {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    display: inline-block;
    border-radius: 1px; /* Slight rounding for smoother appearance */
}

.editor-toggle:not(.expanded) .editor-toggle-icon {
    transform: rotate(-90deg); /* Rotate from down to right when collapsed */
}

.editor-toggle.expanded .editor-toggle-icon {
    transform: rotate(0deg); /* Point down when expanded */
}

.editor-content {
    padding: 0;
    max-height: 2025px; /* Increased from 1350px (50% more) */
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    border-radius: 0 0 8px 8px;
}

.editor-content::-webkit-scrollbar {
    width: 8px;
}

.editor-content::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.editor-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.editor-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    background-color: var(--bg-primary); /* White background for header */
    z-index: var(--z-editor-header);
    border-bottom: 1px solid var(--border-color);
}

.editor-header h3 {
    margin: 0;
    padding-left: 0.5rem; /* Match section-header left padding for alignment */
    font-size: 1rem; /* Same size as section headers */
    font-weight: 500; /* Not bold, same as section headers */
    color: var(--text-primary);
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Editor Sections */
.editor-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin: 0; /* Ensure no margin */
}

.editor-section:last-child {
    border-bottom: none;
}

.editor-section h4 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* Collapsible Sections */
.collapsible-section {
    position: relative;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 0.35rem 0.5rem; /* Reduced vertical padding to make rows shorter */
    margin: 0; /* Remove all margins - no negative margins */
    margin-bottom: 0.35rem; /* Only bottom margin for spacing */
    border-radius: 4px;
    transition: background-color 0.2s ease;
    user-select: none;
    min-height: auto; /* Ensure no minimum height */
    height: auto;
    line-height: 1; /* Tight line-height for the container */
    background-color: var(--bg-primary); /* White background for section headers */
}

/* Make section headers sticky for Units and Items sections */
#units-section .section-header,
#items-section .section-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky-section);
    background-color: var(--bg-primary); /* Ensure background is solid */
    margin-bottom: 0.5rem; /* Add space between header and content */
    padding-bottom: 0.5rem; /* Add padding below header */
    border: none; /* Remove any border */
}

/* Apply hover effect to all section headers */
.section-header:hover {
    background-color: var(--hover-bg) !important; /* Lighter grey on hover - use !important to override sticky background */
}

/* But don't apply hover when hovering over action button containers */
.section-header:has(.items-section-actions:hover):hover,
.section-header:has(.units-section-actions:hover):hover,
.section-header:has(.dimension-section-actions:hover):hover {
    background-color: var(--bg-primary) !important; /* Keep white background when hovering buttons */
}

.section-header-left {
    display: flex;
    align-items: center;
}

.section-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-header h4 {
    margin: 0;
    padding: 0;
    font-size: 1rem; /* Slightly smaller to differentiate from Edit Plot */
    font-weight: 500; /* Match the weight of other UI text */
    color: var(--text-primary);
    /* Match editor-header h3 exactly - no line-height override, let flex handle centering */
}

.section-toggle-icon {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    display: inline-block;
    border-radius: 1px; /* Slight rounding for smoother appearance */
}

.collapsible-section.collapsed .section-toggle-icon {
    transform: rotate(-90deg);
}

.section-content {
    overflow: visible; /* Changed from hidden to allow proper scrolling */
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 10000px;
    opacity: 1;
}

/* Make section content scrollable for Units and Items */
#units-section .section-content,
#items-section .section-content {
    max-height: 600px; /* Increased from 400px (50% more) */
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-color); /* Gray border around scrolling area */
    border-radius: 4px;
    padding: 0.75rem; /* Add some padding inside the border - increased for more space */
    padding-right: 0rem; /* Extra padding on right to account for thicker scrollbar */
    background-color: var(--bg-primary); /* White background for the scrollable area */
    scrollbar-gutter: stable; /* Reserve space for scrollbar */
    /* Align with section-header by negating editor-section padding */
    margin-left: -1.1rem;
    margin-right: -1.1rem;
    margin-top: 0; /* Ensure no top margin that could create gap */
}

/* Custom scrollbar styling for section-content to make it less intrusive */
#units-section .section-content::-webkit-scrollbar,
#items-section .section-content::-webkit-scrollbar {
    width: 18px !important; /* Wider scrollbar for better usability */
}

#units-section .section-content::-webkit-scrollbar-track,
#items-section .section-content::-webkit-scrollbar-track {
    background: transparent; /* Transparent track */
    margin: 0.25rem 0; /* Add some margin from edges */
}

#units-section .section-content::-webkit-scrollbar-thumb,
#items-section .section-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px; /* Slightly larger radius for thicker scrollbar */
    opacity: 0.5; /* Make it more subtle */
}

#units-section .section-content::-webkit-scrollbar-thumb:hover,
#items-section .section-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
    opacity: 0.8; /* Slightly more visible on hover */
}

/* Firefox scrollbar styling */
#units-section .section-content,
#items-section .section-content {
    scrollbar-width: auto; /* Use auto instead of thin for thicker scrollbar */
    scrollbar-color: var(--border-color) transparent;
}

.collapsible-section.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    overflow: hidden; /* Only hide overflow when collapsed */
}

/* Override max-height for collapsed Units and Items sections */
#units-section.collapsible-section.collapsed .section-content,
#items-section.collapsible-section.collapsed .section-content {
    max-height: 0 !important;
    overflow: hidden;
    padding: 0 !important; /* Remove padding when collapsed */
    border: none !important; /* Remove border when collapsed */
    margin: 0 !important; /* Remove margin when collapsed */
    border-radius: 0 !important; /* Remove border-radius when collapsed */
}

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

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

.editor-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.editor-input,
.editor-textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
}

.editor-input:focus,
.editor-textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.editor-textarea {
    min-height: 100px;
    resize: vertical;
}

/* Dimension Editor Card - matches unit/item card styling */
.dimension-editor-card {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    background-color: var(--bg-secondary); /* Grey background for card container */
}

.dimension-editor-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dimension-editor-form .editor-form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.dimension-input,
.dimension-textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--bg-primary); /* White background for input fields */
    color: var(--text-primary);
    font-family: inherit;
    box-sizing: border-box;
}

.dimension-textarea {
    resize: vertical;
    min-height: 60px;
}

.dimension-input:focus,
.dimension-textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Items Section */
.items-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.items-section-actions,
.units-section-actions,
.dimension-section-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Section headers can wrap to accommodate buttons */
#items-section .section-header,
#units-section .section-header,
#dimension-metadata-section .section-header {
    flex-wrap: wrap;
}

#items-section .section-header-right,
#units-section .section-header-right,
#dimension-metadata-section .section-header-right {
    flex-wrap: wrap;
}

/* Units Section */
.units-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0; /* Remove padding since section-content now has padding */
}

.unit-editor-card {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    background-color: var(--bg-secondary); /* Grey background for card container */
    transition: opacity 0.2s ease, border-color 0.2s ease;
}

.unit-editor-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.unit-editor-card:not(.dragging):hover {
    border-color: var(--accent-color);
}

.unit-editor-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.unit-editor-card-title-row {
    display: flex;
    align-items: center;
    position: relative;
    justify-content: space-between;
}

.unit-editor-card-title-row h5 {
    flex: 1;
    text-align: left;
    margin: 0;
}

.unit-editor-card-title-row .unit-drag-handle {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    flex-shrink: 0;
    z-index: var(--z-base); /* Ensure it's above other elements */
}

.unit-editor-card-title-row .btn {
    flex-shrink: 0;
    margin-left: auto; /* Push to the right */
}

.unit-drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    padding: 0.25rem;
    display: flex;
    align-items: center;
    user-select: none;
}

.unit-drag-handle:active {
    cursor: grabbing;
}

.drag-handle-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.unit-editor-card-header h5 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.unit-editor-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.unit-name-symbol-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.unit-name-group,
.unit-symbol-group {
    display: flex;
    flex-direction: column;
}

.unit-editor-form .editor-form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.unit-editor-form .editor-form-group input,
.unit-editor-form .editor-form-group textarea {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--bg-primary); /* White background for input fields */
    color: var(--text-primary);
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}

.unit-editor-form .editor-form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.unit-editor-form .editor-form-group input:focus,
.unit-editor-form .editor-form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-secondary:hover {
    background-color: var(--bg-secondary);
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0; /* Remove padding since section-content now has padding */
    padding-bottom: 1rem; /* Small padding at bottom to ensure last item is fully visible */
    flex: 1;
}

.item-editor-card {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    background-color: var(--bg-secondary); /* Grey background for card container */
}

.item-editor-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.item-editor-card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item-editor-card-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.item-editor-card-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    line-height: 1.5;
    box-sizing: border-box;
}

/* Only apply default hover to buttons that aren't primary or danger */
.btn:hover:not(.btn-primary):not(.btn-danger) {
    background-color: var(--bg-secondary);
}

.btn-danger {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
}

.btn-danger:hover {
    background-color: #c82333;
}

.item-editor-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: stretch;
}

.item-editor-form-left {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.item-editor-form-right {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
    overflow: hidden;
}

.item-editor-form-group {
    display: flex;
    flex-direction: column;
}

.item-editor-form-group.full-width {
    grid-column: 1 / -1;
}

.item-editor-form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.item-editor-form-group input,
.item-editor-form-group textarea {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--bg-primary); /* White background for input fields */
    color: var(--text-primary);
    font-family: inherit;
}

.item-editor-form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.item-editor-form-group input:focus,
.item-editor-form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.image-upload-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    height: 100%;
    min-height: 0;
}

.image-upload-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.image-upload-controls .file-input-wrapper {
    display: flex;
    align-items: center;
}

.image-upload-controls .file-input-label.btn {
    padding: 0.25rem 0.5rem;
    margin: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-width: 1px;
    border-radius: 4px;
    font-family: inherit;
    line-height: 1.5;
    box-sizing: border-box;
    height: auto;
    min-height: auto;
    display: inline-block;
    cursor: pointer;
    transition: all 0.2s ease;
    vertical-align: middle;
    text-align: center; /* Center the text in the button */
}

.image-upload-controls .file-input-label.btn:hover {
    background-color: var(--bg-secondary);
}

.image-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.image-label-row label {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.image-preview-container {
    flex: 1 1 0;
    min-height: 200px;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-primary); /* White background for images */
    overflow: hidden;
    position: relative;
}

.image-preview-container:empty::before {
    content: 'No image';
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.image-preview {
    max-width: 100%; /* Never exceed container width */
    max-height: 100%; /* Never exceed container height */
    width: auto;
    height: auto;
    object-fit: contain; /* Change from cover to contain to show full image within bounds */
    display: block;
}

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

.item-editor-card-actions .file-input-wrapper {
    display: flex;
    align-items: center;
}

.file-input-wrapper input[type=file] {
    position: absolute;
    left: -9999px;
}

.file-input-label {
    padding: 0.5rem 1rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-block;
    transition: background-color 0.2s ease;
}

.file-input-label:hover {
    background-color: var(--bg-primary);
}

/* When file-input-label is used as a button in header */
.item-editor-card-actions .file-input-label.btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    margin: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    line-height: inherit;
    box-sizing: border-box;
    height: auto;
    min-height: auto;
    display: inline-block;
    cursor: pointer;
    transition: all 0.2s ease;
}

.item-editor-card-actions .file-input-label.btn:hover {
    background-color: var(--bg-secondary);
}

/* YAML Import/Export Modal */
.yaml-modal {
    display: none;
    position: fixed;
    z-index: var(--z-modal);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.yaml-modal-content {
    background-color: var(--bg-primary);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.yaml-modal-content.drag-over {
    border: 2px dashed var(--accent-color);
    background-color: var(--bg-secondary);
}

.yaml-drop-hint {
    text-align: center;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    background-color: var(--bg-secondary);
}

.yaml-modal-content.drag-over .yaml-drop-hint {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background-color: var(--bg-primary);
}

.yaml-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.yaml-modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.yaml-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.yaml-modal-close:hover {
    color: var(--text-primary);
}

.yaml-textarea {
    width: 100%;
    min-height: 300px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    resize: vertical;
}

.yaml-modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.editor-save-all-btn {
    position: sticky;
    bottom: 0;
    width: 100%;
    padding: 1rem;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 1px solid var(--border-color);
    font-size: 1rem;
    font-weight: 600;
    z-index: var(--z-editor-save);
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.editor-save-all-btn:hover {
    background-color: #0056b3;
}

/* Main Content */
.main {
    position: relative;
}

.plot-container {
    width: 100%;
    min-height: 200px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    overflow: hidden; /* Allow labels to extend beyond container when points go off-screen */
    position: relative;
}

/* Allow SVG content to extend beyond bounds for labels */
.plot-container svg {
    overflow: visible;
}

.zoom-controls {
    position: absolute;
    bottom: 3rem;
    right: 0.75rem;
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 48px);
    grid-template-areas:
        "left right plus"
        "reset reset minus";
    gap: 0.4rem;
    z-index: var(--z-zoom-controls);
    pointer-events: auto;
}
.zoom-controls-floating {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    left: auto;
    transform: none;
    width: clamp(240px, 30vw, 360px);
    gap: 0.5rem;
    z-index: var(--z-zoom-controls-floating);
    box-shadow: var(--shadow-lg);
    border-radius: 18px;
    padding: 0.25rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.zoom-controls-floating.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.zoom-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    width: 100%;
    height: 100%;
    min-width: 48px;
    min-height: 48px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}
.zoom-btn--reset { grid-area: reset; }
.zoom-btn--plus { grid-area: plus; }
.zoom-btn--left { grid-area: left; }
.zoom-btn--right { grid-area: right; }
.zoom-btn--minus { grid-area: minus; }

[data-theme="dark"] .zoom-btn {
    background: rgba(40, 40, 45, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
}

.zoom-btn:hover,
.zoom-btn:focus-visible {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
    transform: translateY(-1px);
}

[data-theme="dark"] .zoom-btn:hover,
[data-theme="dark"] .zoom-btn:focus-visible {
    background: var(--accent-color);
    color: #fff;
}

.zoom-btn:active {
    transform: translateY(1px);
}

.zoom-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

#plot-svg .zoom-background,
.zoom-background {
    touch-action: pan-y pinch-zoom;
}

#plot-svg {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Unit Selector Below Graph */
.unit-selector-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.unit-selector-container label {
    font-weight: 500;
    color: var(--text-secondary);
}

.unit-selector-container select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.unit-selector-container select:hover {
    border-color: var(--accent-color);
}

.unit-selector-container select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Tooltip Styles */
.tooltip {
    position: absolute;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: var(--z-tooltip);
    max-width: 400px;
}

.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.tooltip-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.tooltip-image {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    display: none;
}

.tooltip-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
    font-family: inherit;
}

.tooltip-description {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.tooltip-source {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.tooltip-source:hover {
    text-decoration: underline;
}

/* Plot Elements */
.plot-item {
    cursor: pointer;
    transition: all 0.2s ease;
}

.plot-item:hover {
    transform: scale(1.2);
}

.plot-band {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.plot-band:hover {
    opacity: 0.8;
}

.item-label {
    pointer-events: none;
    font-weight: 500;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

[data-theme="dark"] .item-label {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Axes */
.axis {
    font-size: 12px;
    fill: var(--text-secondary);
}

.axis path,
.axis line {
    fill: none;
    stroke: var(--border-color);
    shape-rendering: crispEdges;
}

.axis text {
    fill: var(--text-secondary);
}

.grid-line {
    stroke: var(--border-color);
    stroke-opacity: 0.6;
    stroke-dasharray: 2,2;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: 0.5rem; /* Reduced from 1.5rem to decrease space above footer */
    border-top: none; /* Removed border line above footer */
    color: var(--text-secondary);
}

.footer p {
    margin: 0.5rem 0;
}

.footer-attribution {
    font-size: 0.9rem;
    margin-top: 1rem;
}

.footer-attribution a {
    color: var(--accent-color);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.footer-attribution a:hover {
    text-decoration: underline;
    opacity: 0.8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header h1 {
        font-size: 2rem;
    }
    
    .controls {
        flex-direction: column;
        gap: 1rem;
    }
    
    .plot-container {
        height: 500px;
    }

}

/* Loading Animation */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    color: var(--text-secondary);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Removed CSS transitions on SVG text for better performance on mobile */
/* Theme changes are handled via direct style updates in JavaScript */