/* ============================================================
   Levi Chat — CSS custom properties for light/dark mode
   ============================================================ */

:root {
    --bg:                #ecedf0;
    --fg:                #383f48;
    --fg-muted:          #777;
    --border:            #d8d9dc;
    --composer-bg:       #ffffff;
    --composer-border:   #d0d1d4;
    --composer-focus:    #0088cc;
    --bubble-user-bg:    #dde0e6;
    --bubble-user-fg:    #383f48;
    --accent:            #0088cc;
    --send-bg:           #0088cc;
    --send-fg:           #ffffff;
    --send-disabled:     #c0c0c0;
    --title-fg:          #383f48;
    --icon-fg:           #0088cc;
    --nav-bg:            #ffffff;
    --nav-fg:            #383f48;
    --nav-border:        #d8d9dc;
    --nav-dropdown-bg:   #ffffff;
    --nav-dropdown-fg:   #383f48;
    --nav-dropdown-hover:#f0f1f3;
    --nav-h:             56px;
}

html.dark {
    --bg:                #171717;
    --fg:                #d0d4e0;
    --fg-muted:          #888;
    --border:            #2a2a2a;
    --composer-bg:       #222222;
    --composer-border:   #333333;
    --composer-focus:    #0099e6;
    --bubble-user-bg:    #2a2a2a;
    --bubble-user-fg:    #d0d4e0;
    --accent:            #0099e6;
    --send-bg:           #0099e6;
    --send-fg:           #ffffff;
    --send-disabled:     #444;
    --title-fg:          #d0d4e0;
    --icon-fg:           #0099e6;
    --nav-bg:            #1a1f2e;
    --nav-fg:            #d0d4e0;
    --nav-border:        #2a3045;
    --nav-dropdown-bg:   #222840;
    --nav-dropdown-fg:   #d0d4e0;
    --nav-dropdown-hover:#2e3555;
}

/* ============================================================
   Reset + base
   ============================================================ */

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
    font-size: 16px;
    line-height: 1.65;
    transition: background .2s, color .2s;
}

body {
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Top navigation header
   ============================================================ */

.levi-nav {
    height: var(--nav-h, 56px);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    transition: background .2s, border-color .2s;
    position: relative;
    z-index: 100;
}

.levi-nav__logo {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .02em;
    color: var(--nav-fg);
    text-decoration: none;
}
.levi-nav__logo:hover { color: var(--accent); text-decoration: none; }

.levi-nav__right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* User dropdown trigger */
.levi-nav__user {
    position: relative;
    display: flex;
    align-items: center;
    gap: .45rem;
    cursor: pointer;
    padding: .35rem .5rem;
    border-radius: 6px;
    color: var(--nav-fg);
    font-size: .875rem;
    font-weight: 500;
    user-select: none;
    transition: background .15s;
}
.levi-nav__user:hover { background: var(--nav-dropdown-hover); }

.levi-nav__user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.levi-nav__caret {
    font-size: .65rem;
    opacity: .6;
    transition: transform .2s;
}
.levi-nav__user[aria-expanded="true"] .levi-nav__caret { transform: rotate(180deg); }

/* Dropdown menu */
.levi-nav__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 170px;
    background: var(--nav-dropdown-bg);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.15);
    padding: .35rem 0;
    z-index: 200;
    list-style: none;
}
.levi-nav__dropdown.is-open { display: block; }

.levi-nav__dropdown li a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem 1rem;
    color: var(--nav-dropdown-fg);
    font-size: .875rem;
    text-decoration: none;
    transition: background .1s;
}
.levi-nav__dropdown li a:hover { background: var(--nav-dropdown-hover); }
.levi-nav__dropdown li a i    { width: 16px; text-align: center; opacity: .7; }

.levi-nav__dropdown .levi-nav__divider {
    height: 1px;
    background: var(--nav-border);
    margin: .35rem 0;
}

/* ============================================================
   App root
   ============================================================ */

#levi-app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Welcome screen
   ============================================================ */

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

.levi-welcome__title {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 600;
    color: var(--title-fg);
    text-align: center;
    letter-spacing: -.02em;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.levi-welcome__icon {
    color: var(--icon-fg);
}

/* ============================================================
   Chat view
   ============================================================ */

.levi-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Message thread */
.levi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    scroll-behavior: smooth;
}

/* ============================================================
   Messages — conversation style (not SMS bubbles)
   ============================================================ */

.levi-msg {
    display: flex;
    gap: .9rem;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
}

/* --- Assistant: avatar + plain flowing text --- */
.levi-msg--assistant {
    align-items: flex-start;
}

.levi-msg__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.levi-msg--assistant .levi-msg__body {
    flex: 1;
    color: var(--fg);
    font-size: 1rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- User: bubble right-aligned, no avatar --- */
.levi-msg--user {
    justify-content: flex-end;
}

.levi-msg--user .levi-msg__body {
    background: var(--bubble-user-bg);
    color: var(--bubble-user-fg);
    border-radius: 18px 18px 4px 18px;
    padding: .75rem 1.1rem;
    max-width: 72%;
    font-size: 1rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- Error / status --- */
.levi-msg--error {
    justify-content: center;
    font-size: .78rem;
    color: var(--fg-muted);
    font-style: italic;
    max-width: 760px;
    margin: 0 auto;
}

/* Typing indicator */
.levi-msg__body--typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: .25rem 0;
}

.levi-msg__body--typing span {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--fg-muted);
    animation: levi-bounce 1s infinite;
}
.levi-msg__body--typing span:nth-child(2) { animation-delay: .15s; }
.levi-msg__body--typing span:nth-child(3) { animation-delay: .3s; }

@keyframes levi-bounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: .4; }
    40%            { transform: translateY(-5px); opacity: 1;  }
}

/* ============================================================
   Composer — shared between welcome + chat states
   ============================================================ */

.levi-composer {
    width: 100%;
}

/* Welcome: full-width, centered, generous padding */
.levi-composer--welcome {
    max-width: 680px;
    background: var(--composer-bg);
    border: 1px solid var(--composer-border);
    border-radius: 20px;
    padding: 1rem 1rem .75rem;
    transition: border-color .15s, box-shadow .15s;
}

.levi-composer--welcome:focus-within {
    border-color: var(--composer-focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--composer-focus) 15%, transparent);
}

/* Chat: anchored to bottom */
.levi-composer--chat {
    flex-shrink: 0;
    padding: .75rem 1rem 1rem;
    border-top: 1px solid var(--border);
}

.levi-composer--chat .levi-composer__inner-wrap {
    background: var(--composer-bg);
    border: 1px solid var(--composer-border);
    border-radius: 16px;
    padding: .75rem 1rem .6rem;
    max-width: 760px;
    margin: 0 auto;
    transition: border-color .15s;
}

.levi-composer--chat .levi-composer__inner-wrap:focus-within {
    border-color: var(--composer-focus);
}

.levi-composer__textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 1.4rem;
    line-height: 1.55;
    color: var(--fg);
    font-family: inherit;
    max-height: 200px;
    overflow-y: auto;
}

.levi-composer--chat .levi-composer__textarea {
    font-size: 1rem;
}

.levi-composer__textarea::placeholder { color: var(--fg-muted); }
.levi-composer__textarea:disabled     { opacity: .5; cursor: not-allowed; }

.levi-composer__bar {
    display: flex;
    justify-content: flex-end;
    margin-top: .5rem;
}

.levi-composer__send {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--send-bg);
    color: var(--send-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: .85rem;
    transition: opacity .15s, transform .1s;
}

.levi-composer__send:hover    { opacity: .88; }
.levi-composer__send:active   { transform: scale(.92); }
.levi-composer__send:disabled { background: var(--send-disabled); cursor: default; }

.levi-composer__disclaimer {
    font-size: .72rem;
    color: var(--fg-muted);
    text-align: center;
    margin-top: .45rem;
    opacity: .7;
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 600px) {
    .levi-welcome          { padding: 2rem 1rem; }
    .levi-messages         { padding: 1.25rem .75rem; gap: 1.5rem; }
    .levi-composer--chat   { padding: .5rem .75rem .75rem; }
    .levi-msg--user .levi-msg__body { max-width: 88%; }
}

/* ============================================================
   Wrap-up flow (#12)
   ============================================================ */

.levi-composer__finish {
    display: inline-block;
    margin-left: .35rem;
    color: var(--fg-muted);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.levi-composer__finish:hover {
    color: var(--accent, #0d6efd);
    text-decoration: none;
}

.levi-modal {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
}
.levi-modal__backdrop {
    position: absolute; inset: 0;
    background: rgba(20, 22, 30, 0.55);
    backdrop-filter: blur(2px);
}
.levi-modal__panel {
    position: relative;
    width: min(92vw, 480px);
    background: #fff;
    color: #1a1f2e;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    padding: 1.5rem 1.5rem 1.25rem;
}
.levi-modal__title {
    margin: 0 0 .6rem;
    font-size: 1.2rem;
    font-weight: 700;
}
.levi-modal__body {
    margin: 0 0 1rem;
    color: #444a58;
    line-height: 1.5;
}
.levi-modal__status {
    background: #fff3cd;
    border: 1px solid #ffe69c;
    color: #664d03;
    padding: .55rem .75rem;
    border-radius: 6px;
    font-size: .9rem;
    margin-bottom: .85rem;
}
.levi-modal__actions {
    display: flex; gap: .55rem; justify-content: flex-end;
}
.levi-modal__btn {
    padding: .55rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    font-weight: 600;
    cursor: pointer;
    font-size: .92rem;
}
.levi-modal__btn--cancel {
    background: #f0f2f5;
    color: #1a1f2e;
}
.levi-modal__btn--confirm {
    background: #0d6efd;
    color: #fff;
}
.levi-modal__btn:disabled {
    opacity: .6;
    cursor: default;
}

.levi-thanks {
    max-width: 640px;
    margin: 3rem auto;
    padding: 2rem 1.5rem;
    text-align: center;
}
.levi-thanks__title {
    color: #198754;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 1rem;
}
.levi-thanks__title i { margin-right: .4rem; }
.levi-thanks__body {
    color: var(--fg-muted);
    line-height: 1.6;
}
.levi-thanks__body a { color: var(--accent, #0d6efd); }
