/* Public site (Flight-AI-az0): a dark graph canvas with a white reading/ask panel. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body.public {
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--night);
    -webkit-font-smoothing: antialiased;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

button {
    font: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot-cfr { background: var(--cfr); }
.dot-aim { background: var(--aim); }
.dot-handbook { background: var(--handbook); }
.dot-ac { background: var(--ac); }

/* ---- Layout ---------------------------------------------------------- */

.home-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.graph-area {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--night-ink);
    overflow: hidden;
}

.graph {
    position: absolute;
    inset: 0;
}

.graph-bar {
    position: absolute;
    top: 20px;
    left: 24px;
    right: 24px;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    pointer-events: none;
}
.graph-bar > * {
    pointer-events: auto;
}

.brand {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.01em;
    color: var(--night-ink);
    text-decoration: none;
}

.graph-search {
    position: relative;
    flex: 1 1 260px;
    max-width: 420px;
}
.graph-search input {
    width: 100%;
    height: 44px;
    padding: 0 18px;
    border: 1px solid var(--night-line);
    border-radius: var(--pill);
    background: var(--night-2);
    color: var(--night-ink);
    font: inherit;
    font-size: 14px;
}
.graph-search input::placeholder {
    color: var(--night-ink-2);
}

.search-results {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--ground);
    color: var(--ink);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
    max-height: 60vh;
    overflow-y: auto;
}
.search-result {
    width: 100%;
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
    padding: 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    text-align: left;
    cursor: pointer;
    color: inherit;
}
.search-result:hover,
.search-result:focus-visible {
    background: var(--ground-2);
}
.search-label {
    font-size: 14px;
    font-weight: 500;
}
.search-sub {
    grid-column: 2;
    font-size: 12px;
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-empty {
    padding: 10px;
    font-size: 14px;
    color: var(--ink-muted);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 12px;
    color: var(--night-ink-2);
}
.legend li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.staff-link {
    margin-left: auto;
    padding: 8px 14px;
    border: 1px solid var(--night-line);
    border-radius: var(--pill);
    background: var(--night-2);
    color: var(--night-ink);
    font-size: 13px;
    text-decoration: none;
}
.staff-link:hover {
    border-color: #3c4452;
}

.graph-status {
    position: absolute;
    left: 24px;
    bottom: 84px;
    z-index: 2;
    margin: 0;
    max-width: 420px;
    font-size: 13px;
    color: var(--night-ink-2);
}

.graph-controls {
    position: absolute;
    left: 24px;
    bottom: 24px;
    z-index: 2;
    display: flex;
    gap: 8px;
}
.graph-button {
    min-width: 44px;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--night-line);
    border-radius: 10px;
    background: var(--night-2);
    color: var(--night-ink);
    font-size: 15px;
    cursor: pointer;
}
.graph-button:hover {
    border-color: #3c4452;
}

/* ---- Panel ----------------------------------------------------------- */

.panel {
    flex: 0 0 420px;
    width: 420px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--ground);
    min-height: 0;
}

.sheet-handle {
    display: none;
}

.panel-tabs {
    display: flex;
    gap: 4px;
    padding: 14px 20px 0;
    border-bottom: 1px solid var(--line);
}
.panel-tabs [role="tab"] {
    padding: 10px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--ink-muted);
    font-size: 14px;
    cursor: pointer;
}
.panel-tabs [aria-selected="true"] {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--ink);
}

.panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 28px 28px 32px;
}
.panel-body[hidden] {
    display: none;
}

.eyebrow {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.panel-title {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
}
.panel-ref {
    margin: 0 0 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-muted);
}
.panel-lead,
.panel-excerpt {
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.65;
    color: var(--ink-2);
}
.source-link {
    display: inline-block;
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
}

.related {
    border-top: 1px solid var(--line);
    padding-top: 14px;
    margin-bottom: 18px;
}
.related-title {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.related-count {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}
.related-list {
    margin: 0;
    padding: 0;
    list-style: none;
}
.related-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 0;
    border: 0;
    background: none;
    text-align: left;
    cursor: pointer;
    color: inherit;
}
.related-item:hover .related-label {
    color: var(--accent);
}
.related-label {
    font-size: 14px;
    font-weight: 500;
}
.related-sub {
    font-size: 12px;
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.button-primary {
    display: block;
    width: 100%;
    min-height: 46px;
    margin-top: 8px;
    padding: 12px 16px;
    border: 0;
    border-radius: 10px;
    background: var(--ink);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
.button-primary:hover {
    background: #2a303b;
}

/* ---- Chat (classes from chat.js) ------------------------------------- */

.panel-body.chat {
    display: flex;
    flex-direction: column;
    padding: 0;
}
.panel-body.chat[hidden] {
    display: none;
}
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.message {
    display: flex;
}
.message.user {
    justify-content: flex-end;
}
.message-content {
    max-width: 100%;
    font-size: 15px;
    line-height: 1.65;
}
.message.user .message-content {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    background: #f1f2f4;
}
.message.ai .message-content {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.message.ai .message-text {
    padding: 14px 16px;
}
.message-text p {
    margin: 0 0 10px;
}
.message-text p:last-child {
    margin-bottom: 0;
}
.message.error .message-content {
    background: var(--danger-tint);
    border-color: var(--error);
    color: var(--danger);
}

/* Live progress while a question is answered (chat.js addProgress). */
.progress {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--ground-2);
}
.progress-title {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 600;
}
.progress-steps {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.progress-step {
    display: grid;
    grid-template-columns: 10px auto minmax(0, 1fr);
    align-items: center;
    column-gap: 8px;
    font-size: 13px;
    transition: opacity var(--fast);
}
.progress-name {
    font-weight: 500;
}
.progress-detail {
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.progress-step.pending .dot {
    animation: dotPulse 1s infinite ease-in-out;
}
.progress-step.empty {
    opacity: 0.55;
}
.progress-step.waiting {
    opacity: 0.45;
}
.progress-spinner {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--line-2);
}
.progress-step.active .progress-spinner {
    border-color: var(--accent) transparent var(--accent) transparent;
    animation: spin 0.9s linear infinite;
}
.progress-step.done .progress-spinner {
    border-color: var(--success-ink);
    background: var(--success-ink);
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.progress.finished {
    background: none;
    padding: 8px 12px;
}

/* Sources under an answer, as chips coloured by kind. */
.src-chips {
    padding: 0 16px 14px;
}
.src-chips-label {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}
.src-chips-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.src-chip {
    max-width: 100%;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 0;
    border-radius: var(--pill);
    font-size: 13px;
    line-height: 1.3;
    text-decoration: none;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--ground-2);
    color: var(--ink-2);
}
.src-chip-cfr { background: var(--cfr-tint); color: var(--cfr-ink); }
.src-chip-aim { background: var(--aim-tint); color: var(--aim-ink); }
.src-chip-handbook { background: var(--handbook-tint); color: var(--handbook-ink); }
.src-chip-ac { background: var(--ac-tint); color: var(--ac-ink); }
.src-chip:hover {
    filter: brightness(0.96);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 14px 20px 8px;
    border-top: 1px solid var(--line);
}
.input-field {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 16px;
    border: 1px solid var(--line-2);
    border-radius: 22px;
    font: inherit;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    background: var(--ground);
    transition: border-color var(--fast), box-shadow var(--fast);
}
.input-field {
    overflow-y: hidden;
    scrollbar-width: thin;
}
.input-field::placeholder {
    color: #8f95a1;
}
/* One ring, not the page-wide outline drawn around the border. */
.input-field:focus,
.input-field:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgb(36 87 197 / 0.14);
}
.send-button {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    cursor: pointer;
    transition: background var(--fast), color var(--fast);
}
.send-button:hover:not(:disabled) {
    background: #2a303b;
}
.send-button:disabled {
    background: #eceef1;
    color: #8f95a1;
    cursor: default;
}
.loading-dots {
    display: flex;
    justify-content: center;
    gap: 3px;
}
.loading-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #fff;
    animation: dotPulse 1s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}
.disclaimer {
    margin: 0;
    padding: 0 20px 14px;
    font-size: 12px;
    color: var(--ink-muted);
}

/* The feedback button sits at the graph's bottom right, not over the chat box. */
.home .feedback-button {
    right: 444px;
    bottom: 24px;
    animation: none;
}
.home .feedback-panel {
    right: 444px;
}

/* ---- Phone: graph above, panel as a bottom sheet ---------------------- */

@media (max-width: 768px) {
    .home-layout {
        display: block;
        position: relative;
    }
    .graph-area {
        height: 100vh;
        height: 100dvh;
    }
    .graph-bar {
        top: 14px;
        left: 14px;
        right: 14px;
        gap: 10px;
    }
    .legend {
        display: none;
    }
    .graph {
        top: 60px;
        bottom: calc(42dvh + 64px);
    }
    .home .graph-bar {
        right: 70px;
    }
    .home .feedback-button {
        top: 14px;
        right: 14px;
        bottom: auto;
    }
    .home .feedback-panel {
        right: 16px;
    }
    .graph-status {
        left: 14px;
        right: 14px;
        bottom: calc(42dvh + 70px);
    }
    .graph-controls {
        left: auto;
        right: 14px;
        bottom: calc(42dvh + 14px);
    }
    .panel {
        width: auto;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 42dvh;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgb(0 0 0 / 0.35);
        transition: height 0.25s ease;
        z-index: 5;
    }
    .panel.expanded {
        height: 88dvh;
    }
    .sheet-handle {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 24px;
        border: 0;
        background: none;
        cursor: pointer;
    }
    .sheet-handle span {
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--line-2);
    }
    .panel-tabs {
        padding-top: 0;
    }
    .panel-body {
        padding: 20px;
    }
    .panel-title {
        font-size: 24px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .panel {
        transition: none;
    }
    .loading-dots span,
    .progress-step.pending .dot,
    .progress-step.active .progress-spinner {
        animation: none;
    }
}
