/* =============================================================================
   TorahChat-PHP — Application Stylesheet
   Design goals: clean, readable, conversational. Follows a parchment-inspired
   warm neutral palette with strong typographic hierarchy.
============================================================================= */

/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
    --color-bg:           #f9f6f0;
    --color-bg-alt:       #f0ece2;
    --color-surface:      #ffffff;
    --color-border:       #d9d4c7;
    --color-text:         #2c2a25;
    --color-text-muted:   #7a7265;
    --color-accent:       #1a5c3a;
    --color-accent-light: #e6f2ec;
    --color-user-bubble:  #1a5c3a;
    --color-user-text:    #ffffff;
    --color-asst-bubble:  #ffffff;
    --color-asst-border:  #d9d4c7;
    --color-scrollbar:    #c8c2b4;

    --font-sans:   system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-serif:  Georgia, "Times New Roman", serif;
    --font-hebrew: "SBL Hebrew", "Ezra SIL", "Frank Ruehl CLM", serif;
    --font-mono:   "Cascadia Code", "Fira Code", monospace;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --sidebar-width: 260px;
    --source-panel-width: 340px;
    --input-max-h: 180px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

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

html, body { height: 100%; overflow: hidden; }
body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
}

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

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ── App shell ───────────────────────────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.logo { font-weight: 700; font-size: 1.05rem; color: var(--color-accent); }

#btn-new-chat {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .15s;
}
#btn-new-chat:hover { opacity: .85; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }

.nav-section { padding: 0 12px 16px; }
.nav-section h3 {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    padding: 6px 4px 4px;
}
.nav-section ul { list-style: none; }
.nav-section li a {
    display: block;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: .9rem;
    transition: background .12s;
}
.nav-section li a:hover {
    background: var(--color-border);
    text-decoration: none;
}

.sidebar-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--color-border);
    font-size: .78rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

/* ── Main area ───────────────────────────────────────────────────────────── */
#main {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
#chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Messages list */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb { background: var(--color-scrollbar); border-radius: 3px; }

/* Welcome screen */
.welcome {
    max-width: 600px;
    margin: 60px auto 0;
    padding: 0 24px;
    text-align: center;
}
.welcome h1 {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    color: var(--color-accent);
    margin-bottom: 10px;
}
.welcome p { color: var(--color-text-muted); margin-bottom: 28px; }

.example-prompts { display: flex; flex-direction: column; gap: 10px; }
.example-prompt {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    text-align: left;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: .92rem;
    transition: border-color .15s, box-shadow .15s;
}
.example-prompt:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

/* Individual messages */
.message {
    max-width: 720px;
    margin: 0 auto 16px;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
}

.message--user .message-content {
    align-self: flex-end;
    background: var(--color-user-bubble);
    color: var(--color-user-text);
    padding: 10px 15px;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
    max-width: 85%;
    white-space: pre-wrap;
    word-break: break-word;
}

.message--assistant .message-content {
    background: var(--color-asst-bubble);
    border: 1px solid var(--color-asst-border);
    padding: 14px 18px;
    border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
    box-shadow: var(--shadow-sm);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.7;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    padding: 0 2px;
}

.message-model {
    font-size: .75rem;
    color: var(--color-text-muted);
}

.btn-sources {
    font-size: .78rem;
    color: var(--color-accent);
    border: 1px solid var(--color-accent-light);
    background: var(--color-accent-light);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    transition: background .12s;
}
.btn-sources:hover { background: #c7e5d3; }

/* Citations (inline expansion) */
.citations {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.citation {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    background: var(--color-bg-alt);
}
.citation-ref {
    font-size: .82rem;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 6px;
}
.citation-text--en { font-size: .9rem; line-height: 1.6; }
.citation-text--he {
    font-family: var(--font-hebrew);
    font-size: 1rem;
    line-height: 1.8;
    margin-top: 6px;
    color: var(--color-text-muted);
}

/* Typing indicator */
.message--typing .message-content::after {
    content: "●●●";
    letter-spacing: 3px;
    animation: typing 1s steps(3, end) infinite;
}
@keyframes typing {
    0%, 100% { clip-path: inset(0 100% 0 0); }
    33%       { clip-path: inset(0 66% 0 0); }
    66%       { clip-path: inset(0 33% 0 0); }
}

/* ── Input area ──────────────────────────────────────────────────────────── */
#chat-form {
    flex-shrink: 0;
    padding: 12px 24px 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

#user-input {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font: inherit;
    font-size: .95rem;
    resize: none;
    max-height: var(--input-max-h);
    overflow-y: auto;
    line-height: 1.5;
    transition: border-color .15s;
    background: var(--color-bg);
    color: var(--color-text);
}
#user-input:focus { outline: none; border-color: var(--color-accent); }

#btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .15s;
}
#btn-send:disabled { opacity: .45; cursor: default; }
#btn-send:not(:disabled):hover { opacity: .88; }

.input-meta {
    display: flex;
    justify-content: space-between;
    padding: 4px 2px 0;
    font-size: .73rem;
    color: var(--color-text-muted);
}

.model-badge {
    font-size: .72rem;
    padding: 1px 6px;
    border-radius: 8px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
}

/* ── Source panel ────────────────────────────────────────────────────────── */
#source-panel {
    width: var(--source-panel-width);
    border-left: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}
#source-panel[hidden] { display: none; }

#source-panel header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
#source-panel h2 { font-size: 1rem; font-weight: 600; }
#btn-close-sources { font-size: 16px; color: var(--color-text-muted); }
#btn-close-sources:hover { color: var(--color-text); }

#source-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
    #sidebar { display: none; }
    #source-panel { display: none !important; }
}
