/* Jinnie Chat CSS — Horizon light theme, mobile responsive, dark mode */
:root {
    --bg: #f1f3f5;
    --surface: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --text: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --user-bubble: #eff6ff;
    --assistant-bubble: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 24px;
    --btn-bg: #e2e8f0;
    --surface-alt: #f8fafc;
    --btn-border: #cbd5e1;
    --btn-hover: #cbd5e1;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #151c2c;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #10b981;
    --danger: #ef4444;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --border: #1e293b;
    --user-bubble: #1e293b;
    --assistant-bubble: #151c2c;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
    --btn-bg: #1e293b;
    --surface-alt: #101726;
    --btn-border: #334155;
    --btn-hover: #334155;
}


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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===== Button helpers ===== */
.btn-round {
    background: var(--btn-bg) !important;
    border: none !important;
    color: var(--text-secondary) !important;
    border-radius: 50% !important;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
}
.btn-round:hover { background: var(--btn-hover) !important; color: var(--text) !important; transform: scale(1.05); }
.btn-round:active { transform: scale(0.95); }

.btn-square {
    background: var(--btn-bg) !important;
    border: none !important;
    color: var(--text-secondary) !important;
    border-radius: 8px !important;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
}
.btn-square:hover { background: var(--btn-hover) !important; color: var(--text) !important; transform: scale(1.05); }
.btn-square:active { transform: scale(0.95); }

.btn-pill {
    background: var(--btn-bg) !important;
    border: none !important;
    color: var(--text-secondary) !important;
    border-radius: var(--radius-pill) !important;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-weight: 500;
    padding: 6px 16px;
}
.btn-pill:hover { background: var(--btn-hover) !important; color: var(--text) !important; }
.btn-pill:active { transform: scale(0.98); }

/* ===== Layout ===== */
.layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ===== LEFT SIDEBAR (Desktop) ===== */
.history-pane {
    width: 300px;
    background: linear-gradient(180deg, var(--bg) 0%, var(--surface-alt) 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s ease;
    z-index: 1000;
    flex-shrink: 0;
    overflow: hidden;
}

.history-pane.mobile-hidden {
    transform: translateX(-100%);
    position: absolute;
    height: 100%;
}

/* Sidebar footer pins to bottom, never compresses */
.sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.history-pane.collapsed {
    width: 48px;
    overflow: hidden;
}

.history-pane.collapsed .history-head,
.history-pane.collapsed .history-body,
.history-pane.collapsed .history-search {
    display: none;
}

/* History head — never compresses */
.history-head {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.history-head button#open-mobile-menu {
    display: flex;
    padding: 6px;
    border: none;
    background: transparent;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    min-width: 32px;
    min-height: 32px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.history-head button#open-mobile-menu:hover { background: var(--user-bubble); }

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.history-head button.new-chat-btn {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 8px 12px;
    font-size: 13px;
    transition: all 0.2s;
    cursor: pointer;
}
.history-head button.new-chat-btn:hover {
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    border-color: var(--text-secondary);
}

/* Search — never compresses */
.history-search {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.history-search input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.history-search input:focus { border-color: var(--primary); }

/* History body — scrollable session list */
.history-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-secondary) transparent;
}
.history-body::-webkit-scrollbar { width: 4px; }
.history-body::-webkit-scrollbar-track { background: transparent; }
.history-body::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 2px; }
.history-body::-webkit-scrollbar-thumb:hover { background: var(--text); }

/* History turns */
.history-turn {
    margin-bottom: 2px;
    background: transparent;
    padding: 10px 12px;
    padding-right: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.4;
    transition: background 0.15s ease;
    min-height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: none;
    position: relative;
}
.history-turn:hover { background: rgba(0,0,0,0.04); }
.history-turn:active, .history-turn.active { background: rgba(0,0,0,0.06); }
.history-turn.active { border-left: 3px solid var(--primary); padding-left: 9px; }

.history-turn .turn-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-turn .turn-time {
    font-size: 11px;
    margin-top: 4px;
    color: var(--text-secondary);
}

/* Turn action buttons (hover) */
.history-turn .turn-actions {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    gap: 2px;
}
.history-turn:hover .turn-actions { display: flex; }

.turn-action-btn {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
.turn-action-btn:hover { background: var(--btn-bg); color: var(--text); }
.turn-action-btn.publish-btn svg { width: 11px; height: 11px; }

/* Sidebar footer */
.sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.sidebar-footer-btn {
    flex-grow: 1;
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.15s ease;
}
.sidebar-footer-btn:hover { background: var(--surface-alt); color: var(--text); }

.sidebar-logout-btn { color: var(--danger); }
.sidebar-logout-btn:hover { background: rgba(220,38,38,0.08); border-color: var(--danger); }
	.sidebar-footer-btn.sidebar-logout-btn { min-height: 34px; padding: 6px; }

/* User menu in sidebar footer */
.sidebar-user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    flex-grow: 1;
}
.sidebar-user-menu:hover { background: var(--surface-alt); }

.sidebar-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
    text-align: left;
}
.sidebar-user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ===== OVERLAY ===== */
#overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 998;
    cursor: pointer;
}
#overlay.visible { display: block; }

/* ===== MAIN CONTENT ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    overflow: hidden;
}

/* ===== UPPER NAV BAR ===== */
.system-status {
    font-size: 14px;
    color: var(--text-secondary);
    background: transparent;
    padding: 8px 12px;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    flex-shrink: 0;
}
.system-status > div { display: flex; align-items: center; gap: 6px; }

.system-status button#open-mobile-menu {
    margin-right: 4px;
}


.system-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
    cursor: pointer;
    background: none;
    border: none;
}
.system-link:hover { background: var(--user-bubble); color: var(--text); }

/* ===== AVATAR CONTAINER ===== */
.user-avatar-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.user-avatar {
    width: 34px !important;
    height: 34px !important;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
}
.user-avatar:hover { background: var(--btn-hover); }

.avatar-dropdown {
    display: none;
    position: absolute;
    top: 48px;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 2000;
    overflow: hidden;
}
.avatar-dropdown.show { display: block; }

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.1s;
    min-height: 44px;
    white-space: nowrap;
}
.dropdown-item:hover { background: var(--user-bubble); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ===== CHAT CONTAINER ===== */
.chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Anonymous mode (splash) */
.chat-container.anonymous-mode {
    justify-content: flex-start;
}
.chat-container:not(.anonymous-mode) #story-showcase { display: none !important; }

/* ===== MESSAGES ===== */
.messages {
    background: var(--bg);
    flex-grow: 1;
    padding: 16px;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-container.anonymous-mode .messages {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    padding-top: clamp(32px, 10vh, 100px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-container.anonymous-mode.anonymous-chat-started .messages {
    flex-grow: 1;
    padding-top: 8px;
}

.message-row {
    display: flex;
    flex-direction: row;
    width: 100%;
    margin: 4px 0;
}
.message-row.user {
    justify-content: flex-end;
}
.message-row.assistant {
    justify-content: flex-start;
}

.message {
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    box-sizing: border-box;
    max-width: 80%;
    margin-bottom: 6px;
}
.message.user {
    background-color: var(--primary);
    color: #ffffff;
    border: none;
}
.message.user p { color: #ffffff; margin: 4px 0; }
.message.user p:first-child { margin-top: 0; }
.message.user p:last-child { margin-bottom: 0; }
.message.user code:not(pre code) {
    background: rgba(255,255,255,0.2);
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}
.message.user pre {
    background: rgba(0,0,0,0.2);
    color: #ffffff;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.message.user pre code { color: #ffffff; }
.message.user a { color: #93c5fd; text-decoration: none; }
.message.user a:hover { text-decoration: underline; }
.message.user blockquote {
    border-left-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.1);
}
.message.assistant {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.message p { margin: 6px 0; }
.message h1, .message h2, .message h3 { margin: 12px 0 6px; font-weight: 600; line-height: 1.3; }
.message h1 { font-size: 1.5em; }
.message h2 { font-size: 1.3em; }
.message h3 { font-size: 1.15em; }
.message ul, .message ol { margin: 8px 0; padding-left: 24px; }
.message li { margin: 3px 0; line-height: 1.6; }
.message ul { list-style-type: disc; }
.message ol { list-style-type: decimal; }
.message code:not(pre code) {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

.message pre {
    background: var(--code-bg);
    color: var(--text);
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.message pre code { color: inherit; font-size: 12px; line-height: 1.5; }

.message blockquote {
    margin: 8px 0;
    padding: 8px 14px;
    border-left: 4px solid var(--primary);
    background: rgba(37,99,235,0.06);
    border-radius: 0 6px 6px 0;
}

.message a { color: var(--primary); text-decoration: none; }
.message a:hover { text-decoration: underline; }
.message hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ===== INPUT AREA ===== */
.input-area {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    width: 100%;
}

.chat-container.anonymous-mode .input-area {
    width: min(760px, 100%);
    margin: 0 auto;
    padding: 8px 0;
    order: 1;
}

.input-area input[type="text"] {
    flex-grow: 1;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    font-size: 16px;
    height: 28px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 28px;
}
.input-area input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.input-area input[type="text"]::placeholder { color: var(--text-secondary); }

.input-area button {
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    background: var(--btn-bg);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
    height: 28px;
    min-width: 28px;
    flex-shrink: 0;
}
.input-area button:hover { background: var(--btn-hover); color: var(--text); }
.input-area button:active { transform: scale(0.95); }

.input-area button.send-btn {
    background: var(--primary);
    color: white;
}
.input-area button.send-btn:hover { background: var(--primary-hover); }

/* Upload/attach button */
.attach-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.attach-btn:hover { background: var(--btn-hover); color: var(--text); transform: scale(1.05); }
.attach-btn:active { transform: scale(0.95); }

.input-area button.attach-btn { box-shadow: none; }

/* ===== FEATURE CARDS ===== */
#feature-showcase {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0 16px;
}
#feature-showcase > div:first-child {
    text-align: center;
    margin-bottom: 24px;
}
#feature-showcase > div:first-child h1 {
    font-size: 42px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.04em;
    margin-bottom: 8px;
}
#feature-showcase > div:first-child p {
    font-size: 16px;
    color: var(--text-secondary);
}

#feature-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 14px !important;
    max-width: 800px !important;
    width: 100% !important;
    margin: 0 auto 28px !important;
}

.feature-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 12px !important;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.feature-card:hover {
    border-color: var(--primary);
    background: var(--user-bubble);
}
.feature-card:active { transform: translateY(0); }
.feature-card .card-icon { font-size: 24px !important; margin-bottom: 8px !important; }
.feature-card .card-title { font-size: 13px !important; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.feature-card .card-desc { font-size: 11px !important; color: var(--text-secondary); line-height: 1.4; }

/* ===== ANONYMOUS UPGRADE CARD ===== */
.anonymous-upgrade-card {
    width: min(520px, 92%);
    align-self: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 20px !important;
    margin: 20px auto !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    text-align: center;
}
.anonymous-upgrade-card::before {
    content: '';
    display: block;
    width: 40px;
    height: 3px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--primary), var(--success));
    margin: 0 auto 16px;
}
.anonymous-upgrade-card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.anonymous-upgrade-card p { margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.anonymous-upgrade-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.anonymous-upgrade-actions button {
    border-radius: var(--radius-pill);
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    height: 36px;
}
.anonymous-upgrade-actions button:first-child {
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(37,99,235,0.2);
}
.anonymous-upgrade-actions button:first-child:hover { box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.anonymous-upgrade-actions .secondary-action {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.anonymous-upgrade-actions .secondary-action:hover { background: var(--user-bubble); }

/* ===== AUTH MODAL (Login/Register) ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    cursor: pointer;
}
.modal-overlay.visible { display: block; }

#auth-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}
#auth-modal.visible { display: flex; }

#auth-modal .modal {
    background: var(--surface);
    padding: 32px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    position: relative;
}
#auth-modal .modal h2 { color: var(--text); margin-bottom: 4px; }
#auth-modal .subtitle { color: var(--text-secondary); margin-bottom: 20px; font-size: 14px; }

#auth-modal .form-group { margin-bottom: 16px; text-align: left; }
#auth-modal .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
#auth-modal .form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: var(--surface);
    color: var(--text);
    min-height: 48px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
#auth-modal .form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

#auth-modal .btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 12px;
    min-height: 48px;
    transition: background 0.15s;
}
#auth-modal .btn-primary:hover { background: var(--primary-hover); }
#auth-modal .btn-primary:disabled { opacity: 0.6; cursor: wait; }

#auth-modal .error-msg {
    color: var(--danger);
    margin-top: 10px;
    font-size: 13px;
    min-height: 18px;
    display: none;
}
#auth-modal .error-msg.visible { display: block; }

#auth-modal .success-msg {
    color: #28a745;
    margin-top: 10px;
    font-size: 13px;
    display: none;
}

#auth-modal .switch-text {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}
#auth-modal .switch-text a { color: var(--primary); cursor: pointer; }

#auth-modal .modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
}

/* ===== SETTINGS MODAL ===== */
#settings-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}
#settings-modal.visible { display: flex; }

.settings-modal-box {
    background: var(--surface);
    padding: 0;
    border-radius: 16px;
    width: 92%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}
.settings-modal-box .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.settings-modal-box .modal-header h2 { margin: 0; font-size: 18px; color: var(--text); }
.settings-modal-box .close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
}

.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}
.settings-tab {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.settings-content { padding: 20px; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }

.settings-panel .form-group { margin-bottom: 16px; }
.settings-panel label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.settings-panel .help-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.settings-panel input[type="text"],
.settings-panel input[type="email"],
.settings-panel input[type="password"],
.settings-panel textarea,
.settings-panel select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.settings-panel input:focus,
.settings-panel textarea:focus,
.settings-panel select:focus {
    border-color: var(--primary);
}

.avatar-upload {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.avatar-upload-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--btn-bg);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.avatar-upload-btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}

/* ===== STORY MODALS ===== */
#publish-story-modal, #manage-stories-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}
#publish-story-modal.visible, #manage-stories-modal.visible { display: flex; }

.story-editor-box {
    background: var(--surface);
    border-radius: 16px;
    width: 92%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}
.story-editor-box .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.story-editor-box .modal-header h2 { margin: 0; font-size: 18px; }
.story-editor-box .close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.story-form { padding: 20px; }
.story-form .form-group { margin-bottom: 16px; }
.story-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.story-form input[type="text"],
.story-form textarea,
.story-form input[type="url"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    outline: none;
}
.story-form input:focus, .story-form textarea:focus { border-color: var(--primary); }
.story-form textarea { resize: vertical; min-height: 80px; }

.story-cover-preview {
    width: 100%;
    height: 120px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    background: var(--surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 13px;
    overflow: hidden;
    margin-top: 8px;
}
.story-cover-preview img { width: 100%; height: 100%; object-fit: cover; }

.story-checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.story-checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}
.story-checkbox-group label { margin: 0; font-weight: 400; }

.story-submit-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 8px;
}
.story-submit-btn:hover { background: var(--primary-hover); }

/* Manage stories list */
#stories-list { padding: 16px; }
.story-list-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 8px;
    align-items: center;
    background: var(--surface);
}
.story-list-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: var(--surface-alt);
    flex-shrink: 0;
    overflow: hidden;
}
.story-list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.story-list-info { flex: 1; min-width: 0; }
.story-list-info h4 { font-size: 14px; margin: 0 0 4px; color: var(--text); }
.story-list-info p { font-size: 12px; margin: 0; color: var(--text-secondary); }
.story-list-actions { display: flex; gap: 4px; }
.story-list-actions button {
    padding: 4px 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
}
.story-list-actions button:hover { background: var(--surface-alt); color: var(--text); }

/* ===== STORIES DIRECTORY ===== */
.stories-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px;
    flex-grow: 1;
    overflow-y: auto;
}
.stories-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.stories-header h1 { font-size: 24px; font-weight: 700; color: var(--text); }
.stories-header .back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.stories-header .back-link:hover { text-decoration: underline; }

.story-group { margin-bottom: 32px; }
.story-group h2 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.story-group a.user-profile-link { color: var(--primary); text-decoration: none; font-weight: 500; }

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.story-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    min-height: 140px;
}
.story-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }
.story-card-cover {
    width: 100%;
    height: 160px;
    background: var(--surface-alt);
    overflow: hidden;
}
.story-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.story-card-body { padding: 14px; background: var(--surface-alt); }
.story-card-body h3 { font-size: 15px; font-weight: 600; margin: 0 0 6px; color: var(--text); }
.story-card-body p { font-size: 13px; color: var(--text-secondary); margin: 0 0 8px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.story-card-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.story-tag { font-size: 11px; padding: 2px 8px; border-radius: 9999px; background: var(--user-bubble); color: var(--primary); font-weight: 500; }
.story-card-footer { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-secondary); }

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    font-size: 14px;
    color: var(--text);
    min-width: 200px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ===== ATTACHMENT PREVIEW ===== */
#attachment-preview {
    display: none;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
#attachment-preview.visible {
    display: block;
}
#attach-processing .typing-dots span {
    animation: blink 1.4s infinite ease-in-out;
}
#attach-processing .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
#attach-processing .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

/* ===== RESPONSIVE (Mobile) ===== */
@media (max-width: 600px) {
    .history-pane {
        position: absolute;
        height: 100%;
        left: 0;
        top: 0;
        width: 80%;
        max-width: 280px;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
        z-index: 1000;
    }
    .history-pane.mobile-hidden { transform: translateX(-100%); }

    /* Show mobile menu button on mobile, hide on desktop */
    #mobile-menu-btn {
        display: inline-flex;
    }

    @media (min-width: 769px) {
        #mobile-menu-btn {
            display: none;
        }
    }

    .system-status { font-size: 14px; padding: 4px 8px; }

    .chat-container { padding: 8px; max-width: 100%; }
    .chat-container.anonymous-mode .messages { padding-top: clamp(24px, 8vh, 60px); }

    .user-avatar-container { width: 36px !important; height: 24px !important; }
    .user-avatar {
        width: 36px !important;
        height: 24px !important;
        border-radius: 12px !important;
        background: var(--btn-bg) !important;
        border: 1px solid var(--btn-border) !important;
        font-size: 11px !important;
    }

    .avatar-dropdown { top: 40px; right: 4px; min-width: 180px; }

    .input-area { flex-wrap: wrap; gap: 6px; }
    .input-area input[type="text"] { width: calc(100% - 36px); }

    .message { max-width: 95%; font-size: 14px; }

    #feature-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .stories-grid { grid-template-columns: 1fr !important; }

    .settings-modal-box { width: 96%; }
    .story-editor-box { width: 96%; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text); }

/* ===== Loading state ===== */
.history-turn.loading-turn {
    color: var(--text-secondary);
    font-style: italic;
    padding: 10px 12px;
}
