/* Edwin Chat Widget */

:root {
    --edwin-primary: #1a56db;
    --edwin-primary-dark: #1347b8;
    --edwin-radius: 12px;
    --edwin-shadow: 0 8px 32px rgba(0,0,0,0.16);
}

/* Launcher button */
#edwin-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--edwin-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--edwin-shadow);
    transition: transform 0.2s, background 0.2s;
}

#edwin-launcher:hover { background: var(--edwin-primary-dark); transform: scale(1.07); }

#edwin-launcher svg { width: 26px; height: 26px; fill: #fff; }

#edwin-launcher .edwin-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

#edwin-launcher .edwin-badge.visible { display: block; }

/* Chat window */
#edwin-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 99999;
    width: 380px;
    max-height: 600px;
    background: #fff;
    border-radius: var(--edwin-radius);
    box-shadow: var(--edwin-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity 0.2s, transform 0.2s;
}

#edwin-window.edwin-hidden {
    opacity: 0;
    transform: scale(0.92);
    pointer-events: none;
}

/* Header */
.edwin-header {
    background: var(--edwin-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.edwin-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.edwin-header-info { flex: 1; }
.edwin-header-info strong { display: block; font-size: 15px; }
.edwin-header-info span   { font-size: 12px; opacity: 0.8; }

.edwin-header-btns { display: flex; gap: 6px; }

.edwin-header-btns button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
    white-space: nowrap;
}

.edwin-header-btns button:hover { background: rgba(255,255,255,0.28); }

#edwin-close-btn {
    background: transparent !important;
    font-size: 18px;
    padding: 4px 8px !important;
    line-height: 1;
}

/* Screens */
.edwin-screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.edwin-screen.active { display: flex; }

/* Welcome / email collection screen */
#edwin-screen-welcome {
    padding: 20px;
    overflow-y: auto;
}

#edwin-screen-welcome h2 {
    font-size: 16px;
    margin: 0 0 8px;
    color: #111827;
}

#edwin-screen-welcome p {
    color: #6b7280;
    font-size: 13px;
    margin: 0 0 20px;
    line-height: 1.5;
}

.edwin-field { margin-bottom: 14px; }

.edwin-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}

.edwin-field input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 14px;
    color: #111827;
    box-sizing: border-box;
    transition: border-color 0.15s;
    outline: none;
}

.edwin-field input:focus { border-color: var(--edwin-primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.12); }
.edwin-field input.error { border-color: #ef4444; }

.edwin-field .edwin-field-note {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

.edwin-btn-primary {
    width: 100%;
    background: var(--edwin-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 11px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 6px;
}

.edwin-btn-primary:hover { background: var(--edwin-primary-dark); }
.edwin-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Chat screen */
#edwin-screen-chat { flex: 1; }

.edwin-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f9fafb;
}

.edwin-msg {
    max-width: 85%;
    padding: 10px 13px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.55;
}

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

.edwin-msg.assistant {
    align-self: flex-start;
    background: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 3px;
}

.edwin-msg.system {
    align-self: center;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
    font-size: 12px;
    max-width: 95%;
    text-align: center;
    border-radius: 6px;
}

.edwin-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 3px;
    text-align: right;
}

.edwin-typing {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    border-bottom-left-radius: 3px;
    padding: 10px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.edwin-typing span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: edwinBounce 1.2s infinite;
}

.edwin-typing span:nth-child(2) { animation-delay: 0.2s; }
.edwin-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes edwinBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Input bar */
.edwin-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

#edwin-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 90px;
    line-height: 1.4;
    transition: border-color 0.15s;
    font-family: inherit;
}

#edwin-input:focus { border-color: var(--edwin-primary); }

#edwin-send-btn {
    width: 36px;
    height: 36px;
    background: var(--edwin-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

#edwin-send-btn:hover { background: var(--edwin-primary-dark); }
#edwin-send-btn svg { width: 17px; height: 17px; fill: #fff; }

/* Escalation screen */
#edwin-screen-escalate {
    padding: 18px;
    overflow-y: auto;
}

#edwin-screen-escalate h3 {
    font-size: 15px;
    margin: 0 0 8px;
}

#edwin-screen-escalate p {
    font-size: 13px;
    color: #6b7280;
    margin: 0 0 14px;
    line-height: 1.5;
}

#edwin-summary-edit {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    font-family: inherit;
    color: #111827;
    min-height: 100px;
    resize: vertical;
    outline: none;
    line-height: 1.5;
    transition: border-color 0.15s;
}

#edwin-summary-edit:focus { border-color: var(--edwin-primary); }

.edwin-escalate-btns {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.edwin-escalate-btns button {
    flex: 1;
    padding: 9px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}

#edwin-escalate-send {
    background: var(--edwin-primary);
    color: #fff;
}

#edwin-escalate-send:hover { background: var(--edwin-primary-dark); }

#edwin-escalate-cancel {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db !important;
}

#edwin-escalate-cancel:hover { background: #e5e7eb; }

/* Inactivity warning banner */
#edwin-timeout-bar {
    background: #fef3c7;
    border-top: 1px solid #fde68a;
    padding: 8px 14px;
    font-size: 12px;
    color: #92400e;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#edwin-timeout-bar.hidden { display: none; }
#edwin-timeout-keep { font-weight: 600; cursor: pointer; color: var(--edwin-primary); background: none; border: none; font-size: 12px; }

/* Ended screen */
#edwin-screen-ended {
    padding: 24px;
    text-align: center;
}

#edwin-screen-ended .edwin-ended-icon { font-size: 40px; margin-bottom: 12px; }
#edwin-screen-ended h3 { font-size: 16px; margin: 0 0 8px; }
#edwin-screen-ended p { font-size: 13px; color: #6b7280; line-height: 1.5; }

/* Mobile responsiveness */
@media (max-width: 440px) {
    #edwin-window {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 80px;
        max-height: 80vh;
    }
    #edwin-launcher { right: 12px; bottom: 12px; }
}

/* Markdown rendering in assistant messages */
.edwin-msg.assistant p        { margin: 0 0 8px; }
.edwin-msg.assistant p:last-child { margin-bottom: 0; }
.edwin-msg.assistant h2,
.edwin-msg.assistant h3,
.edwin-msg.assistant h4       { font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: #111827; }
.edwin-msg.assistant strong   { font-weight: 600; }
.edwin-msg.assistant em       { font-style: italic; }
.edwin-msg.assistant code     { background: #f3f4f6; border-radius: 3px; padding: 1px 5px; font-size: 12px; font-family: monospace; }
.edwin-msg.assistant ul,
.edwin-msg.assistant ol       { margin: 6px 0 6px 18px; padding: 0; }
.edwin-msg.assistant li       { margin-bottom: 3px; }
.edwin-msg.assistant hr       { border: none; border-top: 1px solid #e5e7eb; margin: 8px 0; }

.edwin-table                  { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.edwin-table th               { background: #1a56db; color: #fff; padding: 6px 10px; text-align: left; font-weight: 600; }
.edwin-table td               { padding: 5px 10px; border-bottom: 1px solid #e5e7eb; color: #374151; }
.edwin-table tr:last-child td { border-bottom: none; }
.edwin-table tr:nth-child(even) td { background: #f9fafb; }

/* Links in assistant messages */
.edwin-msg.assistant a         { color: #1a56db; text-decoration: underline; word-break: break-all; }
.edwin-msg.assistant a:hover   { color: #1347b8; }
