/* ============== BASE STYLES ============== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #64748b;
    --danger: #ef4444;
    --success: #22c55e;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

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

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

a:hover {
    text-decoration: underline;
}

/* ============== NAVBAR ============== */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand a {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
    text-decoration: none;
}

.nav-user {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ============== BUTTONS ============== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

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

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

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
}

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

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

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

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

.btn-block {
    width: 100%;
}

/* ============== CONTAINER ============== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* ============== HERO ============== */
.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.125rem;
}

/* ============== USAGE BAR ============== */
.usage-bar {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 2rem;
}

.usage-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.usage-remaining {
    color: var(--text-muted);
}

.usage-progress {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.usage-progress-bar {
    height: 100%;
    background: #22c55e;
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s ease;
}

/* ============== COMPARE SECTION ============== */
.compare-section {
    margin-bottom: 3rem;
}

.prompt-area {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.prompt-area textarea {
    flex: 1;
    padding: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    resize: vertical;
    font-family: inherit;
}

.prompt-area textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.prompt-area textarea::placeholder {
    color: var(--text-muted);
}

.model-selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.model-selection h3 {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.model-selection-summary {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.selection-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.selection-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    flex: 1;
}

.selection-tag {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
}

.selection-tag strong {
    background: rgba(255, 255, 255, 0.25);
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    margin-left: 0.5rem;
}

.model-selection-summary .btn {
    margin-left: 1rem;
}

.model-selection-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-style: italic;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.provider-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.provider-card h4 {
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.model-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.model-option:hover {
    background: var(--bg-input);
}

.model-option.selected {
    background: var(--primary);
    border-color: var(--primary);
}

.model-option.selected:hover {
    background: var(--primary-hover);
}

.model-name {
    font-size: 0.875rem;
    color: var(--text);
}

.model-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}

/* Premium-only models */
.model-option.premium-only {
    opacity: 0.5;
    cursor: not-allowed;
}

.model-option.premium-only:hover {
    background: transparent;
}

.model-option.premium-only .model-name {
    color: var(--text-muted);
}

.premium-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ============== RESULTS ============== */
.results-section {
    margin-top: 3rem;
}

.results-section h2 {
    margin-bottom: 1.5rem;
}

.results-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.results-grid .result-card {
    flex: 1 1 350px;
    min-width: 300px;
    max-width: 100%;
}

.result-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    border-top: 3px solid;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: auto;
    resize: both;
    min-width: 300px;
    min-height: 150px;
}

.result-card.draggable {
    cursor: default;
}

.result-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
    transform: scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.result-card.drag-over {
    border: 2px dashed var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.drag-handle {
    cursor: grab;
    padding: 0.25rem 0.5rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.drag-handle:hover {
    color: var(--text);
}

.drag-handle svg {
    width: 16px;
    height: 16px;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
}

.result-provider {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

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

.result-content {
    display: block;
    padding: 1rem;
    font-size: 0.875rem;
    line-height: 1.7;
    height: calc(100% - 45px);
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    background: var(--bg-card);
}

/* Resize indicator on card */
.result-card::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, transparent 50%, var(--primary) 50%);
    border-radius: 0 0 var(--radius) 0;
    pointer-events: none;
    opacity: 0.8;
}

.result-error {
    padding: 1rem;
    color: var(--danger);
    font-size: 0.875rem;
}

.result-time {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.result-status {
    margin-left: 0.5rem;
}

.status-done {
    color: var(--success);
    font-weight: bold;
}

.status-error {
    color: var(--danger);
    font-weight: bold;
}

/* Typing indicator animation */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.result-card.streaming .result-content {
    min-height: 100px;
}

.result-card.streaming .result-content:empty::after {
    content: 'Waiting for response...';
    color: var(--text-muted);
    font-style: italic;
}

/* ============== AUTH PAGES ============== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

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

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: block;
    margin-bottom: 1rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
}

.form-group input {
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
}

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

.form-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ============== MODAL ============== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 400px;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.copyable-content {
    position: relative;
}

.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

.copy-btn svg {
    width: 16px;
    height: 16px;
}

/* Copy tooltip */
.copy-tooltip {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.copy-tooltip.show {
    opacity: 1;
    visibility: visible;
}

.copy-btn-wrapper {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.copy-btn-wrapper .copy-btn {
    position: static;
}

.copy-btn-header-wrapper {
    position: relative;
    margin-left: auto;
}

.copy-btn-header {
    position: static;
    padding: 0.35rem;
    background: transparent;
    border: 1px solid var(--border);
}

.copy-btn-header svg {
    width: 14px;
    height: 14px;
}

.copy-btn-header-wrapper .copy-tooltip {
    top: -28px;
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
}

/* ============== CONFIG PAGE ============== */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--text-muted);
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.config-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}

.config-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-input);
}

.config-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.config-info h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.config-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.config-body {
    padding: 1rem;
}

.config-body p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.config-link {
    font-size: 0.75rem;
}

.config-footer {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--border);
}

.config-footer input {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.875rem;
}

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

/* ============== HISTORY PAGE ============== */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.history-item:hover {
    background: var(--bg-input);
}

.history-prompt {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.history-delete {
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state .btn {
    margin-top: 1rem;
}

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

.error {
    text-align: center;
    padding: 2rem;
    color: var(--danger);
}

/* ============== COMPARISON DETAIL ============== */
.comparison-detail {
    padding-top: 1rem;
}

.detail-content {
    margin-top: 1.5rem;
}

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

.detail-date {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.detail-prompt {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 2rem;
}

.detail-prompt h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.detail-results h3 {
    margin-bottom: 1rem;
}

/* ============== DASHBOARD ============== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.stat-value.stat-cost {
    color: var(--success);
}

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

.dashboard-section {
    margin-bottom: 2rem;
}

.dashboard-section h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.models-table-container,
.prompts-table-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-input);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.data-table tbody tr:hover {
    background: var(--bg-input);
}

.data-table tbody tr.clickable {
    cursor: pointer;
}

.data-table .empty,
.data-table .loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.provider-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

.prompt-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.date-cell {
    white-space: nowrap;
    color: var(--text-muted);
}

.models-cell {
    white-space: nowrap;
}

.cost-cell {
    color: var(--success);
    font-weight: 500;
    white-space: nowrap;
}

.modal-large {
    max-width: 700px;
    width: 100%;
}

.prompt-detail pre {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ============== RESPONSIVE ============== */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }

    .container {
        padding: 1rem;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .prompt-area {
        flex-direction: column;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .history-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-meta {
        width: 100%;
        justify-content: space-between;
    }
}
