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

:root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --sidebar-width: 280px;
    --narration-width: 320px;
    --nav-height: 48px;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* === Top Nav === */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--nav-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.top-nav.transparent {
    background: transparent;
    border-bottom: none;
}

.nav-left-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    display: flex;
    align-items: center;
}

.nav-logo img {
    height: 24px;
}

.top-nav:has(.nav-left-group),
.top-nav:has(.nav-logo) {
    justify-content: space-between;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1.5;
    text-decoration: none;
    font-family: inherit;
}

.nav-link:hover {
    color: var(--text);
    border-color: var(--accent);
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* === Auth Modal === */
.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
    position: relative;
}

.auth-modal-content h2 {
    margin-bottom: 20px;
}

.auth-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

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

.auth-error {
    color: var(--red);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

#auth-submit-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    margin-top: 4px;
    transition: background 0.15s;
}

#auth-submit-btn:hover {
    background: var(--accent-hover);
}

.auth-switch {
    margin-top: 16px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === UML Modal === */
.uml-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.uml-modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 90vw;
    max-width: 1000px;
    max-height: 85vh;
    overflow: auto;
    position: relative;
}

.uml-modal-content h2 {
    margin-bottom: 16px;
}

.uml-render {
    display: flex;
    justify-content: center;
}

.uml-render svg {
    max-width: 100%;
    height: auto;
}

.uml-fallback {
    white-space: pre-wrap;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
}

/* === File Tree === */
.filetree-legend {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.filetree-analyzed-dot::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
}

.filetree-other-dot::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-right: 6px;
    opacity: 0.4;
}

.filetree-render {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
}

.filetree-list {
    list-style: none;
    padding-left: 18px;
}

.filetree-render > .filetree-list {
    padding-left: 0;
}

.filetree-dir-name {
    color: var(--accent);
    font-weight: 600;
}

.filetree-file {
    color: var(--text-muted);
    opacity: 0.5;
}

.filetree-file.analyzed {
    color: var(--text);
    opacity: 1;
    font-weight: 500;
}

.filetree-file.analyzed::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 8px;
}

/* === Landing Page === */
.landing {
    max-width: 640px;
    margin: 0 auto;
    padding: 80px 24px;
    position: relative;
    z-index: 1;
}

.landing-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: url('/static/bg.svg') center center / cover no-repeat;
}

.landing-header {
    text-align: center;
    margin-bottom: 48px;
}

.landing-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-top: 8px;
}

.wordmark {
    width: 100%;
    max-width: 500px;
    height: auto;
    margin-bottom: 8px;
}

.landing-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 50;
}

.tour-form {
    background: rgba(22, 27, 34, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
}

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

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.optional {
    color: var(--text-muted);
    font-weight: 400;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.input-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b949e' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 38px;
    cursor: pointer;
}

.input-group select option {
    background: var(--bg-secondary);
    color: var(--text);
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--accent);
}

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

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

button {
    cursor: pointer;
    font-family: inherit;
}

.tour-form button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.15s;
}

.tour-form button[type="submit"]:hover:not(:disabled) {
    background: var(--accent-hover);
}

.tour-form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.status {
    margin-top: 16px;
    padding: 12px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    font-size: 0.9rem;
    text-align: center;
}

.status.error {
    color: var(--red);
    background: rgba(248, 81, 73, 0.1);
}

.hidden { display: none; }

/* Recent tours */
.recent-tours {
    margin-top: 48px;
}

.recent-tours h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.tour-list {
    list-style: none;
}

.tour-list li {
    border-bottom: 1px solid var(--border);
}

.tour-list li:last-child {
    border-bottom: none;
}

.tour-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    text-decoration: none;
}

.tour-list a:hover .tour-name {
    color: var(--accent-hover);
}

.tour-name {
    font-weight: 500;
}

.tour-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.private-label {
    color: var(--yellow);
    font-weight: 600;
}

/* === Pricing Page === */
.pricing-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 100px 24px 60px;
}

.pricing-header {
    text-align: center;
    margin-bottom: 48px;
}

.pricing-header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.pricing-header .subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.pricing-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.pricing-card-featured {
    border-color: var(--accent);
}

.pricing-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 14px;
    border-radius: 12px;
}

.pricing-card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.pricing-price {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 20px;
}

.pricing-period {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-muted);
}

.pricing-price-custom {
    color: var(--text-muted);
}

.pricing-features {
    list-style: none;
    flex: 1;
    margin-bottom: 24px;
}

.pricing-features li {
    padding: 6px 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.pricing-features li:last-child {
    border-bottom: none;
}

.pricing-cta {
    display: block;
    text-align: center;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    background: none;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}

.pricing-cta:hover {
    border-color: var(--accent);
    color: var(--text);
    text-decoration: none;
}

.pricing-cta-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pricing-cta-accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

@media (max-width: 900px) {
    .pricing-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .pricing-grid {
        grid-template-columns: 1fr;
    }
}

/* === Profile Page === */
.profile-page {
    max-width: 500px;
    margin: 0 auto;
    padding: 100px 24px 60px;
}

.profile-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
}

.profile-card h1 {
    font-size: 1.5rem;
    margin-bottom: 24px;
}

.profile-card h2 {
    font-size: 1.1rem;
    margin-top: 28px;
    margin-bottom: 16px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.profile-email {
    font-size: 0.95rem;
}

.profile-email label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.profile-submit-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    margin-top: 4px;
    transition: background 0.15s;
}

.profile-submit-btn:hover {
    background: var(--accent-hover);
}

.profile-success {
    color: var(--green);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* === Tour Layout (3-panel) === */
.tour-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--narration-width);
    height: calc(100vh - var(--nav-height));
    margin-top: var(--nav-height);
    overflow: hidden;
}

/* Step sidebar */
.step-sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.back-link {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sidebar-header h2 {
    font-size: 1rem;
    margin-top: 8px;
    word-break: break-word;
}

.repo-link {
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 4px;
    display: block;
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.git-hash {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
    margin-top: 4px;
    display: block;
}

.git-hash a {
    color: var(--accent);
    text-decoration: none;
}

.git-hash a:hover {
    text-decoration: underline;
}

.tour-summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.step-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.step-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.1s, border-color 0.1s;
}

.step-item:hover {
    background: var(--bg-tertiary);
}

.step-item.active {
    background: var(--bg-tertiary);
    border-left-color: var(--accent);
}

.step-number {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.step-item.active .step-number {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.step-info {
    min-width: 0;
}

.step-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.3;
}

.step-item-category {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Code panel */
.code-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.code-filepath {
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--text-muted);
}

.code-ref-nav {
    display: flex;
    gap: 6px;
}

.code-ref-btn {
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
}

.code-ref-btn:hover, .code-ref-btn.active {
    border-color: var(--accent);
    color: var(--accent);
}

.code-container {
    flex: 1;
    overflow: auto;
    background: var(--bg);
}

.code-container pre {
    margin: 0;
    padding: 0;
}

.code-container code {
    display: block;
    padding: 16px;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    tab-size: 4;
}

.code-line {
    display: block;
    padding: 0 16px;
    margin: 0 -16px;
}

.code-line.dimmed {
    opacity: 0.35;
}

.code-line.highlighted {
    background: rgba(88, 166, 255, 0.1);
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

.line-number {
    display: inline-block;
    width: 4em;
    text-align: right;
    padding-right: 1.5em;
    color: var(--text-muted);
    user-select: none;
    opacity: 0.5;
}

/* Narration panel */
.narration-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.narration-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.narration-header h3 {
    font-size: 1rem;
    flex: 1;
}

.category-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.category-badge.overview { border-color: var(--accent); color: var(--accent); }
.category-badge.entry_point { border-color: var(--green); color: var(--green); }
.category-badge.build { border-color: var(--yellow); color: var(--yellow); }
.category-badge.run { border-color: #bc8cff; color: #bc8cff; }
.category-badge.extend { border-color: #f78166; color: #f78166; }

.narration-text {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
}

.narration-text p {
    margin-bottom: 12px;
}

/* Audio controls */
.audio-controls {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.audio-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.audio-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.audio-btn.no-audio {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: default;
}

.audio-progress-wrap {
    flex: 1;
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.audio-progress {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0;
    transition: width 0.1s linear;
}

.audio-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
}

.nav-buttons {
    display: flex;
    gap: 8px;
}

.nav-btn {
    flex: 1;
    padding: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    transition: border-color 0.15s;
}

.nav-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 17, 23, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.retry-btn {
    margin-top: 16px;
    padding: 10px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

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

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Admin Dashboard === */
.admin-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 100px 24px 60px;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.admin-stat-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.admin-stat-card h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.admin-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.admin-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.cost-input {
    width: 100px;
    padding: 4px 8px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}

.cost-input:focus {
    outline: none;
    border-color: var(--accent);
}

.cost-delete-btn {
    background: none;
    border: none;
    color: var(--red);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
}

.cost-delete-btn:hover {
    background: rgba(248, 81, 73, 0.15);
}
