:root {
    --stirling-blue-dark: #004b73;
    --stirling-blue-darker: #002f4f;
    --stirling-blue: #0076a8;
    --stirling-cyan: #4fb3d8;
    --stirling-green: #7ac142;
    --stirling-lime: #b7d433;

    --bg-main: #f4f7f8;
    --bg-card: #ffffff;
    --text-main: #1f2f38;
    --text-muted: #6c7a80;
    --border-soft: #d9e2e6;

    --shadow-soft: 0 16px 40px rgba(0, 53, 82, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background:
        linear-gradient(135deg, rgba(0, 118, 168, 0.10), rgba(122, 193, 66, 0.10)),
        var(--bg-main);
    color: var(--text-main);
}

.page-wrapper {
    height: 100vh;
    padding: 28px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-header {
    max-width: 1180px;
    width: 100%;
    margin: 0 auto 24px auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    height: 46px;
}

.bar {
    width: 10px;
    border-radius: 3px;
}

.blue-dark {
    height: 42px;
    background: var(--stirling-blue-dark);
}

.blue {
    height: 34px;
    background: var(--stirling-blue);
}

.green {
    height: 26px;
    background: var(--stirling-green);
}

.lime {
    height: 18px;
    background: var(--stirling-lime);
}

.top-header h1 {
    margin: 0;
    color: var(--stirling-blue-dark);
    font-size: 26px;
    letter-spacing: 0.5px;
}

.top-header p {
    margin: 3px 0 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.chat-header-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    flex-shrink: 0;
    opacity: 0.95;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    color: var(--stirling-blue-dark);
    border: 1px solid var(--border-soft);
    padding: 9px 14px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: var(--shadow-soft);
}

.status-dot {
    width: 10px;
    height: 10px;
    background: var(--stirling-green);
    border-radius: 50%;
}

.chat-shell {
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 22px;
    flex: 1;
    min-height: 0;
}

.chat-panel {
    position: relative;
    background: var(--bg-card);
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-soft);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.image-extracting-label {
    position: absolute;
    top: 128px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    padding: 10px 18px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #d8e3e8;
    box-shadow: 0 8px 20px rgba(0, 53, 82, 0.12);
    color: #00557f;
    font-size: 13px;
    font-weight: 700;
}

.image-extracting-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(244, 247, 248, 0.72);
    backdrop-filter: blur(2px);
}

.extracting-card {
    width: min(420px, 86%);
    padding: 28px 30px;
    border-radius: 22px;
    background: #ffffff;
    border: 1px solid #d8e3e8;
    box-shadow: 0 18px 45px rgba(0, 53, 82, 0.18);
    text-align: center;
}

.extracting-spinner {
    width: 42px;
    height: 42px;
    margin: 0 auto 16px;
    border: 4px solid #d8e3e8;
    border-top-color: var(--stirling-green);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

.extracting-text {
    color: #00557f;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.extracting-subtext {
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.45;
}

.loading-dots::after {
    content: "";
    animation: loadingDots 1.2s steps(4, end) infinite;
}

.hidden {
    display: none;
}

@keyframes loadingDots {
    0% {
        content: "";
    }

    25% {
        content: ".";
    }

    50% {
        content: "..";
    }

    75%,
    100% {
        content: "...";
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.chat-header {
    background: linear-gradient(
        90deg,
        #004b73 0%,
        #006f9e 55%,
        #22a6d0 100%
    );
    color: white;
    padding: 22px 26px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header h2 {
    margin: 0;
    font-size: 22px;
}

.chat-header p {
    margin: 5px 0 0 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 14px;
}

/* MODE TOGGLE (info panel) */

.mode-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.mode-toggle {
    position: relative;
    flex-shrink: 0;
    width: 42px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: #d5dee2;
    cursor: pointer;
    transition: background 0.18s ease;
}

.mode-toggle:hover {
    background: #c3cfd4;
}

.mode-toggle.active {
    background: var(--stirling-green);
}

.mode-toggle.active:hover {
    background: #6cad3c;
}

.mode-toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 53, 82, 0.35);
    transition: transform 0.18s ease;
}

.mode-toggle.active .mode-toggle-knob {
    transform: translateX(18px);
}

.new-diagnosis-link {
    display: inline-block;
    margin-top: 10px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--stirling-blue);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.new-diagnosis-link:hover {
    color: var(--stirling-blue-dark);
    text-decoration: underline;
}

.sample-questions {
    margin: 48px auto 0;
    width: min(560px, 82%);
    text-align: center;
}

.sample-title {
    margin: 0 0 14px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.sample-question-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sample-question {
    position: relative;
    width: 100%;
    min-height: 58px;
    padding: 14px 44px 14px 18px;
    border: 1px solid #d8e3e8;
    border-radius: 14px 14px 4px 14px;
    background: #ffffff;
    color: #1f2f38;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    box-shadow: none;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.sample-question-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: transparent;
    color: var(--stirling-green);
    transition: background 0.12s ease, color 0.12s ease;
}

.sample-question-icon svg {
    width: 28px;
    height: 28px;
}

.sample-question:hover .sample-question-icon {
    background: transparent;
    color: #5faa38;
}

.sample-question-text {
    display: block;
    flex: 1;
}

.sample-question-arrow {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.sample-question:hover .sample-question-arrow {
    transform: translateY(-50%) translateX(2px);
}

.sample-question:hover {
    border-color: var(--stirling-cyan);
    box-shadow: 0 8px 18px rgba(0, 53, 82, 0.08);
    transform: translateY(-1px);
}

.sample-question:active {
    transform: translateY(0);
}

.model-badge {
    background: var(--stirling-green);
    color: #10220c;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

/* Bot and sample question text = dark blue */
.bot-message .message-content,
.bot-message .message-content p,
.bot-response,
.bot-response p,
.bot-response li,
.bot-response strong,
.bot-response h1,
.bot-response h2,
.bot-response h3,
.bot-response h4,
.sample-title,
.sample-question,
.sample-question-text {
    color: #00263d;
}

/* User messages stay white because their background is blue */
.user-message .message-content,
.user-message .message-content p {
    color: #ffffff;
}

/* Bot meta text */
.bot-message .message-meta {
    color: #4d6470;
}

/* User meta text stays light/white */
.user-message .message-meta {
    color: rgba(255, 255, 255, 0.8);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    padding: 26px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background:
        linear-gradient(180deg, #ffffff, #f7fafb);
}

.message {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 0;
}

.bot-message {
    justify-content: flex-start;
}

.user-message {
    justify-content: flex-end;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 800;
    flex-shrink: 0;
}

.bot-avatar {
    background: var(--stirling-blue-dark);
    color: white;
}

.user-avatar {
    background: var(--stirling-green);
    color: white;
}

.message-content {
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid var(--border-soft);
    width: fit-content;
}

.bot-message .message-content {
    background: white;
    border-top-left-radius: 6px;
    max-width: min(620px, 72%);
}

.user-message .message-content {
    background: var(--stirling-blue);
    color: white;
    border-color: var(--stirling-blue);
    border-top-right-radius: 6px;
    max-width: 72%;
}

.bot-response {
    margin: 0;
    width: fit-content;
    max-width: 100%;
}

.message-content p,
.bot-response p {
    margin: 0;
    line-height: 1.45;
    font-size: 15px;
}

.bot-response p + p {
    margin-top: 12px;
}

.bot-response > *:first-child {
    margin-top: 0;
}

.bot-response > *:last-child {
    margin-bottom: 0;
}

.message-meta {
    display: block;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.user-message .message-meta {
    color: rgba(255, 255, 255, 0.75);
}

/* INPUT AREA */

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px;
    border-top: 1px solid var(--border-soft);
    background: #f7fafb;
    flex-shrink: 0;
}

.chat-input-area input {
    flex: 1;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 14px 18px;
    font-size: 15px;
    outline: none;
    background: white;
}

.input-accent {
    width: 8px;
    height: 34px;
    border-radius: 4px;
    flex-shrink: 0;
    background: linear-gradient(
        to bottom,
        var(--stirling-blue-dark) 0%,
        var(--stirling-blue-dark) 20%,
        var(--stirling-blue) 20%,
        var(--stirling-blue) 40%,
        var(--stirling-cyan) 40%,
        var(--stirling-cyan) 60%,
        var(--stirling-green) 60%,
        var(--stirling-green) 80%,
        var(--stirling-lime) 80%,
        var(--stirling-lime) 100%
    );
}

#userInput {
    flex: 1;
}

.chat-input-area button {
    height: 48px;
    padding: 0 24px;
    border: none;
    border-radius: 14px;
    background: #6fbe44;
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.chat-input-area button:hover {
    background: #5faa38;
    box-shadow: 0 4px 10px rgba(111, 190, 68, 0.25);
}

.chat-input-area button:active {
    transform: translateY(1px);
}

/* SCROLLBAR */

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c8d4d8;
    border-radius: 8px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9fb0b7;
}

.chat-graph {
    margin-top: 12px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    width: 100%;
    max-width: 520px;
    height: 300px;
}

.chat-graph canvas {
    width: 100% !important;
    height: 100% !important;
}

/* SIDE PANEL */

.info-panel {
    background: var(--bg-card);
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-soft);
    padding: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;

    display: flex;
    flex-direction: column;
}

.info-panel-scroll {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px;
    padding-right: 14px;
    box-sizing: border-box;

    scrollbar-width: thin;
    scrollbar-color: #c8d4da transparent;
}

.info-panel-scroll::-webkit-scrollbar {
    width: 6px;
}

.info-panel-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.info-panel-scroll::-webkit-scrollbar-thumb {
    background: #c8d4da;
    border-radius: 8px;
}

.info-panel-scroll::-webkit-scrollbar-thumb:hover {
    background: #9fb0b8;
}

.info-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.info-panel-title-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--stirling-blue-dark);
    flex-shrink: 0;
    line-height: 0;
}

.info-panel-title h3 {
    margin: 0;
    color: var(--stirling-blue-dark);
    font-size: 17px;
    line-height: 1;
}

.unit-card {
    border: 1px solid var(--border-soft);
    border-left: 5px solid var(--stirling-green);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 12px;
    background: #fbfdfe;
}

.unit-card strong {
    font-size: 17px;
    color: var(--text-main);
    text-transform: capitalize;
}

.unit-card span {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.unit-card strong {
    font-size: 17px;
    color: var(--text-main);
}

.side-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 40px;
    padding-top: 18px;
    border-top: 1px solid var(--border-soft);
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-muted);
}

.side-note-icon {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--stirling-blue-dark);
    opacity: 0.75;
}

/* UPLOAD CARD */

.upload-card {
    background: #ffffff;
    border: 1px solid #d8e3e8;
    border-radius: 16px;
    padding: 20px;
    margin-top: 4px;
}

.upload-card-title {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
}

.upload-card-title-icon {
    display: grid;
    place-items: center;
    color: var(--stirling-blue-dark);
    flex-shrink: 0;
}

.upload-card-title-icon svg {
    width: 21px;
    height: 21px;
}

.upload-card h3,
.upload-card-title h3 {
    margin: 0;
    color: var(--stirling-blue-dark);
    font-size: 15px;
    font-weight: 700;
}

.upload-description {
    margin: 0 0 16px;
    color: #5c6f78;
    font-size: 12px;
    line-height: 1.4;
}

.upload-file-button {
    width: 100%;
    height: 42px;
    border: 1px solid #cfdbe4;
    border-radius: 8px;
    background: transparent;
    color: var(--stirling-blue-dark);
    font-size: 13px;
    font-weight: 700;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    cursor: pointer;
    box-sizing: border-box;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.upload-file-button:hover {
    background: rgba(0, 118, 168, 0.06);
    border-color: var(--stirling-blue);
    box-shadow: 0 1px 4px rgba(0, 75, 115, 0.10);
}

.upload-file-icon {
    color: var(--stirling-blue-dark);
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.file-name {
    display: block;
    margin-top: 9px;
    color: #667982;
    font-size: 11px;
    text-align: center;
}

.upload-button-hidden {
    display: none;
}

.upload-result,
#uploadResult {
    margin: 10px 0 0 0;
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.35;
}

/* TYPING INDICATOR */

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 20px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--stirling-blue-dark);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.35;
    }

    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.loading-indicator {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 40px;
}

.loading-logo-wrap {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
}

.loading-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.loading-text {
    color: #9aa5aa;
    font-size: 12px;
    font-weight: 500;
}

@media (prefers-reduced-motion: no-preference) {
    .loading-logo-wrap {
        animation: logoBloom 1.5s ease-in-out infinite;
    }

    .loading-logo {
        animation: logoSpin 3s linear infinite;
    }
}

@keyframes logoBloom {
    0%,
    100% {
        transform: scale(0.82);
        filter: drop-shadow(0 0 0 rgba(79, 179, 216, 0));
    }

    50% {
        transform: scale(1.08);
        filter: drop-shadow(0 0 6px rgba(79, 179, 216, 0.45));
    }
}

@keyframes logoSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* RESPONSIVE */

@media (max-width: 850px) {
    html,
    body {
        overflow: auto;
    }

    .page-wrapper {
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    .chat-shell {
        grid-template-columns: 1fr;
        flex: none;
    }

    .chat-panel {
        height: 75vh;
    }

    .info-panel {
        order: -1;
        max-height: none;
    }

    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }

    .bot-message .message-content,
    .user-message .message-content {
        max-width: 84%;
    }
}
