/* ─── AI Chat Widget ─────────────────────────────────────────────────────────── */

:root {
    --aicw-primary:      #2c7be5;
    --aicw-primary-dark: #1a68d1;
}

body.aicw-body-open {
    overflow: hidden;
}

/* ── Trigger button ─────────────────────────────────────────────────────────── */

#aicw-trigger {
    color: #fff;
    text-align: center;
    background-color: var(--aicw-primary);
    border: 3px solid var(--aicw-primary);
    border-radius: 4px;
    padding: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24);
    transition: color .2s ease, background-color .2s ease;
    position: fixed;
    right: 5px;
    bottom: 5px;
    height: 40px;
    width: 120px;
    z-index: 100000000;
    cursor: pointer;
}

#aicw-trigger:hover {
    color: var(--aicw-primary);
    background-color: #fff;
    box-shadow: none;
}

#aicw-trigger span {
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    font-weight: bold;
    text-transform: uppercase;
}

/* ── Panel ──────────────────────────────────────────────────────────────────── */

#aicw-panel {
    opacity: 0;
    visibility: hidden;
    position: fixed;
    width: 400px;
    box-sizing: border-box;
    transition: opacity .35s ease, visibility .35s ease, bottom .35s ease;
    z-index: 1000000000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    /* Needed so the absolutely-positioned close button anchors to the panel */
    isolation: isolate;
}

#aicw-panel.aicw-open {
    opacity: 1;
    visibility: visible;
    bottom: 70px;
    right: 20px;
}

/* ── Close button ───────────────────────────────────────────────────────────── */

.aicw-header {
    position: absolute;
    top: -14px;
    left: -14px;
    z-index: 22;
}

.aicw-close-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: block;
}

.aicw-close-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    width: 34px;
    height: 34px;
    border: 2px solid #bab6b6;
    border-radius: 50%;
    cursor: pointer;
    transition: border-color .2s;
}

.aicw-close-circle span { color: #bab6b6; font-family: Arial; font-size: 16px; line-height: 1; }

.aicw-close-circle:hover { border-color: #000; }
.aicw-close-circle:hover span { color: #000; }

/* ── Title bar ──────────────────────────────────────────────────────────────── */

.aicw-title {
    font-weight: bold;
    font-size: 16px;
    text-align: center;
    padding: 10px 0;
    color: #fff;
    background: var(--aicw-primary);
    box-shadow: inset 0 3px 15px rgba(255,255,255,.2), 0 5px 13px rgba(67,74,76,.12);
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}

/* ── Chat view ──────────────────────────────────────────────────────────────── */

#aicw-chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* ── Messages area ──────────────────────────────────────────────────────────── */

#aicw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 15px;
    background: #f8f8f8;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 380px;
    min-height: 150px;
    scrollbar-width: thin;
    scrollbar-color: #666 #CFD8DC;
}

#aicw-messages::-webkit-scrollbar       { width: 6px; }
#aicw-messages::-webkit-scrollbar-track { background: #CFD8DC; }
#aicw-messages::-webkit-scrollbar-thumb { background-color: #666; border-radius: 6px; }

/* ── Bubbles ────────────────────────────────────────────────────────────────── */

.aicw-bubble {
    max-width: 85%;
    word-wrap: break-word;
    animation: aicw-fadein .2s ease;
}

.aicw-bubble p {
    margin: 0;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

.aicw-bubble--bot { align-self: flex-start; }
.aicw-bubble--bot p {
    background: #fff;
    color: #333;
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
}

.aicw-bubble--user { align-self: flex-end; }
.aicw-bubble--user p {
    background: var(--aicw-primary);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
}

.aicw-bubble--bot p a {
    color: var(--aicw-primary);
    text-decoration: underline;
    text-decoration-style: dotted;
    word-break: break-all;
}
.aicw-bubble--bot p a:hover { text-decoration-style: solid; }
.aicw-bubble--user p a { color: #fff; text-decoration: underline; opacity: .9; }

/* ── Typing indicator ───────────────────────────────────────────────────────── */

.aicw-typing {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: #fff;
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
    align-self: flex-start;
    gap: 5px;
}

.aicw-typing span {
    width: 8px; height: 8px;
    background: #aaa;
    border-radius: 50%;
    display: inline-block;
    animation: aicw-bounce 1.2s infinite;
}
.aicw-typing span:nth-child(2) { animation-delay: .2s; }
.aicw-typing span:nth-child(3) { animation-delay: .4s; }

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

@keyframes aicw-fadein {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Input area ─────────────────────────────────────────────────────────────── */

.aicw-input-area {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    gap: 8px;
    flex-shrink: 0;
}

#aicw-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    outline: none;
    color: #333;
    background: #f8f8f8;
}
#aicw-input:focus    { border-color: var(--aicw-primary); background: #fff; }
#aicw-input:disabled { opacity: .6; }

#aicw-send {
    background: var(--aicw-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px; height: 36px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color .2s ease;
}
#aicw-send:hover    { background: var(--aicw-primary-dark); }
#aicw-send:disabled { opacity: .5; cursor: not-allowed; }

/* ── Footer bar ─────────────────────────────────────────────────────────────── */

.aicw-footer-bar {
    text-align: center;
    padding: 5px 0 7px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.aicw-footer-bar button {
    background: none;
    border: none;
    color: var(--aicw-primary);
    font-size: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    cursor: pointer;
    padding: 2px 8px;
    text-decoration: underline;
    text-decoration-style: dotted;
}
.aicw-footer-bar button:hover { text-decoration-style: solid; }

/* ── Contact form view ──────────────────────────────────────────────────────── */

#aicw-contact-view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.aicw-contact-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px 16px;
    background: #f8f8f8;
    scrollbar-width: thin;
    scrollbar-color: #666 #CFD8DC;
}

.aicw-contact-intro {
    margin: 0 0 12px;
    font-size: 13px;
    color: #555;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.4;
}

.aicw-field { margin-bottom: 8px; }

.aicw-field input,
.aicw-field textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    color: #333;
    background: #fff;
    outline: none;
    transition: border-color .2s ease;
}
.aicw-field input:focus,
.aicw-field textarea:focus { border-color: var(--aicw-primary); }
.aicw-field textarea { resize: vertical; min-height: 70px; }

#aicw-cf-status {
    min-height: 16px;
    margin: 6px 0;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.4;
}
.aicw-cf-error   { color: #c0392b; }
.aicw-cf-success { color: #27ae60; font-weight: bold; }

.aicw-contact-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

#aicw-back-to-chat {
    background: none;
    border: none;
    color: #888;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-decoration-style: dotted;
}
#aicw-back-to-chat:hover { color: #333; text-decoration-style: solid; }

#aicw-cf-submit {
    background: var(--aicw-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 20px;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    cursor: pointer;
    transition: background-color .2s ease;
}
#aicw-cf-submit:hover    { background: var(--aicw-primary-dark); }
#aicw-cf-submit:disabled { opacity: .5; cursor: not-allowed; }

/* ── Overlay ────────────────────────────────────────────────────────────────── */

.aicw-overlay {
    display: none;
    background: rgba(0,0,0,.3);
    height: 100%;
    left: 0;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 999999999;
}
.aicw-overlay.aicw-open { display: block; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */

@media only screen and (min-width: 651px) and (max-width: 1024px) {
    #aicw-panel       { width: 350px; }
    #aicw-panel.aicw-open { margin-left: -175px; }
}

@media only screen and (max-width: 650px) {
    #aicw-panel            { width: 90%; min-width: 90%; }
    #aicw-panel.aicw-open  { top: 5%; left: 5%; bottom: 5%; height: 90%; margin-left: unset; }
    #aicw-messages         { max-height: none; }
    #aicw-trigger          { height: 40px; width: 120px; }
}
