/* ===== CSS Variables ===== */
:root {
    --primary: #0078d4;
    --primary-dark: #106ebe;
    --primary-light: #deecf9;
    --secondary: #5c2d91;
    --success: #107c10;
    --warning: #ff8c00;
    --danger: #d13438;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --gray-900: #171717;
    --sidebar-width: 260px;
    --header-height: 70px;
    --border-radius: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.6;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px;
    border-bottom: 1px solid var(--gray-200);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
}

.logo span {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--gray-600);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    font-size: 0.875rem;
    color: var(--gray-600);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(16, 124, 16, 0.2);
}

.status-indicator.disconnected {
    background: var(--gray-400);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
}

.section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    margin-bottom: 32px;
}

.section-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 8px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.section-header p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon svg {
    width: 28px;
    height: 28px;
    color: white;
}

.stat-icon.blue { background: linear-gradient(135deg, #0078d4, #00bcf2); }
.stat-icon.green { background: linear-gradient(135deg, #107c10, #00b294); }
.stat-icon.purple { background: linear-gradient(135deg, #5c2d91, #b4a0ff); }
.stat-icon.orange { background: linear-gradient(135deg, #ff8c00, #ffb900); }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-800);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* ===== Quick Actions ===== */
.quick-actions {
    background: white;
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
}

.quick-actions h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--gray-800);
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
    background: var(--gray-50);
    border: 2px solid var(--gray-200);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-700);
}

.action-card:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-2px);
}

.action-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

/* ===== Analyze Section ===== */
.analyze-container {
    background: white;
    border-radius: var(--border-radius);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius);
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 32px;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-area.has-file {
    border-color: var(--success);
    background: rgba(16, 124, 16, 0.05);
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.upload-area h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.upload-area p {
    color: var(--gray-500);
    margin-bottom: 8px;
}

.file-types {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.file-name {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    padding: 12px 20px;
    background: rgba(16, 124, 16, 0.1);
    border-radius: 8px;
    color: var(--success);
    font-weight: 500;
}

/* ===== Model Selection ===== */
.model-selection {
    margin-bottom: 32px;
}

.model-selection h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 16px;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.model-option {
    cursor: pointer;
}

.model-option input {
    display: none;
}

.model-card {
    padding: 16px;
    border: 2px solid var(--gray-200);
    border-radius: 10px;
    text-align: center;
    transition: var(--transition);
}

.model-option input:checked + .model-card {
    border-color: var(--primary);
    background: var(--primary-light);
}

.model-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.model-name {
    display: block;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.model-desc {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ===== Analyze Button ===== */
.analyze-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.analyze-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.analyze-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.analyze-btn svg {
    width: 20px;
    height: 20px;
}

/* ===== Results Area ===== */
.results-area {
    background: white;
    border-radius: var(--border-radius);
    padding: 24px;
    margin-top: 24px;
    box-shadow: var(--shadow-md);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.results-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.export-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.export-btn:hover {
    background: var(--gray-200);
}

.export-btn svg {
    width: 18px;
    height: 18px;
}

.results-content {
    max-height: 500px;
    overflow-y: auto;
}

.result-section {
    margin-bottom: 24px;
}

.result-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.result-text {
    background: var(--gray-50);
    border-radius: 8px;
    padding: 16px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.result-table th, .result-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.result-table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
}

.result-table td {
    font-size: 0.875rem;
}

.confidence-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.confidence-badge.high {
    background: rgba(16, 124, 16, 0.1);
    color: var(--success);
}

.confidence-badge.medium {
    background: rgba(255, 140, 0, 0.1);
    color: var(--warning);
}

.confidence-badge.low {
    background: rgba(209, 52, 56, 0.1);
    color: var(--danger);
}

/* ===== History Section ===== */
.history-controls {
    margin-bottom: 20px;
}

.clear-history-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.clear-history-btn:hover {
    background: var(--danger);
    color: white;
}

.clear-history-btn svg {
    width: 18px;
    height: 18px;
}

.history-list {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.empty-state {
    padding: 64px;
    text-align: center;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-100);
    transition: var(--transition);
}

.history-item:hover {
    background: var(--gray-50);
}

.history-item:last-child {
    border-bottom: none;
}

.history-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.history-icon {
    width: 44px;
    height: 44px;
    background: var(--primary-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.history-details h4 {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.history-details span {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.history-actions {
    display: flex;
    gap: 8px;
}

.history-btn {
    padding: 8px 12px;
    background: var(--gray-100);
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.history-btn:hover {
    background: var(--gray-200);
}

.history-btn.view {
    background: var(--primary-light);
    color: var(--primary);
}

.history-btn.view:hover {
    background: var(--primary);
    color: white;
}

/* ===== Settings Section ===== */
.settings-container {
    max-width: 600px;
}

.settings-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 32px;
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.card-header svg {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

.card-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 1rem;
    transition: var(--transition);
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1);
}

.helper-text {
    display: block;
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--gray-500);
}

.password-input {
    position: relative;
}

.toggle-visibility {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    padding: 4px;
}

.toggle-visibility:hover {
    color: var(--gray-600);
}

.toggle-visibility svg {
    width: 20px;
    height: 20px;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.test-btn, .save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.test-btn {
    flex: 1;
    background: white;
    border: 2px solid var(--gray-300);
    color: var(--gray-700);
}

.test-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.save-btn {
    flex: 1;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border: none;
    color: white;
}

.save-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.test-btn svg, .save-btn svg {
    width: 18px;
    height: 18px;
}

.info-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}

.info-card h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.info-card p {
    font-size: 0.875rem;
    color: var(--gray-600);
    line-height: 1.6;
}

.info-card ol {
    padding-left: 20px;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.info-card li {
    margin-bottom: 8px;
}

.info-card a {
    color: var(--primary);
    text-decoration: none;
}

.info-card a:hover {
    text-decoration: underline;
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--gray-800);
    color: white;
    border-radius: 10px;
    box-shadow: var(--shadow-xl);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

.toast-icon {
    width: 24px;
    height: 24px;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loader {
    background: white;
    padding: 32px 48px;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: var(--shadow-xl);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader span {
    font-weight: 500;
    color: var(--gray-700);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 16px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .model-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
