/* BLDC Motor PID Controller - PC-Powered Auto-Tune
   Catppuccin Mocha Dark Theme */

:root {
    /* Catppuccin Mocha Palette */
    --ctp-rosewater: #f5e0dc;
    --ctp-flamingo: #f2cdcd;
    --ctp-pink: #f5c2e7;
    --ctp-mauve: #cba6f7;
    --ctp-red: #f38ba8;
    --ctp-maroon: #eba0ac;
    --ctp-peach: #fab387;
    --ctp-yellow: #f9e2af;
    --ctp-green: #a6e3a1;
    --ctp-teal: #94e2d5;
    --ctp-sky: #89dceb;
    --ctp-sapphire: #74c7ec;
    --ctp-blue: #89b4fa;
    --ctp-lavender: #b4befe;
    --ctp-text: #cdd6f4;
    --ctp-subtext1: #bac2de;
    --ctp-subtext0: #a6adc8;
    --ctp-overlay2: #9399b2;
    --ctp-overlay1: #7f849c;
    --ctp-overlay0: #6c7086;
    --ctp-surface2: #585b70;
    --ctp-surface1: #45475a;
    --ctp-surface0: #313244;
    --ctp-base: #1e1e2e;
    --ctp-mantle: #181825;
    --ctp-crust: #11111b;

    /* Semantic Colors */
    --bg-primary: var(--ctp-base);
    --bg-secondary: var(--ctp-mantle);
    --bg-tertiary: var(--ctp-surface0);
    --bg-accent: var(--ctp-surface1);
    --bg-hover: var(--ctp-surface2);

    --text-primary: var(--ctp-text);
    --text-secondary: var(--ctp-subtext1);
    --text-muted: var(--ctp-overlay1);

    --primary: var(--ctp-blue);
    --primary-dark: var(--ctp-sapphire);
    --success: var(--ctp-green);
    --success-dark: #7bc57b;
    --danger: var(--ctp-red);
    --danger-dark: #d87a93;
    --warning: var(--ctp-peach);
    --warning-dark: #e09a6c;

    --border-light: var(--ctp-surface0);
    --border-medium: var(--ctp-surface1);
    --border-heavy: var(--ctp-surface2);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);

    --radius: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Navigation */
.navbar {
    background: linear-gradient(180deg, var(--ctp-crust), var(--bg-secondary));
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--border-light);
    padding: 0.75rem 1rem;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--ctp-blue) !important;
    letter-spacing: -0.5px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-medium);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ctp-overlay0);
    transition: all 0.3s ease;
}

.status-text {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* System Status Bar */
.system-status {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    background: var(--bg-secondary);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.status-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 80px;
}

.status-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.status-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.status-value.highlight {
    color: var(--ctp-blue);
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-badge.stable {
    background: rgba(166, 227, 161, 0.2);
    color: var(--ctp-green);
    border: 1px solid var(--ctp-green);
}

.status-badge.settling {
    background: rgba(249, 226, 175, 0.2);
    color: var(--ctp-yellow);
    border: 1px solid var(--ctp-yellow);
}

.status-badge.hunting {
    background: rgba(243, 139, 168, 0.2);
    color: var(--ctp-red);
    border: 1px solid var(--ctp-red);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Control Panels */
.control-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.panel-header {
    background: var(--bg-tertiary);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-medium);
}

.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ctp-blue);
}

.panel-body {
    padding: 1.25rem;
}

/* Compatibility Notice */
.compatibility-notice {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-tertiary);
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border-left: 3px solid var(--ctp-blue);
}

.notice-icon {
    color: var(--ctp-blue);
    font-size: 1.5rem;
}

.notice-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.notice-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-row {
    display: flex;
    gap: 0.5rem;
}

/* Auto-Tune Button */
.btn-auto-tune {
    background: linear-gradient(135deg, var(--ctp-mauve), var(--ctp-blue));
    color: var(--ctp-crust) !important;
    font-weight: 700;
    border: none;
    transition: all 0.3s ease;
}

.btn-auto-tune:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--ctp-pink), var(--ctp-lavender));
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(137, 180, 250, 0.4);
}

.btn-auto-tune:disabled {
    background: var(--bg-accent);
    color: var(--text-muted) !important;
}

/* Progress Bar */
.progress {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    background: linear-gradient(90deg, var(--ctp-blue), var(--ctp-mauve));
}

.tune-status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Form Controls */
.control-group {
    margin-bottom: 1rem;
}

.control-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.input-with-unit {
    display: flex;
}

.input-with-unit .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.unit {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* PID Controls */
.pid-controls {
    margin: 1rem 0;
}

.gain-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.gain-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.gain-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ctp-blue);
    background: var(--bg-tertiary);
    padding: 2px 10px;
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: center;
}

.gain-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

.gain-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ctp-blue);
    border: 2px solid var(--bg-secondary);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.gain-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    background: var(--ctp-lavender);
}

/* Buttons */
.btn {
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    padding: 0.625rem 1.25rem;
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--ctp-blue);
    color: var(--ctp-crust) !important;
}

.btn-primary:hover:not(:disabled) {
    background: var(--ctp-lavender);
    box-shadow: 0 4px 12px rgba(137, 180, 250, 0.3);
}

.btn-danger {
    background: var(--ctp-red);
    color: var(--ctp-crust) !important;
}

.btn-danger:hover:not(:disabled) {
    background: var(--ctp-maroon);
    box-shadow: 0 4px 12px rgba(243, 139, 168, 0.3);
}

.btn-success {
    background: var(--ctp-green);
    color: var(--ctp-crust) !important;
}

.btn-success:hover:not(:disabled) {
    background: var(--ctp-teal);
    box-shadow: 0 4px 12px rgba(166, 227, 161, 0.3);
}

.btn-warning {
    background: var(--ctp-peach);
    color: var(--ctp-crust) !important;
}

.btn-outline-secondary {
    background: transparent;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-medium);
}

.btn-outline-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--border-heavy);
}

.btn-outline-primary {
    background: transparent;
    color: var(--ctp-blue) !important;
    border: 1px solid var(--ctp-blue);
}

.btn-outline-primary:hover:not(:disabled) {
    background: rgba(137, 180, 250, 0.1);
}

.btn-outline-light {
    background: transparent;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-medium);
}

.btn-outline-light:hover {
    background: var(--bg-tertiary);
}

.btn-lg {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

/* Form Controls */
.form-control {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius);
    padding: 0.625rem 0.875rem;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--ctp-blue);
    box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.2);
    background: var(--bg-accent);
}

/* Tuning History */
.tuning-history {
    max-height: 200px;
    overflow-y: auto;
}

.history-placeholder {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
}

.history-placeholder i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.5;
}

.history-item {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--bg-accent);
    border-color: var(--ctp-blue);
}

.history-method {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ctp-blue);
    margin-bottom: 0.25rem;
}

.history-params {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Chart Panels */
.chart-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.chart-header {
    background: var(--bg-tertiary);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-medium);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-header h3, .chart-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ctp-blue);
}

.chart-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legend-dot.target {
    background: var(--ctp-pink);
}

.legend-dot.raw {
    background: var(--ctp-sapphire);
    opacity: 0.6;
}

.legend-dot.filtered {
    background: var(--ctp-blue);
}

.chart-body {
    padding: 1rem;
    background: var(--ctp-crust);
}

.chart-body.chart-large {
    min-height: 250px;
}

.chart-body canvas {
    width: 100% !important;
}

/* Analysis Panel */
.analysis-output {
    min-height: 200px;
}

.analysis-placeholder {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.analysis-placeholder i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    display: block;
    color: var(--ctp-overlay0);
}

.analysis-section {
    margin-bottom: 1.5rem;
}

.analysis-section h5 {
    color: var(--ctp-blue);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.metric-item {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: var(--radius);
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    border-left: 3px solid;
}

.suggestion-success {
    background: rgba(166, 227, 161, 0.1);
    border-color: var(--ctp-green);
}

.suggestion-warning {
    background: rgba(250, 179, 135, 0.1);
    border-color: var(--ctp-peach);
}

.suggestion-danger {
    background: rgba(243, 139, 168, 0.1);
    border-color: var(--ctp-red);
}

.suggestion-info {
    background: rgba(137, 180, 250, 0.1);
    border-color: var(--ctp-blue);
}

.suggestion-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.suggestion-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Alerts */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border: none;
    font-weight: 500;
    font-size: 0.9rem;
}

.alert-info {
    background: rgba(137, 180, 250, 0.15);
    color: var(--ctp-blue);
    border: 1px solid var(--ctp-blue);
}

.alert-success {
    background: rgba(166, 227, 161, 0.15);
    color: var(--ctp-green);
    border: 1px solid var(--ctp-green);
}

.alert-warning {
    background: rgba(250, 179, 135, 0.15);
    color: var(--ctp-peach);
    border: 1px solid var(--ctp-peach);
}

.alert-danger {
    background: rgba(243, 139, 168, 0.15);
    color: var(--ctp-red);
    border: 1px solid var(--ctp-red);
}

/* Modal */
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
}

.modal-header {
    background: linear-gradient(135deg, var(--ctp-blue), var(--ctp-mauve));
    color: var(--ctp-crust);
    border: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.25rem 1.5rem;
}

.modal-title {
    font-weight: 700;
}

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.modal-body {
    padding: 1.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body h6 {
    color: var(--ctp-blue);
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.modal-body ul, .modal-body ol {
    padding-left: 1.25rem;
}

.modal-body li {
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.browser-requirements {
    background: var(--bg-tertiary);
    padding: 0.875rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.modal-footer {
    border-top: 1px solid var(--border-light);
    padding: 1rem 1.5rem;
}

/* Responsive */
@media (max-width: 992px) {
    .system-status {
        gap: 1rem;
    }
    
    .status-item {
        min-width: 70px;
    }
}

@media (max-width: 768px) {
    .system-status {
        flex-direction: column;
    }
    
    .chart-legend {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--ctp-surface2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--ctp-overlay0);
}

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

.small {
    font-size: 0.85rem;
}

.w-100 {
    width: 100%;
}

.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1.5rem; }
.me-1 { margin-right: 0.25rem; }
.me-2 { margin-right: 0.5rem; }
.flex-fill { flex: 1; }
