/* === Ahlsell Brand Fonts === */

@font-face { font-family: 'Ahlsell Slab'; src: url('/fonts/AhlsellSlabExtraBold.otf') format('opentype'); font-weight: 800; }
@font-face { font-family: 'Ahlsell Slab'; src: url('/fonts/AhlsellSlab-Bold.otf') format('opentype'); font-weight: 700; }
@font-face { font-family: 'Ahlsell Slab'; src: url('/fonts/AhlsellSlab-Medium.otf') format('opentype'); font-weight: 500; }
@font-face { font-family: 'Ahlsell Sans'; src: url('/fonts/AhlsellSans-Regular.otf') format('opentype'); font-weight: 400; }
@font-face { font-family: 'Ahlsell Sans'; src: url('/fonts/AhlsellSans-Medium.otf') format('opentype'); font-weight: 500; }
@font-face { font-family: 'Ahlsell Sans'; src: url('/fonts/AhlsellSans-SemiBold.otf') format('opentype'); font-weight: 600; }
@font-face { font-family: 'Ahlsell Sans'; src: url('/fonts/AhlsellSans-Bold.otf') format('opentype'); font-weight: 700; }
@font-face { font-family: 'Ahlsell Sans'; src: url('/fonts/AhlsellSans-Light.otf') format('opentype'); font-weight: 300; }

/* === Tokens === */

:root {
    --bg-base: #0B1623;
    --bg-surface: #0f1d2e;
    --bg-elevated: #152638;
    --bg-hover: #1a2e44;
    --bg-input: #101d2d;

    --border: rgba(255, 255, 255, 0.06);
    --border-focus: #0073B6;

    --ahlsell-blue: #0073B6;
    --navy: #023D62;
    --cyan: #009FE3;
    --orange: #FF5900;

    --text-primary: #e8ecf0;
    --text-secondary: #8899aa;
    --text-muted: #556677;

    --font-heading: 'Ahlsell Slab', Arial, sans-serif;
    --font-body: 'Ahlsell Sans', Arial, sans-serif;

    --radius: 12px;
    --radius-lg: 16px;

    --sidebar-width: 260px;
}

/* === Reset === */

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

body {
    font-family: var(--font-body);
    background: var(--bg-base);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* === Screens === */

.screen { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.screen[hidden] { display: none; }

/* === Login === */

#login-screen {
    background: var(--bg-base);
    justify-content: center;
    align-items: center;
    position: relative;
}

#login-screen::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 115, 182, 0.08) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.login-card {
    position: relative;
    z-index: 1;
    background: none;
    border: none;
    padding: 3rem 2.5rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    object-fit: contain;
}

.logo-img--login {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

.logo-img--topbar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.logo-img--welcome {
    width: 80px;
    height: 80px;
    border-radius: 50%;
}

.logo-img--avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.login-logo-text {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-primary);
}

.login-title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.error {
    color: var(--orange);
    font-size: 0.85rem;
    margin-top: 1rem;
    font-weight: 500;
}

.error-message {
    color: var(--orange);
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

/* === Buttons === */

.btn-login {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--ahlsell-blue);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0.8rem 1.8rem;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-login:hover {
    background: var(--cyan);
    transform: translateY(-1px);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

/* === Topbar === */

.topbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.topbar-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.topbar-version {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 400;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* === Avatars === */

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.avatar--user-sm {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.avatar--user {
    background: var(--ahlsell-blue);
    color: white;
}

.avatar--agent {
    background: linear-gradient(135deg, var(--ahlsell-blue), var(--cyan));
    color: white;
    padding: 7px;
}

.avatar--agent svg {
    width: 100%;
    height: 100%;
}

/* === Chat Main === */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
}

.messages-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Welcome */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 1rem 2rem;
    gap: 1rem;
}

.welcome h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-primary);
}

.welcome p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* === Message Rows === */

.msg-row {
    display: flex;
    gap: 0.75rem;
    animation: fadeIn 0.3s ease;
}

.msg-row--user {
    flex-direction: row-reverse;
}

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

.msg-content {
    min-width: 0;
    max-width: 80%;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.msg-row--user .msg-meta {
    flex-direction: row-reverse;
}

.msg-name {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.msg-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.msg-bubble {
    padding: 0.8rem 1rem;
    line-height: 1.6;
    font-size: 0.88rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.msg-row--agent .msg-bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px var(--radius) var(--radius) var(--radius);
    color: var(--text-primary);
}

.msg-row--user .msg-bubble {
    background: var(--ahlsell-blue);
    border-radius: var(--radius) 4px var(--radius) var(--radius);
    color: white;
}

.msg-row--loading .msg-bubble {
    color: var(--text-muted);
    font-style: italic;
    border: 1px dashed rgba(0, 115, 182, 0.3);
    background: rgba(0, 115, 182, 0.05);
}

.loading-dots::after {
    content: "";
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
}

/* === Markdown in agent bubbles — aggressive reset === */

/* Kill ALL default margins inside bubbles */
.msg-bubble * { margin: 0; padding: 0; }

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    margin-top: 0.5em;
}

.msg-bubble h1 { font-size: 1.05rem; }
.msg-bubble h2 { font-size: 0.95rem; }
.msg-bubble h3 { font-size: 0.9rem; }

.msg-bubble p + p,
.msg-bubble ul + p,
.msg-bubble ol + p,
.msg-bubble blockquote + p,
.msg-bubble pre + p,
.msg-bubble table + p { margin-top: 0.4em; }

.msg-bubble ul, .msg-bubble ol {
    padding-left: 1.3rem;
}

.msg-bubble p + ul,
.msg-bubble p + ol { margin-top: 0.2em; }

.msg-bubble li + li { margin-top: 0.15em; }

/* Remove empty <p> tags that marked.js inserts around lists */
.msg-bubble li > p { display: contents; }

.msg-bubble table {
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0.4em;
    width: 100%;
    font-size: 0.85rem;
}

.msg-bubble th, .msg-bubble td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.3rem 1.5rem 0.3rem 0;
    text-align: left;
    vertical-align: top;
}

.msg-bubble th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.msg-bubble code {
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.82rem;
}

.msg-bubble pre {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-top: 0.3em;
}

.msg-bubble pre code { background: none; padding: 0; }

.msg-bubble blockquote {
    border-left: 3px solid var(--ahlsell-blue);
    padding-left: 0.7rem;
    margin-top: 0.3em;
    color: var(--text-secondary);
}

.msg-bubble hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 0.5em 0;
}

.msg-bubble strong { color: var(--text-primary); }

.msg-bubble a { color: var(--cyan); text-decoration: none; }
.msg-bubble a:hover { text-decoration: underline; }

.msg-bubble > *:first-child {
    margin-top: 0;
}

.msg-bubble > *:last-child {
    margin-bottom: 0;
}

/* Collapsible sections */
.msg-bubble details {
    margin-top: 0.3em;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

.msg-bubble summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.2rem 0;
}

.msg-bubble details[open] > summary {
    margin-bottom: 0.3em;
}

/* Task list checkboxes */
.msg-bubble input[type="checkbox"] {
    margin-right: 0.4rem;
    accent-color: var(--ahlsell-blue);
}

/* Quick reply buttons */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5em;
}

.quick-reply {
    background: rgba(0, 115, 182, 0.15);
    color: var(--cyan);
    border: 1px solid rgba(0, 159, 227, 0.3);
    border-radius: 20px;
    padding: 0.35rem 0.9rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.quick-reply:hover {
    background: rgba(0, 115, 182, 0.3);
    border-color: var(--cyan);
}

/* Copyable values */
.copyable {
    cursor: pointer;
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-family: monospace;
    position: relative;
    transition: background 0.15s;
}

.copyable:hover {
    background: rgba(0, 115, 182, 0.2);
}

.copy-icon {
    width: 12px;
    height: 12px;
    margin-left: 0.2rem;
    vertical-align: middle;
    opacity: 0.5;
}

.copyable:hover .copy-icon { opacity: 1; }

.copyable.copied {
    background: rgba(0, 159, 227, 0.2);
}

.copyable.copied::after {
    content: "Copied!";
    position: absolute;
    top: -1.6rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elevated);
    color: var(--cyan);
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    white-space: nowrap;
}

/* Rating buttons */
.msg-rating {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.4rem;
}

.rate-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all 0.15s;
}

.rate-btn svg {
    width: 14px;
    height: 14px;
}

.rate-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
}

.rate-btn.rated {
    color: var(--cyan);
}

.rate-btn.rated svg {
    fill: var(--cyan);
}

/* === Input === */

.input-area {
    padding: 0 1.5rem 1.25rem;
    flex-shrink: 0;
}

.input-container {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.4rem 0.5rem 0.4rem 1rem;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--ahlsell-blue);
    box-shadow: 0 0 0 3px rgba(0, 115, 182, 0.1);
}

#input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.88rem;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 0.4rem 0;
    color: var(--text-primary);
}

#input:focus { outline: none; }

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

.btn-send {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--ahlsell-blue);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.btn-send:hover {
    background: var(--cyan);
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-send svg {
    width: 16px;
    height: 16px;
}

.input-disclaimer {
    max-width: 720px;
    margin: 0.5rem auto 0;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* === Error Screen === */

#error-screen {
    background: var(--bg-base);
    justify-content: center;
    align-items: center;
}

/* === Scrollbar === */

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
.messages::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Responsive === */

/* === Mobile === */

@media (max-width: 600px) {
    /* Topbar */
    .topbar {
        padding: 0 0.75rem;
        height: 48px;
    }

    .topbar-user span { display: none; }

    .topbar-version { font-size: 0.55rem; }

    .logo-img--topbar {
        width: 28px;
        height: 28px;
    }

    .topbar-title { font-size: 0.85rem; }

    /* Messages */
    .messages { padding: 0.75rem; }

    .messages-inner { gap: 1rem; }

    .msg-row { gap: 0.5rem; }

    .msg-content { max-width: 90%; }

    .msg-bubble {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }

    .msg-meta { gap: 0.3rem; }

    .msg-name { font-size: 0.72rem; }

    .msg-time { font-size: 0.62rem; }

    .avatar {
        width: 26px;
        height: 26px;
        font-size: 0.65rem;
    }

    /* Welcome */
    .welcome {
        padding: 2rem 0.5rem 1rem;
    }

    .welcome h2 { font-size: 1.1rem; }

    .welcome p { font-size: 0.82rem; }

    .logo-img--welcome {
        width: 60px;
        height: 60px;
    }

    /* Input */
    .input-area { padding: 0 0.5rem 0.5rem; }

    .input-container {
        border-radius: 10px;
        padding: 0.3rem 0.4rem 0.3rem 0.75rem;
    }

    #input { font-size: 0.85rem; }

    .btn-send {
        width: 32px;
        height: 32px;
    }

    .btn-send svg {
        width: 14px;
        height: 14px;
    }

    .input-disclaimer { font-size: 0.6rem; }

    /* Login */
    .login-card { padding: 2rem 1.5rem; }

    .logo-img--login {
        width: 100px;
        height: 100px;
    }

    .login-title { font-size: 1.4rem; }

    .login-subtitle { font-size: 0.82rem; }

    .btn-login {
        padding: 0.7rem 1.4rem;
        font-size: 0.85rem;
    }

    /* Mobile markdown */
    .msg-bubble h1 { font-size: 0.92rem; }
    .msg-bubble h2 { font-size: 0.88rem; }
    .msg-bubble h3 { font-size: 0.85rem; }
    .msg-bubble ul, .msg-bubble ol { padding-left: 1.1rem; }
    .msg-bubble pre { padding: 0.4rem 0.5rem; font-size: 0.78rem; }
    .msg-bubble table { font-size: 0.78rem; }
    .msg-bubble th, .msg-bubble td { padding: 0.25rem 0.8rem 0.25rem 0; }

    /* Markdown tables scroll horizontally on small screens */
    .msg-bubble table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
