:root {
    --bg-color: #2b3026;
    --desk-color: #1e221b;
    --paper-color: #dcdcdc;
    --accent-red: #8f4440;
    --accent-green: #5a7d5a;
    --terminal-text: #33ff00;
    --font-main: 'Courier New', Courier, monospace;
}

body {
    background-color: var(--bg-color);
    color: var(--paper-color);
    font-family: var(--font-main);
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- TELAS (STATES) --- */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
}

.active {
    display: flex;
}

/* TELA 1: LOGIN API */
#start-screen {
    background: #111;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.login-box {
    border: 2px solid var(--accent-green);
    padding: 40px;
    text-align: center;
    background: #000;
    max-width: 500px;
    box-shadow: 0 0 20px rgba(51, 255, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.api-link {
    color: #aaa;
    font-size: 0.8rem;
    text-decoration: underline;
    cursor: pointer;
    margin-top: 5px;
}

.api-link:hover {
    color: #fff;
}

.db-section {
    margin-top: 20px;
    padding: 15px;
    background: #0a0a0a;
    border: 1px solid #333;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-radius: 4px;
}

.db-section h3 {
    font-size: 0.8rem;
    margin: 0;
    color: var(--accent-green);
    letter-spacing: 1px;
}

.db-help {
    font-size: 0.7rem;
    color: #888;
    line-height: 1.4;
    margin: 0;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-input-wrapper input[type=file] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}

.custom-file-btn {
    background: #222;
    color: #aaa;
    border: 1px dashed #555;
    padding: 8px;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    box-sizing: border-box;
}

.custom-file-btn:hover {
    border-color: var(--accent-green);
    color: #fff;
}

.db-status {
    font-size: 0.7rem;
    color: #666;
    margin-top: 5px;
}

.reset-link {
    color: var(--accent-red);
    font-size: 0.7rem;
    text-decoration: underline;
    cursor: pointer;
    margin-top: 5px;
    display: none;
    /* Hidden by default */
}

/* TELA 2: LOADING */
#loading-screen {
    background: rgba(0, 0, 0, 0.95);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 90;
    color: var(--terminal-text);
}

.loader {
    border: 8px solid #333;
    border-top: 8px solid var(--terminal-text);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

/* TELA 3: JOGO (INTERFACE ORIGINAL) */
#game-screen {
    flex-direction: column;
    z-index: 1;
    overflow: hidden;
    /* Added */
}

/* --- COMPONENTES DO JOGO --- */

/* Top Bar */
#status-bar {
    background: #111;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #000;
    font-size: 0.9rem;
}

#btn-back-login {
    background: var(--accent-red);
    color: #fff;
    border: none;
    padding: 5px 10px;
    font-size: 0.7rem;
    cursor: pointer;
    text-transform: uppercase;
}

#btn-back-login:hover {
    background: #b2534f;
}

#game-area {
    display: flex;
    flex: 1;
    position: relative;
    min-height: 0;
    /* Added */
}

/* Left: Viewport (Patient) */
#viewport {
    flex: 1;
    background: #4a5045;
    border-right: 4px solid #111;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    overflow: hidden;
}

.patient-sprite {
    width: 220px;
    height: 280px;
    background: #000;
    mask-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="30" r="20"/><rect x="15" y="55" width="70" height="50" /></svg>');
    -webkit-mask-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="30" r="20"/><rect x="15" y="55" width="70" height="50" /></svg>');
    background-color: #8b9bb4;
    position: relative;
    margin-bottom: -40px;
    z-index: 1;
}

#admission-doc {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 200px;
    background: #f0f0f0;
    color: #000;
    padding: 10px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
    font-size: 0.75rem;
    transform: rotate(-2deg);
    z-index: 10;
    border: 1px solid #999;
    opacity: 0.95;
}

#admission-doc h3 {
    font-size: 0.9rem;
    border-bottom: 1px solid #000;
    margin-bottom: 5px;
}

#patient-dialogue {
    background: #000;
    color: #fff;
    width: 100%;
    padding: 15px;
    text-align: center;
    border-top: 4px solid #333;
    min-height: 80px;
    font-style: italic;
    font-size: 1.1rem;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 20;
    position: relative;
    max-height: 80px;
    overflow-y: auto;
}

#desk {
    flex: 1.6;
    background: var(--desk-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

#log-area {
    background: #111;
    color: var(--terminal-text);
    flex: 1;
    min-height: 0;
    padding: 10px;
    font-size: 0.9rem;
    overflow-y: auto;
    border: 2px inset #555;
    margin-bottom: 10px;
    white-space: pre-wrap;
}

.log-user {
    color: #fff;
    font-weight: bold;
    border-top: 1px solid #333;
    margin-top: 5px;
    padding-top: 5px;
}

.log-sys {
    color: #aaa;
    font-style: italic;
}

.log-error {
    color: #ff5555;
    font-weight: bold;
}

.log-retry {
    color: #ffff00;
    font-size: 0.7rem;
}

input,
select,
textarea {
    width: 96%;
    padding: 10px;
    margin-bottom: 8px;
    background: #000;
    color: #fff;
    border: 1px solid #555;
    font-family: var(--font-main);
}

textarea {
    resize: vertical;
    height: 60px;
}

button {
    background: var(--paper-color);
    border: 2px solid #000;
    padding: 10px 16px;
    font-weight: bold;
    font-family: var(--font-main);
    cursor: pointer;
    text-transform: uppercase;
}

button:hover {
    background: #fff;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-finish {
    background: var(--accent-red);
    color: white;
    width: 100%;
    margin-top: 10px;
}

/* Modal Diagnostico */
#diag-modal {
    display: none;
    background: #222;
    padding: 0;
    /* Remove padding to handle header properly */
    border: 2px solid #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 400px;
    z-index: 100;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
}

#diag-modal-header {
    background: #444;
    color: #fff;
    padding: 10px;
    cursor: move;
    font-weight: bold;
    font-size: 0.9rem;
    border-bottom: 1px solid #555;
    text-align: center;
    font-family: 'Workbench', sans-serif;
    text-transform: uppercase;
}

#diag-modal>*:not(#diag-modal-header) {
    margin-left: 15px;
    margin-right: 15px;
}

#diag-modal h3 {
    display: none;
    /* Removed in favor of header */
}

/* TELA 4: REPORT (OVERLAY) */
#report-screen {
    background: rgba(0, 0, 0, 0.95);
    display: none;
    /* Changed from default state to flex when active */
    justify-content: center;
    align-items: center;
    z-index: 200;
}

#report-screen.active {
    display: flex;
}

#report-wrapper {
    display: flex;
    gap: 20px;
    max-width: 95vw;
    align-items: flex-start;
}


#report-paper {
    background: #f4f4f4;
    color: #000;
    width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 40px;
    border: 1px solid #000;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

.report-section {
    border-bottom: 1px dashed #999;
    padding: 10px 0;
    margin-bottom: 10px;
}

h1,
h2,
h3 {
    margin-top: 0;
    text-transform: uppercase;
    font-family: 'Workbench', sans-serif;
    font-variation-settings: "BLED" 0, "SCAN" -10;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.login-box h1 {
    color: white;
    margin-top: 0;
}

.login-box p {
    color: #aaa;
    font-size: 0.9rem;
}

.login-box button {
    width: 100%;
}

.login-box .model-info {
    font-size: 0.7rem;
    color: #666;
    margin-top: 10px;
}

#loading-details {
    font-size: 0.8rem;
    color: #888;
    margin-top: 10px;
}

#admission-doc .triage-info {
    font-size: 0.7rem;
    color: #555;
}

#controls button {
    width: 100%;
}

#diag-modal label {
    display: block;
    margin-top: 10px;
    color: #aaa;
    font-size: 0.8rem;
}

#diag-modal .submit-btn {
    width: 100%;
    background: #fff;
    color: #000;
    margin-top: 15px;
}

#diag-modal .cancel-btn {
    width: 100%;
    background: transparent;
    color: #aaa;
    border: none;
    margin-top: 5px;
    font-size: 0.8rem;
}

#report-paper h1 {
    text-align: center;
    border-bottom: 4px solid #000;
    padding-bottom: 10px;
}

#report-paper button {
    width: 100%;
    margin-top: 20px;
    background: #000;
    color: #fff;
    padding: 15px;
    font-size: 1.1rem;
}

/* Professor Chat */
#professor-chat {
    width: 350px;
    height: 90vh;
    background: #1a1a1a;
    border: 1px solid #444;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

#chat-prof-header {
    background: var(--accent-green);
    color: #fff;
    padding: 10px;
    font-weight: bold;
    text-align: center;
    font-size: 0.9rem;
}

#chat-prof-log {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg {
    padding: 10px;
    border-radius: 5px;
    font-size: 0.85rem;
    max-width: 85%;
    line-height: 1.4;
}

.msg.prof {
    background: #2c3e50;
    color: #ecf0f1;
    align-self: flex-start;
    border-left: 3px solid var(--accent-green);
}

.msg.user {
    background: #2b3026;
    color: var(--terminal-text);
    align-self: flex-end;
    border-right: 3px solid #555;
    text-align: right;
}

#chat-prof-input-area {
    padding: 10px;
    background: #000;
    display: flex;
    gap: 5px;
    border-top: 1px solid #333;
}

#chat-prof-input-area input {
    flex: 1;
    margin-bottom: 0;
    font-size: 0.8rem;
}

#chat-prof-input-area button {
    padding: 10px;
    font-size: 0.7rem;
    background: var(--accent-green);
    color: #fff;
    border: none;
}


/* --- MODAIS GENÉRICOS --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #111;
    border: 2px solid var(--accent-green);
    padding: 30px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 0 30px rgba(51, 255, 0, 0.1);
    color: #eee;
}

.close-modal-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: transparent;
    border: none;
    color: #666;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.close-modal-btn:hover {
    color: #fff;
    background: transparent;
}

.instruction-steps {
    display: flex;
    flex-direction: column;
    gap: 25px;
    margin: 20px 0;
}

.step p {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: #ccc;
}

.step img {
    width: 100%;
    border: 1px solid #444;
    border-radius: 4px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-btn-primary {
    flex: 2;
    background: var(--accent-green);
    color: #fff;
    text-decoration: none;
    text-align: center;
    padding: 12px;
    font-weight: bold;
    font-size: 0.8rem;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-btn-secondary {
    flex: 1;
    background: #222;
    color: #aaa;
    border: 1px solid #444;
}

@media (max-width: 768px) {
    body {
        overflow: auto;
        /* Allow scrolling on smaller screens */
    }

    #game-area {
        flex-direction: column;
    }

    #viewport {
        border-right: none;
        border-bottom: 4px solid #111;
        min-height: 350px;
    }

    #admission-doc {
        transform: none;
        /* Make it straight */
        position: relative;
        /* Put it in the layout flow */
        width: auto;
        left: auto;
        top: auto;
        margin: 10px;
        /* Give it some space */
        box-shadow: none;
        order: -1;
        /* Display it before other flex items in the viewport */
    }

    .patient-sprite {
        margin-bottom: 0;
        /* Remove the negative margin that pulls it down */
    }

    #report-wrapper {
        flex-direction: column;
        align-items: center;
        overflow-y: auto;
        padding: 20px 0;
    }

    #report-paper,
    #professor-chat {
        width: 90vw;
        max-height: none;
        height: auto;
    }

    #professor-chat {
        height: 400px;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
    }
}