:root {
    --primary-color: #0b57d0;
    /* Soft premium blue */
    --hover-bg: #e8f0fe;
    --background-light: #f8f9fa;
    --background-panel: #ffffff;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --error: #ea4335;
    --success: #1e8e3e;

    /* Radius & Spacing */
    --border-radius: 12px;
    --padding-sm: 12px;
    --padding-md: 20px;
    --padding-lg: 32px;

    /* Transitions */
    --transition: 0.25s ease-in-out;
}

/* --- DARK MODE VARIABLES --- */
html.dark-mode {
    --primary-color: #8ab4f8;
    /* Soft blue */
    --hover-bg: #444746;
    --background-light: #202124;
    --background-panel: #282a2d;
    --text-primary: #e3e3e3;
    --text-secondary: #c4c7c5;
    --border-color: #444746;
}

html.dark-mode .preceptor-help {
    background: linear-gradient(135deg, #4d4632 0%, #3d3725 100%);
    border-color: #635b44;
}

html.dark-mode .chat-column .panel-header {
    background-color: #282a2d;
}

html.dark-mode .chat-container {
    background: #202124;
}

html.dark-mode .chat-bubble.model {
    background-color: #3b3d40;
    color: var(--text-primary);
    border-color: #545759;
}

html.dark-mode .chat-bubble.user {
    background-color: #1a365d;
    color: var(--text-primary);
    border: 1px solid #2a4a7f;
}

html.dark-mode .grading-result {
    background: #2b3b32;
    border-color: #3b5042;
}

html.dark-mode .grading-result h3 {
    color: #81c995;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--background-light);
    color: var(--text-primary);
    overflow-x: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 340px;
    flex-shrink: 0;
    background: var(--background-panel);
    border-right: 1px solid var(--border-color);
    padding: var(--padding-lg) var(--padding-md);
    display: flex;
    flex-direction: column;
    gap: var(--padding-lg);
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.sidebar-header {
    text-align: center;
}

.sidebar-logo {
    width: 100%;
    border-radius: var(--border-radius);
    object-fit: cover;
    margin-bottom: 15px;
}

.sidebar h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

.sidebar h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-top: 15px;
    transition: var(--transition);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--hover-bg);
}

.patient-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.patient-option {
    padding: var(--padding-sm) var(--padding-md);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.patient-option:hover {
    background: var(--hover-bg);
}

.patient-option.active {
    background: var(--hover-bg);
    border-color: var(--primary-color);
    font-weight: 500;
    color: var(--primary-color);
}

.preceptor-help {
    background: linear-gradient(135deg, #fef7e0 0%, #fffbf0 100%);
    padding: var(--padding-md);
    border-radius: var(--border-radius);
    border: 1px solid #f6e8b6;
}

.preceptor-help p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

/* --- MAIN CONTENT --- */
.main-content {
    flex-grow: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--padding-lg);
    padding: var(--padding-lg);
    background-color: var(--background-light);
    overflow-y: auto;
}

.panel {
    background: var(--background-panel);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    min-width: 0;
}

.panel-header {
    padding: var(--padding-md);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1.25rem;
    margin: 0 0 8px 0;
}

.patient-intro {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
    margin: 0;
}

/* --- CHAT SECTION --- */
.chat-column .panel-header {
    background-color: #f8fafd;
}

.chat-container {
    flex-grow: 1;
    padding: var(--padding-md);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #fafafa;
    width: 100%;
    box-sizing: border-box;
}

.chat-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.chat-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-wrapper.model {
    align-self: flex-start;
    flex-direction: row;
}

.chat-icon {
    font-size: 1.25rem;
    background: var(--background-panel);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-bubble {
    max-width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-bubble.user {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.model {
    background-color: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.chat-input-area {
    padding: var(--padding-md);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: var(--background-panel);
}

textarea,
input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    background-color: var(--background-light);
    color: var(--text-primary);
    transition: var(--transition);
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}

textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(11, 87, 208, 0.2);
}

/* --- FORM / CHARTING SECTION --- */
.form-container {
    padding: var(--padding-md);
    overflow-y: auto;
    flex-grow: 1;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* --- BUTTONS --- */
.btn {
    padding: 10px 16px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.95rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: #084099;
    box-shadow: 0 2px 6px rgba(11, 87, 208, 0.3);
}

.submit-btn {
    width: 100%;
    background-color: #1e8e3e;
    color: white;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
}

.submit-btn:hover {
    background-color: #156c2f;
}

.secondary-btn.outline {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-secondary);
    margin-top: 10px;
}

.secondary-btn.outline:hover {
    background: var(--hover-bg);
}

/* --- MISC & UTILS --- */
.hidden {
    display: none !important;
}

.grading-result {
    margin-top: 25px;
    padding: var(--padding-md);
    background: #e6f4ea;
    border: 1px solid #ceead6;
    border-radius: var(--border-radius);
}

.grading-result h3 {
    color: #137333;
    margin-top: 0;
}

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.typing-indicator {
    padding: 12px;
    align-self: flex-start;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9rem;
    animation: pulse 1.5s infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

@keyframes pulse {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 15px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        box-sizing: border-box;
    }

    .main-content {
        padding: 15px;
        overflow-y: visible;
    }
}

/* --- IMAGE MODAL --- */
.image-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.image-modal-content {
    background: var(--background-panel);
    padding: 25px;
    border-radius: var(--border-radius);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.close-modal {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.close-modal:hover {
    color: var(--error);
}

.image-gallery {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
    padding-top: 20px;
}

.image-item {
    text-align: center;
    width: 100%;
}

.image-item img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.image-caption {
    margin-top: 15px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}