:root {
    --primary: #2c5282;
    --primary-dark: #1a365d;
    --accent: #c6a34b;
    --bg: #f7f5f0;
    --surface: #ffffff;
    --border: #e2d9cc;
    --text: #2d3748;
    --text-muted: #718096;
    --danger: #c53030;
    --radius: 8px;
    --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

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

body {
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.nav-brand { font-size: 1.1rem; font-weight: bold; letter-spacing: 0.02em; }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; font-family: system-ui, sans-serif; font-size: 0.9rem; }
.nav-links a:hover { color: white; }
.nav-user { color: var(--accent); font-family: system-ui, sans-serif; font-size: 0.85rem; }

/* Flash messages */
.flash-messages { padding: 0.5rem 1.5rem; background: #fff3cd; border-bottom: 1px solid #ffd700; }
.flash { font-family: system-ui, sans-serif; font-size: 0.9rem; padding: 0.25rem 0; }

main { flex: 1; display: flex; flex-direction: column; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.55rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: system-ui, sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e0; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #9b2c2c; }
.btn-full { width: 100%; text-align: center; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Login */
.login-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}
.login-card h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.login-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
    font-family: system-ui, sans-serif;
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-family: system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text);
}
.form-group input[type=text],
.form-group input[type=password] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s;
}
.form-group input:focus { outline: none; border-color: var(--primary); }

/* Search page */
.search-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
    padding: 0 1rem;
}
.search-header { padding: 1rem 0 0.5rem; }
.search-header h2 { font-size: 1.1rem; color: var(--primary); }
.search-hint { font-size: 0.82rem; color: var(--text-muted); font-family: system-ui, sans-serif; margin-top: 0.2rem; }

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.welcome-message {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 2rem;
    max-width: 480px;
}

/* Messages */
.message {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 100%;
}
.message-user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    max-width: 70%;
    font-family: system-ui, sans-serif;
}
.message-assistant {
    background: var(--surface);
    border: 1px solid var(--border);
    align-self: flex-start;
}
.message-error {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    color: var(--danger);
    font-family: system-ui, sans-serif;
    font-size: 0.88rem;
}
.message-loading {
    background: var(--surface);
    border: 1px solid var(--border);
    align-self: flex-start;
    padding: 0.75rem 1rem;
}

/* Dots animation */
.dots span {
    display: inline-block;
    animation: blink 1.2s infinite;
    font-size: 1.3rem;
    color: var(--primary);
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.1; }
    40% { opacity: 1; }
}

.answer-text { white-space: pre-wrap; }

.sources {
    margin-top: 0.9rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-family: system-ui, sans-serif;
    font-size: 0.85rem;
}
.sources strong { color: var(--text-muted); }
.sources ul { list-style: none; margin-top: 0.4rem; }
.sources li { margin-bottom: 0.25rem; }
.sources a { color: var(--primary); text-decoration: none; }
.sources a:hover { text-decoration: underline; }

/* Search input area */
.search-input-area {
    padding: 0.75rem 0 1rem;
    border-top: 1px solid var(--border);
}
.search-bar { display: flex; gap: 0.5rem; align-items: flex-end; }
.search-bar textarea {
    flex: 1;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: system-ui, sans-serif;
    font-size: 0.95rem;
    resize: none;
    overflow: hidden;
    min-height: 42px;
    max-height: 160px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s;
}
.search-bar textarea:focus { outline: none; border-color: var(--primary); }
.search-controls { margin-top: 0.5rem; display: flex; justify-content: flex-end; }

/* Admin */
.admin-container {
    max-width: 860px;
    margin: 1.5rem auto;
    padding: 0 1rem;
    width: 100%;
}
.admin-container h2 { margin-bottom: 1.25rem; color: var(--primary); }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.card h3 { margin-bottom: 1rem; font-size: 1rem; color: var(--primary); }
.form-row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; margin-bottom: 0; }
.form-check { display: flex; align-items: center; gap: 0.4rem; }
.form-check label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.88rem; margin: 0; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-family: system-ui, sans-serif; font-size: 0.9rem; }
.table th, .table td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--text-muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }

@media (max-width: 600px) {
    .search-container { padding: 0 0.5rem; }
    .message-user { max-width: 85%; }
    .form-row { flex-direction: column; }
}
