/* Theme System - Light and Dark Mode */

:root {
    /* Light theme colors */
    --light-bg-primary: #f4f7fa;
    --light-bg-secondary: #ffffff;
    --light-bg-tertiary: #f8f9fa;
    --light-text-primary: #333333;
    --light-text-secondary: #666666;
    --light-text-muted: #999999;
    --light-border: #cccccc;
    --light-header-bg: rgba(10, 22, 40, 0.95);
    --light-header-text: #ffffff;
    --light-sidebar-bg: #ffffff;
    --light-sidebar-border: #e0e0e0;

    /* Dark theme colors */
    --dark-bg-primary: #1a1a1a;
    --dark-bg-secondary: #2a2a2a;
    --dark-bg-tertiary: #333333;
    --dark-text-primary: #ffffff;
    --dark-text-secondary: #d0d0d0;
    --dark-text-muted: #aaaaaa;
    --dark-border: #444444;
    --dark-header-bg: rgba(7, 16, 31, 0.97);
    --dark-header-text: #ffffff;
    --dark-sidebar-bg: #2a2a2a;
    --dark-sidebar-border: #444444;

    /* Accent colors (same for both themes) */
    --accent-primary: #28a745;
    --accent-secondary: #007bff;
    --accent-danger: #dc3545;
    --accent-warning: #ffc107;
    --accent-info: #17a2b8;
    --accent-success: #10b981;

    /* Set default to light theme */
    --bg-primary: var(--light-bg-primary);
    --bg-secondary: var(--light-bg-secondary);
    --bg-tertiary: var(--light-bg-tertiary);
    --text-primary: var(--light-text-primary);
    --text-secondary: var(--light-text-secondary);
    --text-muted: var(--light-text-muted);
    --border-color: var(--light-border);
    --header-bg: var(--light-header-bg);
    --header-text: var(--light-header-text);
    --sidebar-bg: var(--light-sidebar-bg);
    --sidebar-border: var(--light-sidebar-border);
}

/* Dark theme variables */
html[data-theme="dark"],
html[data-bs-theme="dark"] {
    --bg-primary: var(--dark-bg-primary);
    --bg-secondary: var(--dark-bg-secondary);
    --bg-tertiary: var(--dark-bg-tertiary);
    --text-primary: var(--dark-text-primary);
    --text-secondary: var(--dark-text-secondary);
    --text-muted: var(--dark-text-muted);
    --border-color: var(--dark-border);
    --header-bg: var(--dark-header-bg);
    --header-text: var(--dark-header-text);
    --sidebar-bg: var(--dark-sidebar-bg);
    --sidebar-border: var(--dark-sidebar-border);
}

/* Apply theme to body */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Update header colors */
.header {
    background: var(--header-bg) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    color: var(--header-text) !important;
}

.header .nav a {
    color: rgba(255, 255, 255, 0.75) !important;
}

.header .nav a:hover {
    color: #60d0ff !important;
}

/* Theme toggle button always adapts to the dark navbar */
.header .theme-toggle-btn {
    background: rgba(255, 255, 255, 0.08) !important;
    color: rgba(255, 255, 255, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
}

.header .theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.16) !important;
    color: #ffffff !important;
    transform: none !important;
}

/* Sidebar colors */
.sidebar {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--sidebar-border) !important;
    color: var(--text-primary) !important;
}

/* General text and background updates */
.container {
    color: var(--text-primary);
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
}

/* Form elements */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

input[type="text"]::placeholder,
input[type="email"]::placeholder,
input[type="password"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder {
    color: var(--text-muted) !important;
}

/* Buttons */
.btn-outline-secondary {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.btn-outline-secondary:hover {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

/* Accordion styling */
.accordion-item,
.list-group-item,
.card {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.accordion-button {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.accordion-button:not(.collapsed) {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

.accordion-collapse {
    background-color: var(--bg-secondary) !important;
}

.accordion-body {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Fix accordion arrow/chevron visibility in dark mode */
html[data-theme="dark"] .accordion-button::after,
html[data-bs-theme="dark"] .accordion-button::after {
    filter: brightness(1.5) invert(0.8);
}

/* Text colors */
.text-muted {
    color: var(--text-secondary) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

small {
    color: var(--text-secondary) !important;
}

/* Light mode specific: muted text should be lighter gray */
html[data-theme="light"] .text-muted,
html[data-bs-theme="light"] .text-muted,
html[data-theme="light"] small.text-muted,
html[data-bs-theme="light"] small.text-muted,
html[data-theme="light"] div.text-muted,
html[data-bs-theme="light"] div.text-muted {
    color: #666666 !important;
}

/* Dark mode specific: muted text should be light gray */
html[data-theme="dark"] .text-muted,
html[data-bs-theme="dark"] .text-muted,
html[data-theme="dark"] small.text-muted,
html[data-bs-theme="dark"] small.text-muted,
html[data-theme="dark"] div.text-muted,
html[data-bs-theme="dark"] div.text-muted {
    color: #e0e0e0 !important;
}

/* Dropdown menus */
.dropdown-menu {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.dropdown-item {
    color: var(--text-primary) !important;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

/* Modals */
.modal-content {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.modal-header {
    border-color: var(--border-color) !important;
}

.modal-footer {
    border-color: var(--border-color) !important;
}

/* Borders */
.vr {
    border-color: var(--border-color) !important;
    opacity: 0.5;
}

.border {
    border-color: var(--border-color) !important;
}

/* Tables */
table {
    color: var(--text-primary);
}

thead {
    background-color: var(--bg-tertiary);
}

tbody tr {
    border-color: var(--border-color) !important;
}

tbody tr:hover {
    background-color: var(--bg-tertiary);
}

/* Badges */
.badge {
    background-color: var(--accent-secondary) !important;
}

/* Code blocks */
code,
pre {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Alerts */
.alert {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Breadcrumbs */
.breadcrumb {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.breadcrumb-item {
    color: var(--text-primary) !important;
}

.breadcrumb-item.active {
    color: var(--text-muted) !important;
}

/* Range sliders */
input[type="range"] {
    background: var(--border-color) !important;
}

input[type="range"]::-webkit-slider-thumb {
    background: var(--accent-primary) !important;
}

input[type="range"]::-moz-range-thumb {
    background: var(--accent-primary) !important;
}

/* Color picker */
input[type="color"] {
    border-color: var(--border-color) !important;
    background-color: var(--bg-secondary) !important;
}

/* Checkboxes and radio buttons */
input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--accent-primary);
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle-btn.icon-only {
    padding: 0.5rem;
    min-width: 2.5rem;
    justify-content: center;
}

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

/* Image detail specific styling */
html[data-theme="dark"] .page-header,
html[data-bs-theme="dark"] .page-header {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
}

html[data-theme="light"] .page-header,
html[data-bs-theme="light"] .page-header {
    background: linear-gradient(135deg, #003087 0%, #0052cc 100%);
}

html[data-theme="dark"] .sidebar,
html[data-bs-theme="dark"] .sidebar {
    background: #2a2a2a;
    border-right: 1px solid #444;
}

html[data-theme="light"] .sidebar,
html[data-bs-theme="light"] .sidebar {
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
}

html[data-theme="dark"] .control-section h3,
html[data-bs-theme="dark"] .control-section h3 {
    color: #10b981;
}

html[data-theme="light"] .control-section h3,
html[data-bs-theme="light"] .control-section h3 {
    color: #003087;
}

html[data-theme="dark"] .file-selector select,
html[data-bs-theme="dark"] .file-selector select {
    background: #1a1a1a;
    color: white;
    border: 1px solid #444;
}

html[data-theme="light"] .file-selector select,
html[data-bs-theme="light"] .file-selector select {
    background: white;
    color: #333;
    border: 1px solid #ccc;
}

html[data-theme="dark"] .overlay-item,
html[data-bs-theme="dark"] .overlay-item {
    background: #1a1a1a;
    border: 1px solid #444;
}

html[data-theme="light"] .overlay-item,
html[data-bs-theme="light"] .overlay-item {
    background: #f8f9fa;
    border: 1px solid #ddd;
}

html[data-theme="dark"] .rename-btn,
html[data-bs-theme="dark"] .rename-btn {
    color: #aaa;
}

html[data-theme="dark"] .rename-btn:hover,
html[data-bs-theme="dark"] .rename-btn:hover {
    color: #10b981;
}

html[data-theme="light"] .rename-btn,
html[data-bs-theme="light"] .rename-btn {
    color: #666;
}

html[data-theme="light"] .rename-btn:hover,
html[data-bs-theme="light"] .rename-btn:hover {
    color: #003087;
}

html[data-theme="dark"] .colormap-btn,
html[data-bs-theme="dark"] .colormap-btn {
    background: #1a1a1a;
    color: white;
    border: 1px solid #444;
}

html[data-theme="light"] .colormap-btn,
html[data-bs-theme="light"] .colormap-btn {
    background: #ffffff;
    color: #333;
    border: 1px solid #ccc;
}

/* Control Panel Styling */
.control-panel-top {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1rem;
}

/* Bootstrap utility classes theming */
.bg-light {
    background-color: var(--bg-secondary) !important;
}

html[data-theme="light"] .bg-light,
html[data-bs-theme="light"] .bg-light {
    background-color: #f8f9fa !important;
}

html[data-theme="dark"] .bg-light,
html[data-bs-theme="dark"] .bg-light {
    background-color: var(--bg-secondary) !important;
}

.card-footer {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Edit contour and other panel controls */
.control-panel-top {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.viewer-controls {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.editor-layout {
    background-color: var(--bg-primary) !important;
}

.viewer-panel {
    background-color: var(--bg-primary) !important;
}

.dvh-panel {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.slice-controls {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.controls-row {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

.window-controls {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

/* DVH container and panels */
#dvh-container {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.dvh-legend {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

#dvh-legend {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Control sections */
.control-section {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.control-label {
    color: var(--text-primary) !important;
}

/* Feature items in light theme */
html[data-theme="light"] .feature-item,
html[data-bs-theme="light"] .feature-item {
    background-color: #f8f9fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

html[data-theme="dark"] .feature-item,
html[data-bs-theme="dark"] .feature-item {
    background-color: var(--bg-tertiary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Main content area background */
main {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Footer styling if present */
footer {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
}

/* Help text cards */
.card-header {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.card-body {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Keyboard styling */
kbd {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Range input styling */
input[type="range"] {
    background: var(--border-color) !important;
}

input[type="range"]::-webkit-slider-thumb {
    background: var(--accent-success) !important;
}

input[type="range"]::-moz-range-thumb {
    background: var(--accent-success) !important;
}

input[type="range"]::-moz-range-track {
    background: transparent;
    border: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    background: var(--border-color) !important;
}

/* Smooth transitions */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}