/* ─── Polek.ai — Polish Modernism ─── */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=Outfit:wght@300;400;500;600&display=swap');

:root {
    --bg: #fafaf8;
    --bg-card: #ffffff;
    --bg-input: #f5f4f0;
    --bg-sidebar: #1a1215;
    --bg-sidebar-hover: rgba(255,255,255,0.06);
    --border: #e8e5df;
    --border-sidebar: rgba(255,255,255,0.08);
    --text: #4a4540;
    --text-h: #1a1215;
    --text-muted: #9a9590;
    --text-sidebar: rgba(255,255,255,0.65);
    --text-sidebar-h: #ffffff;
    --accent: #DC143C;
    --accent-light: #e8365a;
    --accent-glow: rgba(220, 20, 60, 0.12);
    --accent-bg: rgba(220, 20, 60, 0.06);
    --user-bg: #DC143C;
    --assistant-bg: #ffffff;
    --tool-bg: rgba(220, 20, 60, 0.04);
    --shadow-sm: 0 1px 3px rgba(26,18,21,0.04);
    --shadow-md: 0 4px 20px rgba(26,18,21,0.06);
    --shadow-lg: 0 8px 40px rgba(26,18,21,0.08);
    --radius: 14px;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Outfit', system-ui, sans-serif;
}

/* ─── Dark mode ─── */

[data-theme="dark"] {
    --bg: #0f1014;
    --bg-card: #18191f;
    --bg-input: #1e1f27;
    --bg-sidebar: #0b0c0f;
    --bg-sidebar-hover: rgba(255,255,255,0.06);
    --border: #2a2b33;
    --border-sidebar: rgba(255,255,255,0.06);
    --text: #a0a0ab;
    --text-h: #e8e8ed;
    --text-muted: #6b6b78;
    --text-sidebar: rgba(255,255,255,0.55);
    --text-sidebar-h: #ffffff;
    --accent-glow: rgba(220, 20, 60, 0.18);
    --accent-bg: rgba(220, 20, 60, 0.08);
    --assistant-bg: #18191f;
    --tool-bg: rgba(220, 20, 60, 0.06);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.3);
}

[data-theme="dark"] body::before {
    opacity: 0.04;
}

[data-theme="dark"] .msg-assistant pre {
    background: #0b0c0f;
    border-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .msg-assistant pre code {
    color: rgba(255,255,255,0.85);
}

[data-theme="dark"] .msg-assistant code {
    border-color: var(--border);
}

[data-theme="dark"] .research-line:not(:last-child) {
    border-bottom-color: rgba(255,255,255,0.04);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Smooth theme transition */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

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

body {
    font: 400 14.5px/1.65 var(--font-body);
    color: var(--text);
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Subtle grain overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection {
    background: var(--accent);
    color: white;
}

/* ═══ LOGIN ═══ */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(220,20,60,0.06) 0%, transparent 60%),
        var(--bg);
    animation: loginFadeIn 0.8s ease-out;
}

@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 44px;
    width: 400px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

/* Red top accent stripe — echoes the Polish flag */
.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.login-card h1 {
    font-family: var(--font-display);
    color: var(--text-h);
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}

.login-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 0.02em;
}

.login-card input {
    width: 100%;
    padding: 13px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-h);
    font: 400 14px var(--font-body);
    margin-bottom: 14px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.login-card input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-card input::placeholder {
    color: var(--text-muted);
    font-weight: 300;
}

.login-card button {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font: 500 14.5px var(--font-body);
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    letter-spacing: 0.02em;
}

.login-card button:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(220, 20, 60, 0.25);
}

.login-card button:active {
    transform: translateY(0);
}

.error {
    color: var(--accent);
    font-size: 13px;
    margin-bottom: 12px;
    font-weight: 400;
}

/* ═══ CHAT LAYOUT ═══ */

.app {
    display: flex;
    height: 100vh;
}

/* ─── Sidebar ─── */

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Subtle red glow at top of sidebar */
.sidebar::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 120px;
    background: radial-gradient(ellipse, rgba(220,20,60,0.15), transparent 70%);
    pointer-events: none;
}

.sidebar-header {
    padding: 24px 20px 20px;
    position: relative;
    z-index: 1;
}

.sidebar-header h2 {
    font-family: var(--font-display);
    color: var(--text-sidebar-h);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.btn-new {
    width: 100%;
    padding: 10px 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 9px;
    font: 500 13.5px var(--font-body);
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    letter-spacing: 0.02em;
}

.btn-new:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(220, 20, 60, 0.3);
}

.btn-new:active {
    transform: translateY(0);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    position: relative;
    z-index: 1;
}

.session-item {
    padding: 11px 14px;
    border-radius: 9px;
    cursor: pointer;
    margin-bottom: 2px;
    font-size: 13px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-sidebar);
    transition: background 0.18s, color 0.18s;
}

.session-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-h);
}

.session-item.active {
    background: rgba(220, 20, 60, 0.15);
    color: white;
    font-weight: 500;
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-sidebar);
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-footer a {
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    transition: color 0.18s;
}

.sidebar-footer a:hover {
    color: var(--text-sidebar-h);
}

/* Theme toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-sidebar);
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-sidebar);
    font-size: 16px;
    line-height: 1;
    transition: color 0.18s, border-color 0.18s, background 0.18s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    color: var(--text-sidebar-h);
    border-color: rgba(255,255,255,0.15);
    background: var(--bg-sidebar-hover);
}

/* ─── Chat area ─── */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background:
        radial-gradient(ellipse 100% 40% at 50% 100%, rgba(220,20,60,0.03) 0%, transparent 60%),
        var(--bg);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    max-width: 900px;
    width: 100%;
    align-self: center;
}

/* ─── Messages ─── */

.msg {
    padding: 14px 18px;
    border-radius: var(--radius);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    flex-shrink: 0;
    animation: msgSlideIn 0.3s ease-out;
    width: fit-content;
    min-width: 60px;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-user {
    margin-left: auto;
    background: var(--user-bg);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(220, 20, 60, 0.18);
    font-weight: 400;
    max-width: 80%;
}

.msg-assistant {
    margin-right: auto;
    background: var(--assistant-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.msg-tool {
    margin-right: auto;
    background: var(--tool-bg);
    border: 1px solid rgba(220, 20, 60, 0.12);
    font-size: 12px;
    font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    max-width: 90%;
    color: var(--accent);
    border-radius: 10px;
}

.msg-thinking {
    margin-right: auto;
    color: var(--text-muted);
    font-style: italic;
    font-size: 13px;
    padding: 8px 0;
}

/* ═══ COLLAPSIBLE BLOCKS ═══ */

.msg-collapsible-block {
    margin-right: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    animation: msgSlideIn 0.3s ease-out;
    box-shadow: var(--shadow-sm);
}

.msg-collapsible-block.thinking-block {
    background: var(--accent-bg);
    border-color: rgba(220, 20, 60, 0.1);
}

.msg-collapsible-block.research-block {
    background: rgba(245, 158, 11, 0.04);
    border-color: rgba(245, 158, 11, 0.15);
}

.collapsible-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    transition: color 0.18s;
}

.collapsible-header:hover {
    color: var(--text-h);
}

.collapsible-icon {
    transition: transform 0.25s ease;
    flex-shrink: 0;
    font-size: 10px;
}

.collapsible-icon.expanded {
    transform: rotate(90deg);
}

.collapsible-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: collapsible-spin 0.75s linear infinite;
    flex-shrink: 0;
}

.research-block .collapsible-spinner {
    border-top-color: #f59e0b;
}

@keyframes collapsible-spin {
    to { transform: rotate(360deg); }
}

.collapsible-body {
    padding: 0 16px;
    max-height: calc(1.5em * 5 + 4px);
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
    scroll-behavior: smooth;
}

.collapsible-body.collapsed {
    max-height: calc(1.5em * 5 + 4px);
}

.collapsible-body.expanded {
    max-height: 60vh;
    padding-bottom: 12px;
}

.collapsible-body::-webkit-scrollbar { width: 4px; }
.collapsible-body::-webkit-scrollbar-track { background: transparent; }
.collapsible-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.collapsible-body::-webkit-scrollbar-thumb:hover { background: #bbb; }

.thinking-block .collapsible-body {
    font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
}

.research-line {
    padding: 4px 0;
    font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.research-line:not(:last-child) {
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

/* ═══ MARKDOWN IN ASSISTANT MESSAGES ═══ */

.msg-assistant p { margin: 0 0 8px; }
.msg-assistant p:last-child { margin-bottom: 0; }

.msg-assistant h2, .msg-assistant h3, .msg-assistant h4 {
    color: var(--text-h);
    margin: 14px 0 6px;
    font-weight: 600;
    font-family: var(--font-display);
}
.msg-assistant h2 { font-size: 19px; }
.msg-assistant h3 { font-size: 16.5px; }
.msg-assistant h4 { font-size: 14.5px; }

.msg-assistant strong { color: var(--text-h); font-weight: 600; }
.msg-assistant em { font-style: italic; color: var(--text-muted); }

.msg-assistant code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    font-size: 13px;
    border: 1px solid var(--border);
}

.msg-assistant pre {
    background: var(--bg-sidebar);
    border-radius: 10px;
    padding: 14px 16px;
    margin: 10px 0;
    overflow-x: auto;
    border: 1px solid rgba(255,255,255,0.05);
}

.msg-assistant pre code {
    background: none;
    padding: 0;
    border: none;
    font-size: 13px;
    line-height: 1.6;
    color: rgba(255,255,255,0.85);
}

.msg-assistant ul, .msg-assistant ol {
    margin: 6px 0;
    padding-left: 22px;
}

.msg-assistant li { margin: 3px 0; }

.msg-assistant a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid rgba(220, 20, 60, 0.25);
    transition: border-color 0.18s;
}

.msg-assistant a:hover {
    border-color: var(--accent);
}

/* ═══ INPUT AREA ═══ */

.input-area {
    padding: 20px 28px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(26,18,21,0.03);
}

#chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

#input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-h);
    font: 400 14.5px var(--font-body);
    resize: none;
    outline: none;
    max-height: 150px;
    transition: border-color 0.25s, box-shadow 0.25s;
}

#input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--bg-card);
}

#input::placeholder {
    color: var(--text-muted);
    font-weight: 300;
}

#send-btn {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font: 500 14.5px var(--font-body);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    letter-spacing: 0.02em;
}

#send-btn:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(220, 20, 60, 0.25);
}

#send-btn:active {
    transform: translateY(0);
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ═══ SCROLLBAR ═══ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #ccc; }

/* ═══ RESPONSIVE ═══ */

@media (max-width: 768px) {
    .sidebar { display: none; }
    .messages { padding: 20px 16px; }
    .input-area { padding: 14px 16px 18px; }
    .messages { max-width: 100%; }
}
