:root {
    --primary-color: #4a90e2;
    /* Bulma's link blue, good contrast */
    --bg-dark-1: #22252a;
    /* Deepest background */
    --bg-dark-2: #2a2e33;
    /* Main background */
    --bg-dark-3: #363a40;
    /* Sidebar, bars */
    --bg-dark-4: #40444a;
    /* Hover, borders */
    --text-light-1: #e0e0e0;
    /* Primary light text */
    --text-light-2: #b0b5bb;
    /* Secondary light text */
    --text-dark: #363636;
    /* For light backgrounds if needed */
    --border-color: #4a4e54;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background-color: var(--bg-dark-2);
    color: var(--text-light-1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

body {
    display: flex;
    flex-direction: column;
}

/* Layout: Left Sidebar | Center Area | Right Sidebar */
.main-layout {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    height: 100vh;
    /* Ensure full viewport height */
}

.left-sidebar {
    background-color: var(--bg-dark-3);
    padding: 1rem;
    overflow-y: auto;
    flex: 0 0 220px;
    /* Fixed width */
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.central-content-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.right-sidebar {
    background-color: var(--bg-dark-3);
    flex: 0 0 0px;
    /* Start collapsed */
    width: 0;
    overflow: hidden;
    transition: flex-basis 0.3s ease-out, width 0.3s ease-out;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.right-sidebar.is-active {
    flex-basis: 300px;
    /* Expanded width */
    width: 300px;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-dark-3);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.top-bar .title {
    color: var(--text-light-1);
    font-weight: 600;
    margin-left: auto;
    padding-right: 1rem;
}

.top-bar .action-buttons .button {
    background-color: var(--bg-dark-4);
    border-color: transparent;
    color: var(--text-light-1);
}

.top-bar .action-buttons .button:hover:not(:disabled) {
    background-color: #5a5e64;
}

.top-bar .action-buttons .button.is-link {
    background-color: var(--primary-color);
    color: white;
}

.top-bar .action-buttons .button.is-link:hover:not(:disabled) {
    background-color: #3a80d2;
}

.top-bar .action-buttons .button.is-primary {
    background-color: #3273dc;
    color: white;
}

.top-bar .action-buttons .button.is-primary:hover:not(:disabled) {
    background-color: #275eab;
}

.top-bar .action-buttons .button.is-danger {
    background-color: #cc3b3b;
    color: white;
}

.top-bar .action-buttons .button.is-danger:hover:not(:disabled) {
    background-color: #e04a4a;
}

.top-bar .action-buttons .button:disabled {
    background-color: #40444a !important;
    color: #888 !important;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Media + Canvas Area */
.media-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    overflow: hidden;
    background-color: var(--bg-dark-1);
}

#media-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.5);
    background-color: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#annotator-video,
#annotator-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

#annotator-image {
    display: none;
}

#konva-container {
    position: absolute;
    top: 0;
    left: 0;
}

#konva-container canvas {
    display: block;
}

/* Controls */
.controls-bar {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-dark-3);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 1rem;
}

.controls-bar .button {
    background-color: var(--bg-dark-4);
    border: none;
    color: var(--text-light-1);
}

.controls-bar .button:hover:not(:disabled) {
    background-color: #5a5e64;
}

.controls-bar .button:disabled {
    background-color: #40444a !important;
    color: #888 !important;
    cursor: not-allowed;
    opacity: 0.7;
}

.controls-bar #time-display {
    font-family: "SF Mono", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
    font-size: 0.9em;
    color: var(--text-light-2);
    min-width: 110px;
    text-align: center;
}

/* Custom Range Input (Playbar) */
input[type="range"].playbar {
    height: 8px;
    cursor: pointer;
    appearance: none;
    width: 100%;
    background: linear-gradient(to right, var(--primary-color) 0%, var(--primary-color) var(--progress, 0%), #555b64 var(--progress, 0%), #555b64 100%);
    border-radius: 4px;
    outline: none;
    transition: background 0.1s ease-in-out;
    flex-grow: 1;
    vertical-align: middle;
}

input[type="range"].playbar:disabled {
    background: linear-gradient(to right, #666 0%, #666 var(--progress, 0%), #4a4e54 var(--progress, 0%), #4a4e54 100%);
    cursor: not-allowed;
}

input[type="range"].playbar::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--text-light-1);
    border: 1px solid #888;
    border-radius: 50%;
    cursor: pointer;
    margin-top: -4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: background-color 0.15s ease;
}

input[type="range"].playbar:hover::-webkit-slider-thumb {
    background: white;
}

input[type="range"].playbar:disabled::-webkit-slider-thumb {
    background: #777;
    border-color: #555;
    box-shadow: none;
}

input[type="range"].playbar::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--text-light-1);
    border: 1px solid #888;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: background-color 0.15s ease;
}

input[type="range"].playbar:hover::-moz-range-thumb {
    background: white;
}

input[type="range"].playbar:disabled::-moz-range-thumb {
    background: #777;
    border-color: #555;
    box-shadow: none;
}

input[type="range"].playbar::-moz-range-track {
    background: transparent;
    border-radius: 4px;
    height: 8px;
}

input[type="range"]:focus {
    outline: none;
}

input[type="range"].playbar::-moz-focus-outer {
    border: 0;
}

/* Left Sidebar Tools */
.left-sidebar .menu {
    flex-grow: 1;
}

.left-sidebar .menu-label {
    color: var(--text-light-2);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.left-sidebar .menu-list a {
    color: var(--text-light-2);
    border-radius: 4px;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    padding: 0.6rem 0.75rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.left-sidebar .menu-list a:hover {
    background-color: var(--bg-dark-4);
    color: var(--text-light-1);
}

.left-sidebar .menu-list a.is-active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.left-sidebar .menu-list a .icon {
    margin-right: 0.75rem;
    width: 1em;
    text-align: center;
}

/* Load Media Button Style */
.load-media-label {
    color: var(--text-light-1);
    background-color: var(--bg-dark-4);
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}

.load-media-label:hover {
    background-color: #5a5e64;
    border-color: #666;
}

.load-media-label .icon {
    margin-right: 0.5rem;
}

/* Sidebar Style Controls */
.sidebar-controls {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-controls .label {
    color: var(--text-light-2);
    font-size: 0.8em;
    margin-bottom: 0.3rem;
    display: block;
}

.sidebar-controls input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    padding: 2px;
    background-color: var(--bg-dark-3);
    border-radius: 4px;
}

.sidebar-controls input[type="range"] {
    width: 100%;
    accent-color: var(--primary-color);
    vertical-align: middle;
}

.sidebar-controls .control.is-flex {
    gap: 0.5rem;
}

#annotator-width-display {
    color: var(--text-light-2);
    font-size: 0.9em;
    min-width: 25px;
    text-align: center;
    background-color: var(--bg-dark-4);
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

.left-sidebar .help {
    color: var(--text-light-2);
    opacity: 0.8;
}

/* Right Sidebar (JSON Viewer) */
.right-sidebar .json-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.json-viewer-header {
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-dark-4);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.json-viewer-header:hover {
    background-color: #5a5e64;
}

.json-viewer-header h3 {
    color: var(--text-light-1);
    font-size: 0.9em;
    font-weight: 600;
    margin-bottom: 0;
}

.json-viewer-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background-color: var(--bg-dark-3);
}

.json-viewer textarea {
    background-color: var(--bg-dark-1);
    color: var(--text-light-2);
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-family: monospace;
    resize: none;
    box-shadow: none;
    width: 100%;
    height: 100%;
    display: block;
}

.json-viewer textarea:focus {
    border-color: var(--primary-color);
    box-shadow: none;
    outline: none;
}

#json-toggle-icon {
    transition: transform 0.3s ease;
    color: var(--text-light-2);
}

.right-sidebar:not(.is-active) #json-toggle-icon {
    transform: rotate(-90deg);
}

/* Point left when collapsed */
.right-sidebar.is-active #json-toggle-icon {
    transform: rotate(0deg);
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(42, 46, 51, 0.85);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 1rem;
    color: var(--text-light-1);
}

#loading-overlay.is-hidden {
    display: none;
}

.spinner {
    border: 4px solid #555;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Preview Modal */
.modal-card {
    background-color: var(--bg-dark-3);
    color: var(--text-light-1);
    max-width: 90vw;
    width: auto;
    border-radius: 6px;
}

.modal-card-head,
.modal-card-foot {
    background-color: var(--bg-dark-4);
    border-color: var(--border-color);
    border-radius: 6px 6px 0 0;
}

.modal-card-foot {
    border-radius: 0 0 6px 6px;
}

.modal-card-title {
    color: var(--text-light-1);
    font-weight: 600;
}

.modal-card-body {
    background-color: var(--bg-dark-2);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 60vh;
    padding: 1.5rem;
}

.modal-card-body #preview-media-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 80vh;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background-color: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-card-body #preview-video {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.modal-card-body #preview-konva-container {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.modal-card-body #preview-konva-container canvas {
    display: block;
}

.modal-card-foot .button {
    background-color: var(--bg-dark-4);
    border-color: transparent;
    color: var(--text-light-1);
}

.modal-card-foot .button:hover {
    background-color: #5a5e64;
}