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

/* ─── Dark Theme (default) ─── */
:root, [data-theme="dark"] {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #1a1a25;
    --border: #2a2a3a;
    --border-focus: #6366f1;
    --text-primary: #e8e8ed;
    --text-secondary: #8888a0;
    --text-muted: #555570;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --gradient-1: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-2: linear-gradient(135deg, #0a0a0f 0%, #12121a 100%);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --qr-filter: none;
}

/* ─── Light Theme ─── */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #eeeef0;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f8fa;
    --bg-input: #f0f0f3;
    --border: #d8d8e0;
    --border-focus: #6366f1;
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a72;
    --text-muted: #9090a8;
    --accent: #5b5ef0;
    --accent-hover: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.1);
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.08);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.08);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.08);
    --gradient-1: linear-gradient(135deg, #5b5ef0, #7c5cf6);
    --gradient-2: linear-gradient(135deg, #f5f5f7 0%, #eeeef0 100%);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
    --qr-filter: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ─── Auth Pages ─── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--gradient-2);
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 20%, var(--accent-glow) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, 0.08) 0%, transparent 50%);
    pointer-events: none;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.auth-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
}

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

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    outline: none;
}

.form-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-1);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-build {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-build:hover {
    background: var(--accent-glow);
}

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

.btn-build.building {
    border-color: var(--warning);
    color: var(--warning);
    animation: pulse 1.5s infinite;
}

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

.error-msg {
    background: var(--danger-bg);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 20px;
}

/* ─── QR Code ─── */
.qr-container {
    text-align: center;
    margin: 24px 0;
}

.qr-container img {
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
}

.secret-key {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    word-break: break-all;
    text-align: center;
    margin: 12px 0;
}

/* ─── Token Input ─── */
.token-input {
    text-align: center;
    letter-spacing: 8px;
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ─── Dashboard ─── */
.dashboard {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 32px;
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.user-info strong {
    color: var(--text-primary);
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ─── Stats Bar ─── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

/* ─── Repo Grid ─── */
.repos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.repo-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all 0.2s ease;
}

.repo-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 0 24px var(--accent-glow);
}

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

.repo-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.repo-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.repo-badge.versions {
    background: var(--accent-glow);
    color: var(--accent);
}

.version-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-top: 1px solid rgba(42, 42, 58, 0.5);
}

.version-arch {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    min-width: 50px;
}

.version-number {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--success);
}

.version-file {
    font-size: 0.7rem;
    color: var(--text-muted);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.no-version {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

.repo-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.build-status {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.build-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.build-status .dot.idle { background: var(--text-muted); }
.build-status .dot.running { background: var(--warning); animation: pulse 1s infinite; }
.build-status .dot.success { background: var(--success); }
.build-status .dot.failed { background: var(--danger); }

/* ─── Toast Notifications ─── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

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

/* ─── Changelog Tooltip ─── */
.repo-name.has-changelog {
    cursor: pointer;
    position: relative;
}

.changelog-icon {
    font-size: 0.7rem;
    margin-left: 6px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.repo-name.has-changelog:hover .changelog-icon {
    opacity: 1;
}

.changelog-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    min-width: 350px;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: fadeIn 0.15s ease;
    pointer-events: none;
}

.changelog-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 24px;
    border: 8px solid transparent;
    border-top-color: var(--border);
}

.changelog-tooltip h4 {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 600;
}

.changelog-tooltip pre {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}

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

/* ─── Theme Toggle ─── */
.theme-toggle {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    border-color: var(--accent);
}

.theme-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
}

.theme-option.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

[data-theme="light"] .auth-container::before {
    background: radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, 0.04) 0%, transparent 50%);
}

[data-theme="light"] .auth-card {
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .repo-card:hover {
    box-shadow: 0 0 24px rgba(99, 102, 241, 0.08);
}

[data-theme="light"] .btn-primary {
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.2);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .dashboard { padding: 16px; }
    .repos-grid { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; gap: 12px; text-align: center; }
    .auth-card { padding: 28px; }
}

/* ─── Build Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
}

.modal .build-output {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-top: 12px;
}
