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

:root {
    --bg: #0a0a0b;
    --bg-elevated: #141416;
    --bg-hover: #1a1a1e;
    --surface: #1e1e22;
    --border: #2a2a30;
    --border-light: #3a3a42;
    --text: #e8e8ec;
    --text-dim: #8a8a96;
    --text-muted: #5a5a66;
    --accent: #ff4d4d;
    --accent-glow: rgba(255, 77, 77, 0.15);
    --accent-hover: #ff6b6b;
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #ef4444;
    --font: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 8px;
    --radius-lg: 12px;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Material Symbols */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

/* === Landing Page === */
.landing {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.landing__hero {
    text-align: center;
    max-width: 640px;
    width: 100%;
}

.landing__badge {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 100px;
    background: var(--accent-glow);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 1.5rem;
}

.landing__title {
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.landing__title-accent {
    background: linear-gradient(135deg, var(--accent), #ff8c42);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.landing__subtitle {
    color: var(--text-dim);
    font-size: 1.1rem;
    margin-bottom: 2rem;
    line-height: 1.7;
}

/* API Key Setup */
.landing__api-setup {
    margin-bottom: 1.5rem;
}

.landing__api-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.85rem;
    color: var(--text-dim);
    transition: all 0.2s;
}

.landing__api-status--active {
    border-color: var(--green);
    color: var(--green);
}

.landing__api-status--active .material-symbols-outlined:first-child {
    color: var(--green);
}

.landing__api-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--bg-hover);
    border: none;
    border-radius: 50%;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 0.25rem;
}

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

/* Form */
.landing__form { width: 100%; }

.landing__input-group {
    display: flex;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.2s;
}

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

.landing__input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    padding-left: 1rem;
}

.landing__input-icon {
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.landing__input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 1rem;
    padding: 1rem 0.75rem;
}

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

.landing__submit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.75rem;
    background: var(--accent);
    color: white;
    border: none;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.landing__submit:hover { background: var(--accent-hover); }
.landing__submit:disabled { opacity: 0.6; cursor: not-allowed; }
.landing__submit-icon { display: flex; align-items: center; }

.landing__options {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
}

.landing__depth-label {
    color: var(--text-dim);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.landing__depth-select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Loading */
.landing__loading {
    margin-top: 2rem;
    text-align: center;
}

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

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

.landing__loading-text {
    color: var(--text);
    font-weight: 500;
}

.landing__loading-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Error */
.landing__error {
    margin-top: 2rem;
    padding: 1rem 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius);
    text-align: center;
}

.landing__error p { color: var(--red); margin-bottom: 0.75rem; }

.landing__retry {
    background: none;
    border: 1px solid var(--red);
    color: var(--red);
    padding: 0.4rem 1rem;
    border-radius: var(--radius);
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
}

.landing__retry:hover {
    background: var(--red);
    color: white;
}

/* Features */
.landing__features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-top: 4rem;
    max-width: 800px;
    width: 100%;
}

.landing__feature {
    text-align: center;
    padding: 1.5rem 1rem;
}

.landing__feature-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.landing__feature-icon .material-symbols-outlined {
    font-size: inherit;
}

.landing__feature h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.landing__feature p {
    color: var(--text-dim);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal[hidden] {
    display: none;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.modal__content {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal__header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.modal__close:hover {
    background: var(--surface);
    color: var(--text);
}

.modal__body {
    padding: 1.5rem;
}

.modal__info {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.2);
    border-radius: var(--radius);
}

.modal__field {
    margin-bottom: 1.25rem;
}

.modal__field:last-child {
    margin-bottom: 0;
}

.modal__field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.modal__select {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.modal__select:focus {
    border-color: var(--accent);
}

.modal__input-group {
    display: flex;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s;
}

.modal__input-group:focus-within {
    border-color: var(--accent);
}

.modal__input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
    outline: none;
}

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

.modal__toggle-vis {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.2s;
}

.modal__toggle-vis:hover {
    color: var(--text);
}

.modal__hint {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

.modal__hint a:hover {
    text-decoration: underline;
}

.modal__footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

.modal__btn {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.modal__btn--primary {
    background: var(--accent);
    border: none;
    color: white;
}

.modal__btn--primary:hover {
    background: var(--accent-hover);
}

.modal__btn--secondary {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.modal__btn--secondary:hover {
    border-color: var(--red);
    color: var(--red);
}

/* === Session Page === */
.session {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.session__header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.session__logo {
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
}

.session__logo-accent {
    background: linear-gradient(135deg, var(--accent), #ff8c42);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.session__url {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--text-dim);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session__status {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
}

.session__status--ready { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.session__status--crawling { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.session__status--failed { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.session__status--pending { background: rgba(138, 138, 150, 0.15); color: var(--text-dim); }

.session__header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.session__settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s ease;
}

.session__settings-btn:hover {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--text-dim);
}

.session__recrawl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s ease;
}

.session__recrawl-btn:hover {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--text-dim);
}

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

.session__recrawl-btn--loading .material-symbols-outlined {
    animation: spin 1s linear infinite;
}

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

/* Layout */
.session__layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.session__panel {
    width: 40%;
    min-width: 320px;
    max-width: 520px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1.25rem;
    background: var(--bg-elevated);
}

.session__panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Tabs */
.session__tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.session__tab {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.session__tab:hover { border-color: var(--border-light); color: var(--text); }
.session__tab--active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

/* Screenshots */
.session__screenshot-group {
    margin-bottom: 1rem;
}

.session__screenshot-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.session__screenshot-wrapper {
    max-height: 300px;
    overflow-y: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    position: relative;
}

.session__screenshot-wrapper:hover::after {
    content: 'Click to expand';
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    pointer-events: none;
}

.session__screenshot {
    width: 100%;
    display: block;
}

.session__screenshot--mobile {
    max-width: 200px;
}

/* Screenshot Lightbox */
.screenshot-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    overflow-y: auto;
    padding: 2rem;
    cursor: zoom-out;
}

.screenshot-lightbox img {
    display: block;
    max-width: min(95%, 1200px);
    margin: 0 auto;
    border-radius: var(--radius);
}

.screenshot-lightbox__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screenshot-lightbox__close:hover {
    background: rgba(255,255,255,0.2);
}

.session__screenshot-placeholder {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Stats */
.session__quick-stats {
    margin-top: 1.5rem;
}

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

.session__stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
}

.session__stat--wide {
    grid-column: 1 / -1;
}

.session__stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--mono);
}

.session__stat-value--small {
    font-size: 0.85rem;
    font-weight: 500;
}

.session__stat-value--good { color: var(--green); }
.session__stat-value--bad { color: var(--red); }

.session__stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.2rem;
}

/* === Chat === */
.session__chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat__message {
    max-width: 85%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    font-size: 0.95rem;
}

.chat__message--assistant {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    align-self: flex-start;
}

.chat__message--user {
    background: var(--accent-glow);
    border: 1px solid rgba(255, 77, 77, 0.2);
    align-self: flex-end;
    color: var(--text);
}

/* Markdown in chat */
.chat__message h1, .chat__message h2, .chat__message h3 {
    margin: 1rem 0 0.5rem;
    font-weight: 600;
    line-height: 1.3;
}

.chat__message h1:first-child, .chat__message h2:first-child, .chat__message h3:first-child {
    margin-top: 0;
}

.chat__message h1 { font-size: 1.2rem; }
.chat__message h2 { font-size: 1.1rem; }
.chat__message h3 { font-size: 1rem; color: var(--accent); }

.chat__message p { margin: 0.5rem 0; }
.chat__message p:first-child { margin-top: 0; }
.chat__message p:last-child { margin-bottom: 0; }

.chat__message ul, .chat__message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.chat__message li { margin: 0.25rem 0; }

.chat__message code {
    font-family: var(--mono);
    background: rgba(255, 255, 255, 0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.chat__message pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.chat__message pre code {
    background: none;
    padding: 0;
}

.chat__message strong { color: var(--text); font-weight: 600; }
.chat__message em { color: var(--text-dim); }

/* Loading / typing */
.chat__loading {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.chat__typing {
    display: flex;
    gap: 4px;
}

.chat__typing span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

.chat__typing span:nth-child(2) { animation-delay: 0.2s; }
.chat__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Chat input */
.chat__form {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
    flex-shrink: 0;
}

.chat__input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat__input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.chat__input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

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

.chat__send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chat__send:hover { background: var(--accent-hover); }
.chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Responsive === */
@media (max-width: 768px) {
    .landing__features {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .session__layout {
        flex-direction: column;
    }

    .session__panel {
        width: 100%;
        max-width: none;
        min-width: 0;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}
