/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* QBitwise Color Palette - Extracted from icon */
    --primary-color: #70BBC2;      /* Teal/Turquoise - Main brand color */
    --primary-dark: #347698;       /* Deep blue - Accents */
    --primary-light: #93C6EA;      /* Light blue - Highlights */
    --primary-lighter: #BDDCE3;    /* Very light blue - Backgrounds */
    --success-color: #52B788;      /* Green - Success states */
    --danger-color: #E76F51;       /* Coral red - Errors */
    --warning-color: #F4A261;      /* Orange - Warnings */
    --bg-color: #F5F8FA;           /* Light gray-blue background */
    --card-bg: #FFFFFF;            /* White cards */
    --text-primary: #253B4B;       /* Dark blue-gray - Main text */
    --text-secondary: #5F7A8A;     /* Medium gray-blue - Secondary text */
    --border-color: #BDDCE3;       /* Light blue border */
    --shadow: 0 2px 8px rgba(52, 118, 152, 0.1);
    --shadow-hover: 0 4px 16px rgba(52, 118, 152, 0.15);
}

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

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

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-radius: 12px;
    color: white;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
    animation: headerShine 10s linear infinite;
}

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

.header-branding {
    position: relative;
    z-index: 1;
}

.logo-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 12px;
}

.header-logo {
    width: 48px;
    height: 48px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

header h1 {
    font-size: 2.8rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.subtitle {
    font-size: 1.15rem;
    opacity: 0.95;
    font-weight: 400;
    max-width: 700px;
    margin: 0 auto;
    line-height: 1.5;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

.card h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 1.5rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--border-color);
}

.tab-button {
    background: none;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    font-weight: 500;
}

.tab-button:hover {
    color: var(--primary-color);
    background: rgba(112, 187, 194, 0.05);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Input Groups */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.text-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* File Upload */
.file-label {
    display: inline-block;
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s ease;
    font-weight: 500;
}

.file-label:hover {
    background: var(--primary-dark);
}

.file-label input[type="file"] {
    display: none;
}

.file-name {
    display: inline-block;
    margin-left: 15px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(112, 187, 194, 0.3);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #40916C;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(82, 183, 136, 0.3);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #D8315B;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 71, 111, 0.3);
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Spinner */
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid white;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
}

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

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 8px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: pulse 2s infinite;
}

.status-indicator.connected .status-dot {
    background: var(--success-color);
}

.status-indicator.error .status-dot {
    background: var(--danger-color);
}

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

/* Display Section */
.display-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.display-info {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.canvas-container {
    position: relative;
    background: #F8F9FA;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#detection-canvas {
    max-width: 100%;
    height: auto;
    display: none;
}

#detection-canvas.visible {
    display: block;
}

.canvas-placeholder {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

.canvas-placeholder p:first-child {
    font-size: 4rem;
    margin-bottom: 10px;
}

/* Results Section */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.bbox-toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.image-description {
    background: linear-gradient(135deg, rgba(112, 187, 194, 0.1) 0%, rgba(147, 198, 234, 0.1) 100%);
    border-left: 4px solid var(--primary-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
    display: flex;
    gap: 15px;
    align-items: flex-start;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.description-icon {
    font-size: 2rem;
    flex-shrink: 0;
    line-height: 1;
}

.description-text {
    flex: 1;
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text-primary);
    margin: 0;
}

.no-results {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-style: italic;
}

#results-table {
    width: 100%;
    border-collapse: collapse;
}

#results-table th,
#results-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#results-table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-primary);
}

#results-table tbody tr:hover {
    background: rgba(112, 187, 194, 0.05);
}

.confidence-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.confidence-high {
    background: #D4EDDA;
    color: #155724;
}

.confidence-medium {
    background: #FFF3CD;
    color: #856404;
}

.confidence-low {
    background: #F8D7DA;
    color: #721C24;
}

.bbox-coords {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Status Messages */
#status-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
}

.status-message {
    background: var(--card-bg);
    padding: 16px 20px;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-hover);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.status-message.success {
    border-left: 4px solid var(--success-color);
}

.status-message.error {
    border-left: 4px solid var(--danger-color);
}

.status-message.info {
    border-left: 4px solid var(--primary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        padding: 30px 15px;
    }

    .logo-title {
        gap: 10px;
    }

    .header-logo {
        width: 36px;
        height: 36px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .image-description {
        padding: 15px;
        gap: 10px;
    }

    .description-icon {
        font-size: 1.5rem;
    }

    .description-text {
        font-size: 1rem;
    }

    .tabs {
        flex-direction: column;
        gap: 5px;
    }

    .tab-button {
        border-bottom: none;
        border-left: 3px solid transparent;
    }

    .tab-button.active {
        border-bottom: none;
        border-left-color: var(--primary-color);
        background: rgba(112, 187, 194, 0.05);
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .display-header {
        flex-direction: column;
        align-items: flex-start;
    }

    #status-messages {
        left: 20px;
        right: 20px;
        max-width: none;
    }
}

/* Main Content Layout */
.main-content {
    display: grid;
    gap: 20px;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 2fr;
        grid-template-rows: auto auto;
    }

    .input-section {
        grid-column: 1;
        grid-row: 1 / 3;
    }

    .display-section {
        grid-column: 2;
        grid-row: 1;
    }

    .results-section {
        grid-column: 2;
        grid-row: 2;
    }
}

/* Local Video Tab Styles */
.video-preview-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 1rem auto;
    background: var(--bg-color);
    border-radius: 8px;
    overflow: hidden;
    display: none; /* Hidden until video loaded */
}

.video-preview-container.visible {
    display: block;
}

#local-video-preview {
    width: 100%;
    height: auto;
    display: block;
}

.number-input {
    width: 100px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    text-align: center;
}

.video-progress {
    margin: 1rem 0;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary-color);
    transition: width 0.1s linear;
}

.progress-info {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* Processing Mode Toggle */
.processing-mode-group {
    margin-bottom: 1.5rem;
}

.mode-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.mode-toggle {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.radio-label:hover {
    border-color: var(--primary-color);
    background: rgba(112, 187, 194, 0.05);
}

.radio-label input[type="radio"] {
    accent-color: var(--primary-color);
}

.radio-label input[type="radio"]:checked + span {
    color: var(--primary-color);
    font-weight: 500;
}

/* Video Info Panel */
.video-info-panel {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.video-info-item {
    display: flex;
    gap: 0.5rem;
}

.info-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.video-info-item span:last-child {
    font-weight: 500;
    color: var(--text-primary);
}
