/* CSS Variables for theming */
:root {
    /* Light theme (default) */
    --bg-primary: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
    --bg-header: rgba(255, 255, 255, 0.85);
    --bg-panel: rgba(255, 255, 255, 0.7);
    --bg-canvas: rgba(255, 255, 255, 0.6);
    --bg-upload: rgba(255, 255, 255, 0.5);
    --bg-input: rgba(255, 255, 255, 0.8);
    --bg-annotation: rgba(255, 255, 255, 0.8);
    --bg-custom-color: rgba(255, 255, 255, 0.8);
    --bg-instructions: rgba(26, 115, 232, 0.08);
    
    --text-primary: #3c4043;
    --text-secondary: #5f6368;
    --text-muted: #80868b;
    --text-placeholder: #9aa0a6;
    --text-accent: #1a73e8;
    --text-title: #1a73e8;
    
    --border-primary: rgba(224, 224, 224, 0.8);
    --border-secondary: rgba(224, 224, 224, 0.5);
    --border-focus: rgba(26, 115, 232, 0.6);
    --border-active: rgba(26, 115, 232, 0.8);
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.1);
    
    --btn-primary-bg: rgba(26, 115, 232, 0.9);
    --btn-primary-hover: rgba(25, 105, 220, 0.95);
    --btn-secondary-bg: rgba(255, 255, 255, 0.9);
    --btn-secondary-text: #5f6368;
    --btn-secondary-border: rgba(224, 224, 224, 0.8);
    
    --upload-border: rgba(26, 115, 232, 0.3);
    --upload-border-hover: rgba(26, 115, 232, 0.6);
    --upload-bg-hover: rgba(26, 115, 232, 0.05);
    
    --scrollbar: rgba(154, 160, 166, 0.4);
    --scrollbar-hover: rgba(154, 160, 166, 0.6);
}

/* Dark Theme - GitHub Style */
[data-theme="dark"] {
  /* Background Colors */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --bg-active: rgba(56, 139, 253, 0.15);
  --bg-overlay: rgba(0, 0, 0, 0.7);
  --bg-tooltip: #484f58;

  /* Text Colors */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --text-inverse: #0d1117;
  --text-link: #58a6ff;
  --text-error: #f85149;
  --text-success: #3fb950;
  --text-warning: #d29922;

  /* Border Colors */
  --border-primary: #30363d;
  --border-secondary: #21262d;
  --border-focus: #58a6ff;

  /* Accent Colors */
  --accent-primary: #58a6ff;
  --accent-primary-hover: #79c0ff;
  --accent-primary-light: rgba(56, 139, 253, 0.15);
  --accent-secondary: #8b949e;
  --accent-danger: #f85149;
  --accent-danger-hover: #ff7b72;
  --accent-success: #3fb950;
  --accent-warning: #d29922;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.6);

  /* Code Block */
  --code-bg: #161b22;
  --code-text: #e6edf3;
  --code-border: #30363d;

  /* Scrollbar */
  --scrollbar-track: transparent;
  --scrollbar-thumb: #30363d;
  --scrollbar-thumb-hover: #484f58;

  /* Status Colors */
  --status-online: #3fb950;
  --status-offline: #8b949e;
  --status-busy: #d29922;

  /* Input */
  --input-bg: #0d1117;
  --input-border: #30363d;
  --input-focus-border: #58a6ff;
  --input-focus-shadow: 0 0 0 2px rgba(56, 139, 253, 0.2);

  /* Button */
  --btn-primary-bg: #238636;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #2ea043;
  --btn-secondary-bg: #21262d;
  --btn-secondary-text: #e6edf3;
  --btn-secondary-hover: #30363d;
  --btn-secondary-border: #30363d;
  --btn-danger-bg: #da3633;
  --btn-danger-text: #ffffff;
  --btn-danger-hover: #f85149;

  /* Message Bubbles */
  --msg-user-bg: #238636;
  --msg-user-text: #ffffff;
  --msg-assistant-bg: #161b22;
  --msg-assistant-text: #e6edf3;
  --msg-system-bg: #341a00;
  --msg-system-text: #d29922;

  /* Syntax Highlighting (Dark) */
  --syntax-keyword: #ff7b72;
  --syntax-string: #a5d6ff;
  --syntax-comment: #8b949e;
  --syntax-function: #d2a8ff;
  --syntax-number: #79c0ff;
  --syntax-operator: #ff7b72;

  /* Extended Colors - Dark Theme */
  --text-muted: #8b949e;
  --text-muted-light: #6e7681;
  --text-muted-dark: #8b949e;
  --text-disabled: #484f58;
  --text-code: #a5d6ff;

  /* Background Extended - Dark */
  --bg-code: #0d1117;
  --bg-panel: #161b22;
  --bg-badge-success: rgba(46, 160, 67, 0.15);
  --bg-badge-warning: rgba(210, 153, 34, 0.15);
  --bg-badge-danger: rgba(248, 81, 73, 0.15);
  --bg-badge-info: rgba(56, 139, 253, 0.15);

  /* Border Extended - Dark */
  --border-panel: #21262d;
  --border-dashed: #30363d;

  /* Status Extended - Dark */
  --status-success-bright: #3fb950;
  --status-danger-bright: #f85149;
  --status-warning-bright: #d29922;
  --status-info: #a5d6ff;
  --status-success-text: #3fb950;
  --status-warning-text: #d29922;

  /* Gray Scale - Dark */
  --gray-100: #21262d;
  --gray-200: #30363d;
  --gray-300: #484f58;
  --gray-400: #6e7681;
  --gray-500: #8b949e;
  --gray-600: #8b949e;
  --gray-700: #e6edf3;
  --gray-800: #e6edf3;
  --gray-900: #e6edf3;

  /* Legacy Variable Mapping for Compatibility */
  --bg-header: #161b22;
  --bg-canvas: #0d1117;
  --bg-upload: #21262d;
  --bg-input: #0d1117;
  --bg-annotation: #21262d;
  --bg-custom-color: #21262d;
  --bg-instructions: rgba(56, 139, 253, 0.08);
  
  --text-accent: #58a6ff;
  --text-title: #e6edf3;
  
  --border-active: #58a6ff;
  --border-focus: #58a6ff;
  
  --upload-border: #30363d;
  --upload-border-hover: #58a6ff;
  --upload-bg-hover: rgba(88, 166, 255, 0.05);
  
  --scrollbar: #30363d;
  --scrollbar-hover: #484f58;
  
  /* Button Legacy Mapping */
  --btn-primary-bg: #238636;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #2ea043;
  --btn-secondary-bg: #21262d;
  --btn-secondary-text: #e6edf3;
  --btn-secondary-hover: #30363d;
  --btn-secondary-border: #30363d;
}

/* Scrollbar Styles - Dark Theme */
[data-theme="dark"] ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Selection - Dark Theme */
[data-theme="dark"] ::selection {
  background: var(--accent-primary-light);
  color: var(--text-primary);
}

/* Focus Visible - Dark Theme */
[data-theme="dark"] :focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.header {
    height: 56px;
    background: var(--bg-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-secondary);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.header h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-title);
    letter-spacing: 0.3px;
    transition: color 0.3s ease;
}

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text, white);
    box-shadow: 0 2px 8px rgba(26, 115, 232, 0.25);
    transition: all 0.2s ease;
}

[data-theme="dark"] .btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(35, 134, 54, 0.3);
}

.btn-primary:hover {
    background: var(--btn-primary-hover);
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.35);
}

[data-theme="dark"] .btn-primary:hover {
    background: var(--btn-primary-hover);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(46, 160, 67, 0.4);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border: 1px solid var(--btn-secondary-border);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

[data-theme="dark"] .btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border-color: var(--btn-secondary-border);
}

.btn-secondary:hover {
    background: var(--btn-secondary-hover, var(--bg-input));
    border-color: var(--border-focus);
    color: var(--text-accent);
}

[data-theme="dark"] .btn-secondary:hover {
    background: var(--btn-secondary-hover);
    border-color: var(--border-focus);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.theme-toggle {
    padding: 10px;
    min-width: 40px;
}

.main-container {
    display: flex;
    height: calc(100vh - 56px);
    padding: 16px;
    gap: 16px;
}

.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-canvas);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-secondary);
    transition: all 0.3s ease;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-xl);
    border-radius: 8px;
    overflow: hidden;
}

#canvas {
    display: block;
    cursor: crosshair;
    background: transparent;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.panel {
    padding: 16px;
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-secondary);
    transition: all 0.3s ease;
}

.panel-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    transition: color 0.3s ease;
}

.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
}

.mode-btn {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-primary);
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.mode-btn.active {
    border-color: var(--border-active);
    background: rgba(26, 115, 232, 0.1);
    color: var(--text-accent);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

[data-theme="dark"] .mode-btn.active {
    background: rgba(88, 166, 255, 0.12);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
    border-color: #58a6ff;
}

.mode-btn:hover:not(.active) {
    background: var(--bg-panel);
    border-color: var(--border-focus);
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-secondary);
    transition: all 0.3s ease;
}

.annotation-item {
    background: var(--bg-annotation);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-primary);
}

.annotation-item:hover {
    background: var(--bg-input);
    border-color: var(--border-focus);
    box-shadow: var(--shadow-md);
}

.annotation-item.active {
    border-color: var(--border-active);
    background: rgba(26, 115, 232, 0.08);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

[data-theme="dark"] .annotation-item.active {
    background: rgba(88, 166, 255, 0.08);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.25);
    border-color: rgba(88, 166, 255, 0.5);
}

.annotation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.annotation-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.annotation-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s ease;
}

.icon-btn:hover {
    background: rgba(95, 99, 104, 0.1);
    color: var(--text-primary);
}

.icon-btn.delete:hover {
    background: rgba(217, 48, 37, 0.1);
    color: #d93025;
}

.annotation-info {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    font-family: 'Roboto Mono', 'Consolas', monospace;
    transition: color 0.3s ease;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-placeholder);
    transition: color 0.3s ease;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.upload-area {
    border: 2px dashed var(--upload-border);
    border-radius: 16px;
    width: 320px;
    height: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-upload);
}

.upload-area:hover {
    border-color: var(--upload-border-hover);
    background: var(--upload-bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(26, 115, 232, 0.1);
}

[data-theme="dark"] .upload-area:hover {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(88, 166, 255, 0.3);
}

.upload-area.has-image {
    display: none;
}

.upload-icon {
    font-size: 56px;
    margin-bottom: 16px;
    color: var(--text-accent);
    opacity: 0.5;
    transition: color 0.3s ease;
}

.upload-text {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    transition: color 0.3s ease;
}

#fileInput {
    display: none;
}

.properties-panel {
    padding: 0;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
    transition: color 0.3s ease;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-primary);
    background: var(--bg-input);
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 13px;
    transition: all 0.2s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
    background: var(--bg-input);
}

[data-theme="dark"] .form-input:focus {
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.25);
}

.form-input::placeholder {
    color: var(--text-placeholder);
}

.coordinates-display {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-primary);
    font-family: 'Roboto Mono', 'Consolas', monospace;
    transition: color 0.3s ease;
}

.coord-value {
    color: var(--text-accent);
    font-weight: 600;
    transition: color 0.3s ease;
}

.instructions {
    background: var(--bg-instructions);
    border-left: 3px solid var(--text-accent);
    padding: 12px 16px;
    margin: 0;
    border-radius: 0 10px 10px 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.instructions strong {
    color: var(--text-accent);
    font-weight: 600;
    transition: color 0.3s ease;
}

.color-picker {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.color-option:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.color-option.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--text-accent), 0 4px 8px rgba(0, 0, 0, 0.15);
}

.color-option.custom-color {
    background: var(--bg-custom-color);
    border: 1px dashed var(--text-secondary);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.color-option.custom-color:hover {
    background: var(--bg-instructions);
    border-color: var(--text-accent);
    color: var(--text-accent);
}

.custom-color-panel {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-panel);
    border-radius: 10px;
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

.color-picker-input {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 10px;
}

.custom-color-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

.stats {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-value {
    color: var(--text-accent);
    font-weight: 600;
    transition: color 0.3s ease;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .panel, .annotation-list {
        flex: 1;
        min-width: 280px;
    }
    
    .annotation-list {
        max-height: 300px;
    }
}
