:root {
    --text-color: #333;
    --bg-color: #fcfcfc;
    --accent-color: #d1b17a;
    --link-color: #a07a3f;
    --link-hover-color: #8c6b36;
    --border-color: #eee;
    --muted-color: #888;
    --font-serif: 'Merriweather', Georgia, serif;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* ---- Base ---- */

body {
    font-family: var(--font-serif);
    color: var(--text-color);
    background-color: var(--bg-color);
    line-height: 1.7;
    margin: 0;
    padding: 0;
}

#app {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.5rem 4rem;
    min-height: 100vh;
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    color: var(--link-hover-color);
    text-decoration: underline;
}

h1, h2, h3, h4 {
    font-weight: 400;
    color: #111;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

/* ---- Inputs & Buttons ---- */

input[type="text"] {
    flex-grow: 1;
    padding: 0.55rem 0.9rem;
    font-size: 1rem;
    font-family: var(--font-sans);
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    color: var(--text-color);
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--accent-color);
}

button {
    padding: 0.55rem 1.2rem;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    font-weight: 500;
    background-color: var(--link-color);
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

button:hover {
    background-color: var(--link-hover-color);
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* ---- Breadcrumb ---- */

.breadcrumb {
    padding: 1.2rem 0 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: #666;
}

.breadcrumb a, .back-link {
    color: var(--link-color);
    text-decoration: none;
    cursor: pointer;
}

.breadcrumb a:hover, .back-link:hover {
    color: var(--link-hover-color);
    text-decoration: underline;
}

/* ---- Loading / empty states ---- */

.loading {
    text-align: center;
    color: var(--muted-color);
    margin-top: 2rem;
    font-style: italic;
}

/* ---- Landing View ---- */

.landing-container header {
    text-align: center;
    padding: 0.5rem 0 0.25rem;
    border-bottom: none;
}

.landing-container header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.05em;
    color: #111;
    margin: 0;
}

.intro-card {
    color: #555;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    line-height: 1.8;
    text-align: left;
}

.intro-card p {
    margin: 0 0 0.5rem;
}

.intro-card p:last-child {
    margin-bottom: 0;
}

.landing-view {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 1rem;
}

.landing-cards {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 800px;
}

.search-box-enclosure {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1.8rem 2rem;
    background-color: #fff;
}

.search-box-enclosure h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 400;
    color: #444;
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.85rem;
}

.landing-search-container {
    display: flex;
    gap: 8px;
}

/* Browse card */
.browse-links {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.browse-link {
    display: block;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    text-decoration: none;
    color: var(--link-color);
    background: var(--bg-color);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    transition: background-color 0.2s, border-color 0.2s;
}

.browse-link:hover {
    background-color: #f5efe3;
    border-color: var(--accent-color);
    text-decoration: none;
    color: var(--link-hover-color);
}

.landing-history-link {
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    padding-bottom: 1rem;
}

/* ---- Search View ---- */

.search-view {
    padding-bottom: 2rem;
}

.search-container {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
}

.results-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.result-item {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 0.75rem;
    padding: 1rem 1.2rem;
    transition: background-color 0.15s, border-color 0.15s;
    background: #fff;
    cursor: pointer;
}

.result-item:hover {
    background-color: #f5efe3;
    border-color: var(--accent-color);
}

.result-heading {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    color: var(--link-color);
    text-decoration: none;
    display: block;
}

.result-heading:hover {
    text-decoration: underline;
}

.result-location {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--muted-color);
    margin-bottom: 0.25rem;
}

.result-preview {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #555;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--muted-color);
}

/* ---- Citation chips (inline links rendered from [[ref]] markers) ---- */
/* Match the visual format of .sources-list li a */

.answer-text a {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    background: #fff;
    color: var(--link-color);
    border: 1px solid var(--border-color);
    padding: 0 5px;
    border-radius: 3px;
    text-decoration: none;
    vertical-align: baseline;
    margin: 0 1px;
    white-space: nowrap;
    transition: border-color 0.15s, background-color 0.15s;
}

.answer-text a:hover {
    background-color: #f5efe3;
    border-color: var(--accent-color);
    color: var(--link-hover-color);
    text-decoration: none;
}

/* ---- Chat View ---- */

.chat-view {
    padding-bottom: 0;
}

/* Messages scroll area — leaves room for fixed input bar */
.messages-container {
    padding-bottom: 90px;
}

/* Each row is either user (right) or assistant (left) */
.message-row {
    margin-bottom: 1.5rem;
}

.user-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 2.5rem;
}

.bubble-user {
    background-color: #f0e6cc;
    color: #3a2800;
    border: 1px solid var(--accent-color);
    padding: 0.7rem 1rem;
    border-radius: 16px 16px 4px 16px;
    max-width: 75%;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    line-height: 1.5;
}

.assistant-row {
    max-width: 90%;
}

/* Answer text (markdown rendered) */
.answer-text {
    font-size: 1rem;
    line-height: 1.8;
}

.answer-text p {
    margin-top: 0;
    margin-bottom: 0.9em;
}

.answer-text p:last-child {
    margin-bottom: 0;
}

/* Stage headers */
.status-text {
    color: var(--muted-color);
    font-family: var(--font-sans);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.35rem;
}

.status-text {
    margin-bottom: 0.75rem;
}

/* Source list (below chat response) */
.sources-list {
    margin-top: 1.5rem;
    margin-bottom: 0.9rem;
}

.references-header {
    color: var(--muted-color);
    font-family: var(--font-sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.2rem;
}

.sources-list ol {
    list-style: decimal;
    padding-left: 1.2rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sources-list ol li::marker {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--muted-color);
}

.sources-list li a {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--link-color);
    text-decoration: none;
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 3px;
    background: #fff;
    transition: border-color 0.15s, background-color 0.15s;
    display: inline-block;
}

.sources-list li a:hover {
    border-color: var(--accent-color);
    background: #f5efe3;
    text-decoration: none;
}

/* Animated dots for loading states */
.dots::after {
    content: "\2026";
    overflow: hidden;
    display: inline-block;
    vertical-align: bottom;
    width: 0;
    animation: ellipsis steps(5, end) 2000ms infinite;
}

@keyframes ellipsis {
    to { width: 1.33em; }
}

/* Blinking cursor during streaming */
.cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: #000;
    animation: blink 0.7s infinite;
    vertical-align: middle;
    margin-left: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Fixed input bar at the bottom of the viewport */
.chat-input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    padding: 0.75rem 0;
}

.chat-input-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 8px;
}

/* Response header label */
.response-header {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted-color);
    margin-bottom: 0.5rem;
    margin-top: 1.75rem;
}

/* ---- History / Chat Hub View ---- */

.chat-hub-input {
    margin-bottom: 0;
}

.chat-history-heading {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--muted-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
    margin-bottom: 0.8rem;
}

/* ---- History View ---- */

.history-view {
    padding-bottom: 2rem;
}

.chat-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-history-item {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 0.6rem;
    padding: 0.9rem 1.2rem;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}

.chat-history-item:hover {
    background-color: #f5efe3;
    border-color: var(--accent-color);
}

.chat-history-title {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--link-color);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-date {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--muted-color);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ---- Reference / Passage View ---- */

.reference-view {
    padding-bottom: 2rem;
}

.passage-content {
    font-size: 1rem;
    line-height: 1.8;
}

.passage-content p {
    margin-top: 0;
    margin-bottom: 0.9em;
}

.passage-content p:last-child {
    margin-bottom: 0;
}

/* ---- Auth Header ---- */

.auth-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    font-family: var(--font-sans);
    font-size: 0.85rem;
}

.auth-username {
    color: var(--muted-color);
}

.auth-link {
    color: var(--link-color);
    text-decoration: none;
}

.auth-link:hover {
    color: var(--link-hover-color);
    text-decoration: underline;
}

/* ---- Auth Forms (Login / Signup) ---- */

.auth-view {
    padding-bottom: 2rem;
}

.auth-form-container {
    max-width: 360px;
    margin: 0 auto;
}

.auth-form-container h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: #555;
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
    padding: 0.55rem 0.9rem;
    font-size: 1rem;
    font-family: var(--font-sans);
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    color: var(--text-color);
    outline: none;
    transition: border-color 0.2s;
}

.auth-form input:focus {
    border-color: var(--accent-color);
}

.auth-form button {
    margin-top: 0.5rem;
}

.auth-error {
    color: #c44;
    font-family: var(--font-sans);
    font-size: 0.85rem;
}

.auth-switch {
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-top: 1.5rem;
}

.auth-prompt {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--muted-color);
    text-align: center;
    margin-top: 2rem;
}

/* ---- Chat Sidebar ---- */

.chat-layout {
    position: relative;
}

.chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    display: flex;
}

.sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 8px;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1.2rem;
    background: #fff;
    color: var(--muted-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    z-index: 201;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}

.sidebar-toggle:hover {
    background-color: #f5efe3;
    color: var(--text-color);
}

.chat-sidebar.open .sidebar-toggle {
    left: auto;
    right: 8px;
}

.sidebar-content {
    width: 280px;
    background: #fff;
    border-right: 1px solid var(--border-color);
    height: 100%;
    overflow-y: auto;
    padding: 0.75rem;
    padding-top: 3.5rem;
    box-shadow: 2px 0 8px rgba(0,0,0,0.06);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.sidebar-header h3 {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--muted-color);
}

.sidebar-new-chat {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

.sidebar-loading {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--muted-color);
    font-style: italic;
    padding: 0.5rem 0;
}

.sidebar-empty {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--muted-color);
    font-style: italic;
    padding: 0.5rem 0;
}

.sidebar-chat-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-chat-item {
    padding: 0.6rem 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.12s;
    margin-bottom: 2px;
}

.sidebar-chat-item:hover {
    background-color: #f5efe3;
}

.sidebar-chat-item.active {
    background-color: #f0e6cc;
    border-left: 3px solid var(--accent-color);
}

.sidebar-chat-title {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-chat-date {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--muted-color);
    margin-top: 0.15rem;
}
