/* CSS Variables - Light Theme (Default) */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #ffffff;
    --bg-color: #ffffff;
    --surface: #f8fafc;
    --surface-light: #f1f5f9;
    --card-background: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --border-radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Dark Theme */
[data-theme="dark"] {
    --background: #0f172a;
    --bg-color: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --card-background: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

/* Theme Toggle Switch */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-switch {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

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

.theme-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-light);
    border: 1px solid var(--border-color);
    transition: 0.3s;
    border-radius: 26px;
}

.theme-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: 0.3s;
    border-radius: 50%;
}

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

.theme-switch input:checked + .theme-slider:before {
    transform: translateX(22px);
    background-color: white;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

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

/* Header */
.header {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 1.8rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

.btn-secondary {
    background-color: var(--surface-light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
}

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

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

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

.form-input::placeholder {
    color: var(--text-secondary);
}

/* Cards */
.card {
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-title {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.75rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.auth-footer {
    text-align: center;
    margin-top: 16px;
    color: var(--text-secondary);
}

/* Alert Messages */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    color: var(--error-color);
}

.alert-success {
    background-color: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success-color);
    color: var(--success-color);
}

/* Main App Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 24px 0;
}

/* Debate Configuration */
.config-section {
    margin-bottom: 24px;
}

.config-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.config-row .form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.topic-input {
    flex: 3;
}

.rounds-select {
    flex: 0 0 100px;
}

/* Model Selection */
.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.model-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background-color: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.model-checkbox:hover {
    border-color: var(--primary-color);
}

.model-checkbox.selected {
    border-color: var(--primary-color);
    background-color: rgba(99, 102, 241, 0.1);
}

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

.model-checkbox input {
    display: none;
}

.model-info {
    flex: 1;
}

.model-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.model-provider {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.model-checkbox.selected .checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    font-size: 0.8rem;
}

/* Debate Arena */
.debate-arena {
    margin-top: 24px;
}

.debate-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 16px;
}

.status-info {
    display: flex;
    gap: 24px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.status-value {
    font-weight: 600;
}

.status-running {
    color: var(--warning-color);
}

.status-completed {
    color: var(--success-color);
}

.status-error {
    color: var(--error-color);
}

/* Model Panels */
.model-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 16px;
}

.model-panel {
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 600px;
}

.panel-header {
    padding: 16px;
    background-color: var(--surface-light);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-title {
    font-weight: 600;
}

.panel-provider {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.panel-status {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: var(--surface);
}

.panel-status.speaking {
    background-color: var(--primary-color);
    color: white;
    animation: pulse 1.5s infinite;
}

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

.panel-content {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
}

.round-section {
    margin-bottom: 16px;
}

.round-label {
    font-size: 0.75rem;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.response-text {
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

.waiting-text {
    color: var(--text-secondary);
    font-style: italic;
}

/* Summary Section */
.summary-section {
    margin-top: 24px;
}

.summary-panel {
    background-color: var(--surface);
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 24px;
}

.summary-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.summary-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.summary-content {
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-wrap;
}

/* Settings Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

/* Provider List */
.provider-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.provider-item {
    padding: 16px;
    background-color: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.provider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.provider-name {
    font-weight: 600;
}

.provider-status {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
}

.provider-status.configured {
    background-color: rgba(34, 197, 94, 0.1);
    color: var(--success-color);
}

.provider-status.not-configured {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
}

/* Error text styling for API key validation */
.provider-item .error-text,
.setup-provider .error-text {
    color: var(--error-color);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
    margin-top: 8px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.provider-description {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.provider-help {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.get-key-link {
    color: var(--primary-color);
    font-size: 0.85rem;
    font-weight: 500;
}

.get-key-link:hover {
    text-decoration: underline;
}

/* Prominent Get Key button for setup wizard */
.get-key-btn {
    display: inline-block;
    background: var(--primary-color);
    color: white !important;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.get-key-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    text-decoration: none;
}

.get-key-btn:active {
    transform: translateY(0);
}

.key-help-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Pro Badge */
.pro-badge {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
}

/* Form Hint */
.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Personalities List */
.personalities-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.personality-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface-light);
    border-radius: var(--border-radius);
}

.personality-model-name {
    font-weight: 500;
    min-width: 120px;
}

.personality-input {
    flex: 1;
}

.personality-input::placeholder {
    font-style: italic;
}

.provider-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.provider-actions .api-key-input {
    flex: 1 1 100%;
    margin-bottom: 8px;
}

.provider-actions .btn {
    flex-shrink: 0;
}

.provider-item .api-key-input {
    min-width: 200px;
    flex: 1;
    font-family: monospace;
    font-size: 0.85rem;
}

.api-key-input {
    flex: 1;
    width: 100%;
}

/* Debate History */
.history-section {
    margin-top: 32px;
}

.history-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    padding: 16px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    border-color: var(--primary-color);
}

.history-info {
    flex: 1;
}

.history-topic {
    font-weight: 500;
    margin-bottom: 4px;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-status {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
}

/* Subscription Badge */
.subscription-badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
}

.subscription-badge.free {
    background-color: rgba(100, 116, 139, 0.2);
    color: var(--text-secondary);
}

.subscription-badge.pro {
    background-color: rgba(99, 102, 241, 0.2);
    color: var(--primary-color);
}

.upgrade-banner {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upgrade-banner-text {
    font-size: 0.9rem;
}

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

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

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

.tab:hover {
    color: var(--text-primary);
}

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

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }

    .header {
        padding: 12px 0;
    }

    .config-row {
        flex-direction: column;
    }

    .config-row .form-group {
        width: 100%;
    }

    .model-panels {
        grid-template-columns: 1fr;
    }

    .status-info {
        flex-direction: column;
        gap: 8px;
    }

    .header-actions {
        flex-direction: row;
        gap: 8px;
    }

    .btn-small {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 10000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 500px;
}

.toast-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-notification.toast-warning {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid var(--warning-color);
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .toast-notification.toast-warning {
    background: linear-gradient(135deg, #78350f 0%, #451a03 100%);
}

.toast-notification.toast-info {
    background: var(--surface);
    border: 1px solid var(--border-color);
}

.toast-message {
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.4;
}

.toast-warning .toast-message {
    font-weight: 500;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
}
