:root {
    /* UMD Brand — Core (https://brand.umd.edu/colors) */
    --umd-red:        #e21833;
    --umd-gold:       #ffd200;
    --umd-black:      #000000;
    --umd-white:      #ffffff;

    /* UMD Brand — Neutrals */
    --umd-dark-gray:   #454545;
    --umd-medium-gray: #7f7f7f;
    --umd-light-gray:  #e6e6e6;
    --umd-bronze:      #ad7231;

    /* Semantic */
    --color-bg:                 var(--umd-white);
    --color-surface:            var(--umd-white);
    --color-surface-alt:        #f7f7f7;
    --color-sidebar-bg:         var(--umd-black);
    --color-sidebar-text:       var(--umd-white);
    --color-sidebar-muted:      #b8b8b8;
    --color-sidebar-border:     #1e1e1e;
    --color-sidebar-accent:     var(--umd-gold);
    --color-text-primary:       var(--umd-dark-gray);
    --color-text-muted:         var(--umd-medium-gray);
    --color-border:             var(--umd-light-gray);
    --color-primary:            var(--umd-red);
    --color-primary-text:       var(--umd-white);
    --color-primary-hover:      #b8132a;
    --color-user-msg:           var(--umd-red);
    --color-user-msg-text:      var(--umd-white);
    --color-assistant-msg:      var(--umd-light-gray);
    --color-assistant-msg-text: var(--umd-dark-gray);
    --color-focus-ring:         var(--umd-gold);
    --color-dropzone-active:    rgba(226, 24, 51, 0.12);
    --color-error:              var(--umd-red);

    /* Geometry */
    --radius:        8px;
    --radius-lg:    12px;
    --spacing:      16px;
    --sidebar-width: 320px;
    --content-max:   780px;

    /* Typography */
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
    height: 100%;
    font-family: var(--font-stack);
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
}

:focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ─── App shell ────────────────────────────────────────── */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────── */

.sidebar {
    background-color: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid var(--color-sidebar-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-sidebar-border);
}

.brand-mark {
    width: 44px;
    height: 44px;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--umd-white);
    letter-spacing: 0.01em;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section h2 {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-sidebar-accent);
}

.help-text {
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--color-sidebar-muted);
}

.tip-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--color-sidebar-muted);
}

.tip-list li {
    padding-left: 14px;
    position: relative;
}

.tip-list li::before {
    content: "•";
    color: var(--color-sidebar-accent);
    position: absolute;
    left: 0;
    font-weight: 700;
}

#system-prompt {
    width: 100%;
    background-color: #1c1c1c;
    color: var(--umd-white);
    border: 1px solid #2d2d2d;
    border-radius: var(--radius);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.4;
    resize: vertical;
    min-height: 96px;
    transition: border-color 0.15s;
}

#system-prompt::placeholder {
    color: #808080;
}

#system-prompt:focus {
    outline: none;
    border-color: var(--color-sidebar-accent);
}

.char-count {
    font-size: 0.7rem;
    color: var(--color-sidebar-muted);
    text-align: right;
}

/* ─── Dropzone ─────────────────────────────────────────── */

.dropzone {
    border: 2px dashed #3a3a3a;
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, transform 0.05s;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: #131313;
}

.dropzone:hover {
    border-color: var(--color-sidebar-accent);
    background-color: #181818;
}

.dropzone.is-dragging {
    border-color: var(--umd-red);
    background-color: var(--color-dropzone-active);
    transform: scale(1.01);
}

.dropzone-primary {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--umd-white);
}

.dropzone-secondary {
    font-size: 0.78rem;
    color: var(--color-sidebar-muted);
}

.dropzone .link {
    color: var(--color-sidebar-accent);
    text-decoration: underline;
}

.dropzone-hint {
    font-size: 0.7rem;
    color: var(--color-sidebar-muted);
    margin-top: 4px;
}

#file-input {
    display: none;
}

.uploaded-files {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.uploaded-files li {
    background-color: #1c1c1c;
    border: 1px solid #2d2d2d;
    border-left: 3px solid var(--color-sidebar-accent);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 0.78rem;
    color: var(--umd-white);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.uploaded-files li.error {
    border-left-color: var(--umd-red);
    color: #ffb3bd;
}

.uploaded-files .file-name {
    font-weight: 600;
    word-break: break-all;
}

.uploaded-files .file-meta {
    font-size: 0.7rem;
    color: var(--color-sidebar-muted);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--color-sidebar-border);
}

.org-info {
    font-size: 0.75rem;
    color: var(--color-sidebar-muted);
}

/* ─── Chat main ────────────────────────────────────────── */

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: var(--color-bg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
}

.chat-messages:empty::before {
    content: "Upload a document and ask a question to get started.";
    color: var(--color-text-muted);
    font-size: 0.9rem;
    text-align: center;
    margin: auto;
    max-width: 380px;
    line-height: 1.5;
}

.message {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.55;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.message.user {
    align-self: flex-end;
    background-color: var(--color-user-msg);
    color: var(--color-user-msg-text);
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background-color: var(--color-assistant-msg);
    color: var(--color-assistant-msg-text);
    border-bottom-left-radius: 4px;
}

/* ─── Composer ─────────────────────────────────────────── */

.composer {
    flex-shrink: 0;
    padding: 16px 24px 24px;
    background: linear-gradient(180deg, transparent, var(--color-surface) 32%);
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer-tips {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-align: center;
    line-height: 1.4;
}

.composer-tips strong {
    color: var(--color-text-primary);
}

.input-bar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 14px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-bar:focus-within {
    border-color: var(--umd-red);
    box-shadow: 0 0 0 3px rgba(226, 24, 51, 0.12);
}

#message-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--color-text-primary);
    resize: none;
    padding: 8px 0;
    min-height: 24px;
    max-height: 200px;
}

#message-input::placeholder {
    color: var(--color-text-muted);
}

#send-btn {
    padding: 10px 18px;
    background-color: var(--color-primary);
    color: var(--color-primary-text);
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s;
    flex-shrink: 0;
}

#send-btn:hover {
    background-color: var(--color-primary-hover);
}

#send-btn:active {
    transform: translateY(1px);
}

/* ─── Responsive ───────────────────────────────────────── */

@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: 100vh;
    }

    .sidebar {
        max-height: 45vh;
        border-right: none;
        border-bottom: 3px solid var(--umd-red);
    }

    .message {
        max-width: 90%;
    }

    .chat-messages,
    .composer {
        padding-left: 16px;
        padding-right: 16px;
    }
}
