:root {
    --bg-ink: #06242c;
    --bg-deep: #0b3948;
    --panel: rgba(255, 255, 255, 0.76);
    --panel-strong: rgba(255, 255, 255, 0.9);
    --panel-line: rgba(7, 43, 52, 0.1);
    --text-main: #10252d;
    --text-soft: #546c73;
    --text-faint: #7b9197;
    --accent: #0f90a7;
    --accent-strong: #0c7186;
    --accent-soft: #dbf5f9;
    --danger: #b63b45;
    --success: #13795b;
    --warning: #ba7b12;
    --shadow: 0 28px 70px rgba(7, 29, 35, 0.18);
    --radius-xl: 30px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Source Sans 3", sans-serif;
    color: var(--text-main);
    background:
        radial-gradient(circle at top left, rgba(61, 222, 255, 0.35), transparent 34%),
        radial-gradient(circle at top right, rgba(8, 94, 122, 0.45), transparent 30%),
        linear-gradient(160deg, #63d7ec 0%, #14a8c0 36%, #0c7186 100%);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: var(--accent-strong);
}

.hidden {
    display: none !important;
}

.ambient-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.24), transparent 0 24%),
        radial-gradient(circle at 82% 18%, rgba(255, 255, 255, 0.14), transparent 0 20%),
        radial-gradient(circle at 72% 70%, rgba(255, 255, 255, 0.12), transparent 0 22%);
    opacity: 0.7;
}

.app-shell {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 26px 26px 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    max-width: 1520px;
    margin: 0 auto 24px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 16px;
}

.account-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.brand-logo {
    width: 72px;
    height: 72px;
    border-radius: 22px;
    object-fit: cover;
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.18);
}

.brand-overline,
.eyebrow {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.74rem;
    color: rgba(255, 255, 255, 0.82);
}

.eyebrow {
    color: var(--accent-strong);
}

.brand-title,
.card-heading h2,
.hero-panel h2,
.modal-header h2,
.plan-card h3,
.legal-block h3 {
    margin: 0;
    font-family: "Space Grotesk", sans-serif;
}

.brand-title {
    color: #ffffff;
    font-size: clamp(1.8rem, 2vw, 2.4rem);
}

.user-chip {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 240px;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    color: white;
    background: rgba(7, 41, 50, 0.24);
    backdrop-filter: blur(14px);
}

.topbar-logout-button {
    color: white;
    border-color: rgba(255, 255, 255, 0.26);
    background: rgba(7, 41, 50, 0.24);
    backdrop-filter: blur(14px);
}

.topbar-subscription-button {
    min-width: 220px;
}

.user-chip-label {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.72);
}

.main-shell {
    max-width: 1520px;
    margin: 0 auto;
}

.screen {
    animation: fade-up 260ms ease-out;
}

.auth-layout {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
    align-items: stretch;
}

.hero-panel,
.card,
.modal-card {
    border: 1px solid var(--panel-line);
    border-radius: var(--radius-xl);
    background: var(--panel);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

.hero-panel {
    padding: 34px;
    color: white;
    background:
        linear-gradient(155deg, rgba(9, 56, 69, 0.76), rgba(15, 108, 128, 0.56)),
        rgba(9, 39, 48, 0.18);
    border-color: rgba(255, 255, 255, 0.16);
}

.hero-badge {
    display: inline-flex;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.86rem;
    letter-spacing: 0.04em;
}

.hero-panel h2 {
    margin-top: 20px;
    font-size: clamp(2rem, 3vw, 3.3rem);
    line-height: 1.02;
}

.hero-panel p {
    max-width: 48ch;
    font-size: 1.15rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.84);
}

.hero-art-frame {
    margin-top: 28px;
    padding: 18px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.08);
}

.hero-art-frame img {
    display: block;
    width: min(100%, 460px);
    border-radius: 22px;
}

.card,
.modal-card {
    padding: 28px;
}

.card-heading {
    margin-bottom: 20px;
}

.card-heading.tight {
    margin-bottom: 12px;
}

.card-heading h2 {
    font-size: clamp(1.5rem, 1.9vw, 2rem);
    line-height: 1.08;
}

.auth-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.field,
.field-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.field span,
.field-label {
    font-weight: 700;
    color: var(--text-main);
}

input,
textarea,
pre,
.info-panel,
.markdown-surface,
.status-block,
.summary-list .summary-item {
    border: 1px solid rgba(7, 43, 52, 0.1);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.92);
}

input,
textarea {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    color: var(--text-main);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

pre,
.info-panel,
.status-block,
.markdown-surface {
    margin: 0;
    padding: 14px 16px;
}

pre {
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: pre-wrap;
}

.helper-text {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.95rem;
}

.diagnostic-message {
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px solid rgba(182, 59, 69, 0.22);
    border-radius: var(--radius-md);
    background: rgba(255, 248, 249, 0.94);
    color: #8b2632;
    font-size: 0.92rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.stacked-actions,
.search-actions,
.subscription-stack,
.chat-composer {
    display: flex;
    gap: 12px;
}

.stacked-actions {
    flex-direction: column;
    margin-top: 10px;
}

.search-actions {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    margin-top: 22px;
}

.search-actions .primary-button,
.search-actions .secondary-button,
.search-actions .ghost-button {
    width: min(100%, 320px);
}

.subscription-stack {
    margin-top: 18px;
    flex-wrap: wrap;
}

.search-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.52fr);
    gap: 20px;
    align-items: start;
}

.search-primary-stack {
    grid-column: 1 / -1;
    gap: 16px;
}

.search-question-block {
    grid-column: 1 / -1;
    gap: 12px;
}

.search-question-block textarea {
    min-height: 220px;
}

.compact-field {
    max-width: 360px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 48px;
    padding: 12px 18px;
    border-radius: 999px;
    border: none;
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover {
    transform: translateY(-1px);
}

.primary-button {
    color: white;
    background: linear-gradient(135deg, var(--accent), #0e6f84);
    box-shadow: 0 14px 28px rgba(15, 144, 167, 0.26);
}

.primary-button.subtle-button {
    background: linear-gradient(135deg, #0d8298, #096272);
}

.search-cta-button {
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.22), transparent 0 42%),
        linear-gradient(135deg, #12a9c2, #0c6f84 58%, #094d5b 100%);
    min-width: 260px;
    min-height: 58px;
    padding-inline: 26px;
    font-size: 1rem;
    box-shadow: 0 22px 40px rgba(10, 103, 123, 0.36);
    transform-origin: center;
}

.search-cta-button .button-icon {
    background: rgba(255, 255, 255, 0.2);
    width: 36px;
    height: 36px;
}

.search-cta-button:hover {
    transform: translateY(-2px) scale(1.01);
}

.secondary-button {
    color: var(--accent-strong);
    background: #ebf7f9;
    border: 1px solid rgba(15, 144, 167, 0.16);
}

.ghost-button {
    color: var(--text-main);
    background: transparent;
    border: 1px solid rgba(7, 43, 52, 0.12);
}

.danger-button {
    color: white;
    background: linear-gradient(135deg, #d15c67, #ab3943);
    box-shadow: 0 14px 28px rgba(182, 59, 69, 0.18);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.wide-button {
    min-width: 220px;
}

.button-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.button-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.rule {
    height: 1px;
    background: rgba(7, 43, 52, 0.12);
}

.inline-loading {
    padding: 8px 0;
    color: var(--text-soft);
    font-weight: 600;
}

.loading-banner,
.status-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px 18px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(7, 41, 50, 0.22);
    color: white;
    backdrop-filter: blur(14px);
}

.results-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.results-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
}

.table-wrapper {
    overflow: auto;
    border-radius: 18px;
}

.table-card {
    padding: 14px;
}

.study-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1950px;
    background: var(--panel-strong);
}

.study-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f4fbfc;
    border-bottom: 1px solid rgba(7, 43, 52, 0.12);
}

.study-table th,
.study-table td {
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
    border-right: 1px solid rgba(7, 43, 52, 0.08);
    border-bottom: 1px solid rgba(7, 43, 52, 0.08);
}

.study-table tbody tr:nth-child(even) {
    background: rgba(221, 243, 247, 0.42);
}

.sort-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: transparent;
    padding: 0;
    font-weight: 700;
    color: var(--text-main);
}

.sort-indicator {
    color: var(--text-faint);
}

.cell-multiline {
    white-space: pre-line;
}

.linkish {
    border: none;
    background: none;
    color: var(--accent-strong);
    font-weight: 700;
    padding: 0;
}

.summary-preview-button {
    display: inline-flex;
    width: 100%;
    border: none;
    background: none;
    color: var(--text-main);
    padding: 0;
    text-align: left;
}

.summary-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.markdown-surface {
    overflow: auto;
    line-height: 1.58;
}

.markdown-surface h1,
.markdown-surface h2,
.markdown-surface h3,
.markdown-surface h4 {
    font-family: "Space Grotesk", sans-serif;
    margin: 0 0 0.8rem;
}

.markdown-surface p,
.markdown-surface ul,
.markdown-surface ol {
    margin: 0 0 1rem;
}

.tall-surface {
    min-height: 360px;
    max-height: 58vh;
}

.status-strip {
    margin-top: 16px;
    margin-bottom: 0;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #7dc1cf;
}

.status-dot.loading {
    background: #ffc95a;
}

.status-dot.ready {
    background: #58d39b;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(3, 16, 20, 0.52);
    backdrop-filter: blur(8px);
}

.modal-card {
    width: min(100%, 900px);
    max-height: 92vh;
    overflow: auto;
    background: rgba(249, 254, 255, 0.95);
}

.modal-large {
    width: min(100%, 900px);
}

.modal-xl {
    width: min(100%, 1120px);
}

.modal-xxl {
    width: min(100%, 1220px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.plan-card,
.summary-item,
.chat-bubble {
    border: 1px solid rgba(7, 43, 52, 0.1);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.92);
}

.plan-card {
    flex: 1 1 260px;
    padding: 18px;
}

.plan-card p {
    color: var(--text-soft);
}

.legal-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 22px;
}

.search-inline {
    margin-bottom: 18px;
}

.summary-list {
    display: grid;
    gap: 12px;
}

.summary-item {
    padding: 18px;
}

.summary-item h3,
.summary-item p {
    margin: 0;
}

.summary-item button {
    width: 100%;
    border: none;
    background: none;
    padding: 0;
    text-align: left;
}

.summary-item-meta {
    margin-top: 8px;
    color: var(--text-soft);
    font-size: 0.94rem;
}

.empty-state {
    padding: 34px 16px;
    text-align: center;
    color: var(--text-soft);
}

.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 420px;
    max-height: 58vh;
    overflow: auto;
    padding-right: 6px;
}

.chat-bubble {
    max-width: min(78%, 840px);
    padding: 14px 16px;
}

.chat-bubble.user {
    margin-left: auto;
    background: rgba(15, 144, 167, 0.12);
}

.chat-bubble.assistant {
    margin-right: auto;
}

.chat-bubble .markdown-surface {
    padding: 0;
    border: none;
    background: transparent;
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.chat-composer {
    align-items: flex-end;
    margin-top: 18px;
}

.chat-composer textarea {
    min-height: 80px;
    flex: 1 1 auto;
}

.chat-composer .primary-button {
    min-width: 120px;
}

.toast-region {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 260px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 16px;
    color: white;
    background: rgba(8, 36, 44, 0.94);
    box-shadow: 0 20px 34px rgba(0, 0, 0, 0.18);
}

.toast.error {
    background: rgba(153, 44, 54, 0.94);
}

.toast.success {
    background: rgba(19, 121, 91, 0.94);
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1180px) {
    .auth-layout,
    .search-grid,
    .results-layout {
        grid-template-columns: 1fr;
    }

    .summary-card {
        min-height: 480px;
    }
}

@media (max-width: 960px) {
    .app-shell {
        padding: 20px 18px 34px;
    }

    .topbar {
        align-items: flex-start;
    }

    .account-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .topbar-subscription-button,
    .topbar-logout-button {
        min-width: 0;
    }

    .study-table {
        min-width: 1480px;
    }

    .modal {
        padding: 14px;
    }

    .modal-card {
        padding: 22px;
        max-height: 94vh;
    }

    .toast-region {
        left: 14px;
        right: 14px;
        bottom: 14px;
    }

    .toast {
        min-width: 0;
        max-width: none;
    }
}

@media (max-width: 760px) {
    .app-shell {
        padding: 18px 16px 32px;
    }

    .topbar,
    .account-actions,
    .results-toolbar,
    .modal-header,
    .chat-composer,
    .search-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar {
        gap: 14px;
    }

    .account-actions {
        gap: 10px;
    }

    .brand-lockup {
        align-items: flex-start;
    }

    .user-chip {
        min-width: 0;
    }

    .topbar-subscription-button,
    .topbar-logout-button,
    .results-toolbar .primary-button,
    .results-toolbar .secondary-button,
    .chat-composer .primary-button,
    .search-actions .primary-button,
    .search-actions .secondary-button,
    .search-actions .ghost-button {
        width: 100%;
    }

    .card,
    .hero-panel,
    .modal-card {
        padding: 22px;
        border-radius: 24px;
    }

    .modal {
        padding: 8px;
    }

    .modal-card {
        width: 100%;
        max-height: 96vh;
        padding: 18px;
        border-radius: 20px;
    }

    .main-shell,
    .topbar {
        max-width: 100%;
    }

    .search-question-block textarea {
        min-height: 180px;
    }

    .study-table {
        min-width: 1220px;
    }

    .chat-thread {
        min-height: 280px;
        max-height: 46vh;
    }

    .chat-bubble {
        max-width: 100%;
    }
}
