:root {
    --primary-blue: #2563eb;
    --primary-indigo: #4f46e5;
    --bg-main: #f8fafc;
    /* slate-50 */
    --bg-sidebar: #f1f5f9;
    /* slate-100 */
    --bg-card: #ffffff;
    --text-title: #0f172a;
    /* slate-900 */
    --text-body: #334155;
    /* slate-700 */
    --text-muted: #64748b;
    /* slate-500 */
    --border-color: #e2e8f0;
    /* slate-200 */
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
}

/* Chat Controls & Toggle */
.chat-controls {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 0.4rem;
    padding: 0 0.8rem;
}

.toggle-container {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: white;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.admin-link {
    display: block;
    text-decoration: none;
    color: var(--text-body);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.6rem;
    border-radius: 6px;
    transition: background 0.2s;
    text-align: center;
    background: #f8fafc;
    border: 1px solid var(--border-color);
}

.admin-link:hover {
    background: #f1f5f9;
    color: var(--primary-blue);
}

.toggle-container input {
    display: none;
}

.slider {
    position: relative;
    width: 32px;
    height: 18px;
    background-color: #cbd5e1;
    border-radius: 18px;
    margin-right: 8px;
    transition: .3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .3s;
}

input:checked+.slider {
    background-color: var(--primary-blue);
}

input:checked+.slider:before {
    transform: translateX(14px);
}

.toggle-label {
    font-weight: 500;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-body);
    overflow: hidden;
    height: 100vh;
    font-size: 16px;
    line-height: 1.7;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-title);
    letter-spacing: -0.025em;
}

.upload-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-card);
}

.drop-zone:hover,
.drop-zone.active {
    border-color: var(--primary-blue);
    background: #eff6ff;
}

.drop-zone p {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.status-msg {
    font-size: 0.8125rem;
    text-align: center;
    min-height: 1.2rem;
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-card {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.info-card h3 {
    font-size: 0.9375rem;
    margin-bottom: 0.875rem;
    color: var(--text-title);
    font-weight: 600;
}

.info-card ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-card li {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-card li::before {
    content: "→";
    color: var(--primary-blue);
    font-weight: bold;
}

/* Chat Area Styling */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
}

.chat-header {
    padding: 1.25rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.chat-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-title);
}

.model-badge {
    background: #e0e7ff;
    color: #4338ca;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

/* Centering Message Content */
.message-wrapper {
    width: 100%;
    max-width: 56rem;
    /* 4xl / 896px */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.message {
    max-width: 90%;
    padding: 1.25rem 1.5rem;
    border-radius: 1rem;
    word-break: break-word;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    color: var(--text-body);
}

.user-message {
    align-self: flex-end;
    background: var(--primary-blue);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* Markdown Details within message */
.message h1,
.message h2,
.message h3 {
    margin: 1.5rem 0 1rem 0;
    color: var(--text-title);
    line-height: 1.3;
}

.message p {
    margin-bottom: 1rem;
}

.message ul,
.message ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.message li {
    margin-bottom: 0.5rem;
}

/* Table Styling */
.message .table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.message table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.message th,
.message td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.message th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-title);
}

/* Chat Input Area */
.chat-input-wrapper {
    padding: 1.5rem 2rem 2.5rem 2rem;
    background: linear-gradient(to top, var(--bg-main) 80%, transparent);
}

.chat-input-area-container {
    max-width: 56rem;
    margin: 0 auto;
    width: 100%;
}

.chat-input-area {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.chat-input-area:focus-within {
    border-color: var(--primary-blue);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-title);
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    outline: none;
    max-height: 200px;
}

.send-btn {
    background: var(--primary-blue);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: background 0.2s ease;
}

.send-btn:hover {
    background: #1d4ed8;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.0);
    }
}

/* Source & Excerpt Styling */
.source-container {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.source-header {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.source-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.source-wrapper {
    width: 100%;
}

.source-item {
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
}

.source-item.clickable {
    cursor: pointer;
}

.source-item.clickable:hover {
    background: #e2e8f0;
}

.source-item.active {
    border-color: var(--primary-blue);
    background: #eff6ff;
}

.source-id {
    background: #cbd5e1;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
    color: #475569;
}

.source-info {
    display: flex;
    flex-direction: column;
}

.source-filename {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-title);
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-page {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.source-excerpt {
    margin-top: 0.5rem;
    padding: 1rem;
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hidden {
    display: none;
}