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

:root {
    --brand:      #0BBFBF;
    --brand-dark: #0A9EA0;
    --bg:         #f5f7fa;
    --card-bg:    #ffffff;
    --text:       #1a1a2e;
    --muted:      #6b7280;
    --border:     #e5e7eb;
    --error-bg:   #fff1f1;
    --error-text: #c0392b;
    --radius:     10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* ─── Layout ────────────────────────────────────────────────────── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

main.container {
    flex: 1;
    padding-top: 3rem;
    padding-bottom: 3rem;
}

/* ─── Header ────────────────────────────────────────────────────── */
.site-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--brand);
    text-decoration: none;
}

nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color .2s;
}

nav a:hover { color: var(--brand); }

.user-greeting {
    font-size: 0.9rem;
    color: var(--muted);
}

/* ─── Footer ────────────────────────────────────────────────────── */
footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-logout {
    display: inline-block;
    padding: 0.6rem 1.3rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background .2s, transform .1s;
}

.btn-primary {
    background: var(--brand);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary {
    background: transparent;
    border: 2px solid var(--brand);
    color: var(--brand);
}
.btn-secondary:hover { background: var(--brand); color: #fff; }

.btn-logout {
    background: transparent;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
}
.btn-logout:hover { color: var(--error-text); }

.btn-full { width: 100%; text-align: center; }

/* ─── Hero (index) ──────────────────────────────────────────────── */
.hero {
    text-align: center;
    padding: 5rem 1rem;
}

.hero h1 {
    font-size: 2.75rem;
    font-weight: 800;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero p {
    font-size: 1.15rem;
    color: var(--muted);
    max-width: 520px;
    margin: 0 auto 2rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ─── Auth Card (login/register/account) ────────────────────────── */
.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 4px 24px rgba(0,0,0,.06);
}

.auth-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--muted);
    margin-bottom: 1.75rem;
    font-size: 0.95rem;
}

/* ─── Form ──────────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 1.1rem;
}

label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"] {
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}

input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(11,191,191,.15);
}

/* ─── Alerts ────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #f5c6cb;
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.auth-footer a { color: var(--brand); text-decoration: none; }

/* ─── Account info ──────────────────────────────────────────────── */
.account-info {
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    overflow: hidden;
    margin-top: 1.5rem;
}

.info-row {
    display: flex;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    gap: 1rem;
}

.info-row:last-child { border-bottom: none; }

.info-label {
    font-weight: 600;
    min-width: 80px;
    color: var(--muted);
}

/* ─── Journal list ──────────────────────────────────────────────── */
.journal-list-wrapper {
    max-width: 720px;
    margin: 0 auto;
}

.journal-list-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.journal-list-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.journal-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.journal-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
    transition: border-color .2s, box-shadow .2s, transform .1s;
}

.journal-card:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 16px rgba(11,191,191,.1);
    transform: translateY(-1px);
}

.journal-card-date {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--brand);
    margin-bottom: 0.5rem;
}

.journal-card-preview {
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    /* Clamp to ~4 lines */
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.journal-card-link {
    font-size: 0.85rem;
    color: var(--brand);
    font-weight: 600;
}

.journal-empty {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--muted);
}

.journal-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.journal-empty h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.journal-empty p {
    font-size: 0.95rem;
    max-width: 400px;
    margin: 0 auto;
}

.journal-empty a { color: var(--brand); text-decoration: none; }
.journal-empty a:hover { text-decoration: underline; }

/* ─── Journal detail ────────────────────────────────────────────── */
.journal-detail-wrapper {
    max-width: 720px;
    margin: 0 auto;
}

.journal-back-link {
    display: inline-block;
    font-size: 0.875rem;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 1.5rem;
    transition: color .2s;
}

.journal-back-link:hover { color: var(--brand); }

.journal-detail-header {
    margin-bottom: 1.5rem;
}

.journal-detail-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.journal-detail-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0,0,0,.06);
}

.journal-detail-content {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── App shell (chatbot page full-viewport layout) ─────────────── */
body.app-shell {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
    /* Override the default flex-column set on body */
    min-height: unset;
}

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-top {
    padding: 1.25rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--brand);
    text-decoration: none;
    display: block;
}

.sidebar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.75rem 0 0;
}

.sidebar-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    padding: 0 1rem 0.4rem;
}

.sidebar-journals {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-bottom: 0.5rem;
}

.sidebar-entry {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: var(--text);
    text-decoration: none;
    border-radius: calc(var(--radius) - 4px);
    margin: 0 0.4rem;
    transition: background .15s, color .15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-entry:hover {
    background: var(--bg);
    color: var(--brand);
}

.sidebar-empty {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: var(--muted);
    font-style: italic;
}

.sidebar-bottom {
    border-top: 1px solid var(--border);
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sidebar-user {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-link {
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
    transition: color .2s;
}

.sidebar-link:hover { color: var(--brand); }

/* ─── Chat main area ────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    position: relative;
}

.chat-journal-banner {
    background: #f0fdf4;
    border-bottom: 1px solid #86efac;
    color: #166534;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    text-align: center;
    display: none;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* Center the message column on wide screens */
    align-items: stretch;
}

/* Inner message bubbles — reuse existing .chat-message styles */
.chat-message {
    max-width: 680px;
    width: fit-content;
    padding: 0.65rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--brand);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.chat-message.bot {
    align-self: flex-start;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 3px;
}

/* ─── Chat input (centered, pinned to bottom) ───────────────────── */
.chat-input-area {
    flex-shrink: 0;
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.chat-input-wrapper {
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: row;
    gap: 0.65rem;
    align-items: stretch;
}

.chat-input-box {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 0.65rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    transition: border-color .2s, box-shadow .2s;
}

.chat-input-box:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(11,191,191,.12);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--text);
    outline: none;
    padding: 0.2rem 0.25rem;
    resize: none;
    overflow-y: hidden;
    line-height: 1.5;
    max-height: 10rem;
    font-family: inherit;
}

.chat-send-btn {
    padding: 0.45rem 1.1rem;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.chat-save-btn {
    padding: 0.45rem 1.1rem;
    font-size: 0.9rem;
    flex-shrink: 0;
    align-self: stretch;
}

.chat-hint {
    font-size: 0.78rem;
    color: var(--muted);
    text-align: center;
}

/* ─── Narrow-screen: hide sidebar, stack save button below input ── */
@media (max-width: 767px) {
    .sidebar { display: none; }

    .chat-input-wrapper {
        flex-direction: column;
    }

    .chat-save-btn {
        width: 100%;
        text-align: center;
    }
}

/* ─── Initial state: center input vertically on large screens ──── */
@media (min-width: 768px) {
    .chat-main--empty {
        justify-content: center;
    }

    .chat-main--empty .chat-messages {
        flex: 0 0 auto;
    }
}

/* ─── Mobile bottom navigation bar ──────────────────────────────── */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    z-index: 200;
    flex-direction: row;
    align-items: stretch;
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--muted);
    transition: color .2s;
}

.mobile-nav-item--active,
.mobile-nav-item:hover {
    color: var(--brand);
}

.mobile-nav-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.mobile-nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

@media (max-width: 767px) {
    .mobile-nav { display: flex; }

    /* Shrink app-shell so chat input clears the mobile nav.
       100dvh tracks the actual visible viewport on iOS Safari;
       100vh is the static fallback for older browsers. */
    body.app-shell {
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
    }

    /* Push base-layout content above the fixed mobile nav */
    body:not(.app-shell) main.container { padding-bottom: 60px; }
}
