/* ============================================================
   Allfasteners AI Assistant Widget
   ============================================================ */

.ai-assistant-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

/* ---- Toggle button ---- */
.ai-assistant-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #1a73e8;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(26, 115, 232, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.ai-assistant-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(26, 115, 232, 0.55);
}

.ai-assistant-toggle:focus-visible {
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.35);
}

.ai-assistant-toggle-icon {
    width: 26px;
    height: 26px;
    stroke: #ffffff;
}

/* ---- Panel ---- */
.ai-assistant-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    max-height: 560px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px) scale(0.97);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-assistant-panel.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ---- Header ---- */
.ai-assistant-header {
    background: #1a73e8;
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-assistant-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-assistant-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.ai-assistant-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.ai-assistant-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.75;
    transition: opacity 0.15s;
    border-radius: 4px;
    outline: none;
}

.ai-assistant-close:hover { opacity: 1; }

.ai-assistant-close:focus-visible {
    opacity: 1;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.ai-assistant-close svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
}

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

.ai-screen--hidden {
    display: none !important;
}

/* ---- Login screen ---- */
.ai-login-body {
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.ai-login-intro {
    font-size: 14px;
    color: #4b5563;
    text-align: center;
    margin: 0 0 4px;
}

.ai-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ai-field label {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
}

.ai-field-input {
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    outline: none;
    background: #f9fafb;
    color: #1f2937;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
    box-sizing: border-box;
}

.ai-field-input:focus {
    border-color: #1a73e8;
    background: #ffffff;
}

.ai-field-input::placeholder {
    color: #9ca3af;
}

.ai-login-error {
    font-size: 13px;
    color: #dc2626;
    min-height: 18px;
    text-align: center;
}

.ai-login-submit {
    width: 100%;
    padding: 11px;
    background: #1a73e8;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 2px;
}

.ai-login-submit:hover   { background: #1557b0; }
.ai-login-submit:disabled { background: #9ca3af; cursor: not-allowed; }

.ai-register-row {
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    padding-top: 4px;
}

.ai-register-row a {
    color: #1a73e8;
    text-decoration: none;
    font-weight: 500;
}

.ai-register-row a:hover { text-decoration: underline; }

/* ---- Welcome screen ---- */
.ai-welcome-body {
    padding: 32px 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.ai-welcome-greeting {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    text-align: center;
    margin: 0;
    line-height: 1.5;
}

.ai-welcome-options {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ai-option-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 10px 14px;
    min-height: 88px;
    background: #ffffff;
    border: 1.5px solid #1a73e8;
    border-radius: 12px;
    color: #1a73e8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
}

.ai-option-btn:hover {
    background: #1a73e8;
    color: #ffffff;
}

.ai-option-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.3);
}

.ai-option-icon {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-option-icon svg {
    width: 26px;
    height: 26px;
}

.ai-option-label {
    line-height: 1.3;
    font-size: 12px;
}

.ai-option-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: #e5e7eb;
    color: #6b7280;
    padding: 2px 5px;
    border-radius: 4px;
    line-height: 1.4;
}

.ai-option-btn--unavailable {
    opacity: 0.55;
    border-color: #d1d5db;
    color: #6b7280;
    cursor: default;
}

.ai-option-btn--unavailable:hover {
    background: #ffffff;
    color: #6b7280;
    border-color: #d1d5db;
}

/* ---- Chat screen: messages ---- */
.ai-assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f6f8fc;
    scroll-behavior: smooth;
}

.ai-assistant-messages::-webkit-scrollbar       { width: 4px; }
.ai-assistant-messages::-webkit-scrollbar-track  { background: transparent; }
.ai-assistant-messages::-webkit-scrollbar-thumb  { background: #d1d5db; border-radius: 4px; }

.ai-assistant-message {
    display: flex;
    animation: ai-msg-in 0.18s ease;
}

@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-assistant-message--user { justify-content: flex-end; }
.ai-assistant-message--bot  { justify-content: flex-start; }

.ai-assistant-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.ai-assistant-message--user .ai-assistant-bubble {
    background: #1a73e8;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ai-assistant-message--bot .ai-assistant-bubble {
    background: #ffffff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* ---- Typing indicator ---- */
.ai-assistant-typing .ai-assistant-bubble {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-assistant-typing .ai-assistant-bubble span {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: ai-bounce 1.3s infinite ease-in-out;
}

.ai-assistant-typing .ai-assistant-bubble span:nth-child(2) { animation-delay: 0.18s; }
.ai-assistant-typing .ai-assistant-bubble span:nth-child(3) { animation-delay: 0.36s; }

@keyframes ai-bounce {
    0%, 70%, 100% { transform: translateY(0); }
    35%           { transform: translateY(-7px); }
}

/* ---- Chat screen: footer / input ---- */
.ai-assistant-footer {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.ai-assistant-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-assistant-input {
    flex: 1;
    border: 1.5px solid #d1d5db;
    border-radius: 24px;
    padding: 9px 16px;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    background: #f9fafb;
    color: #1f2937;
    transition: border-color 0.15s, background 0.15s;
}

.ai-assistant-input:focus {
    border-color: #1a73e8;
    background: #ffffff;
}

.ai-assistant-input::placeholder { color: #9ca3af; }

.ai-assistant-send {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #1a73e8;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    outline: none;
}

.ai-assistant-send:hover        { background: #1557b0; transform: scale(1.05); }
.ai-assistant-send:focus-visible { box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.35); }
.ai-assistant-send:disabled     { background: #9ca3af; cursor: not-allowed; transform: none; }

.ai-assistant-send svg {
    width: 17px;
    height: 17px;
    stroke: #ffffff;
}

/* ---- Online badge ---- */
.ai-online-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 13px;
    height: 13px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #ffffff;
    animation: ai-badge-pulse 2.5s ease-in-out infinite;
}

@keyframes ai-badge-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

/* ---- Logo inside avatar ---- */
.ai-assistant-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* ---- Chat back navigation ---- */
.ai-chat-nav {
    padding: 7px 14px;
    background: #f6f8fc;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.ai-back-btn {
    background: none;
    border: none;
    color: #1a73e8;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}

.ai-back-btn:hover { text-decoration: underline; }

/* ---- Markdown rendering inside bot bubbles ---- */
.ai-assistant-message--bot .ai-msg-content {
    max-width: 95%;
}

.ai-assistant-bubble .ai-md-h2 {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    margin: 8px 0 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid #e5e7eb;
}

.ai-assistant-bubble .ai-md-h3 {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin: 6px 0 3px;
}

.ai-assistant-bubble .ai-md-p {
    margin: 2px 0;
    line-height: 1.55;
}

.ai-assistant-bubble .ai-md-list {
    margin: 4px 0;
    padding-left: 18px;
}

.ai-assistant-bubble .ai-md-list li {
    margin: 2px 0;
    line-height: 1.5;
}

.ai-md-table-wrap {
    overflow-x: auto;
    margin: 6px 0;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    -webkit-overflow-scrolling: touch;
}

.ai-md-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    min-width: 200px;
}

.ai-md-table th {
    background: #f3f4f6;
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

.ai-md-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #1f2937;
    vertical-align: top;
}

.ai-md-table tr:last-child td { border-bottom: none; }

.ai-md-table tr:nth-child(even) td { background: #f9fafb; }

/* Links inside bot bubbles */
.ai-assistant-bubble a {
    color: #1a73e8;
    text-decoration: underline;
    word-break: break-all;
}

.ai-assistant-bubble a:hover { color: #1557b0; }

.ai-assistant-message--bot .ai-assistant-bubble {
    overflow-x: auto;
}

.ai-assistant-bubble .ai-md-hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 6px 0;
}

/* ---- Message timestamp ---- */
.ai-msg-content {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.ai-assistant-message--user .ai-msg-content {
    align-items: flex-end;
}

.ai-assistant-message--bot .ai-msg-content {
    align-items: flex-start;
}

.ai-assistant-message--user .ai-assistant-bubble,
.ai-assistant-message--bot .ai-assistant-bubble {
    max-width: 100%;
}

.ai-msg-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
    padding: 0 4px;
    white-space: nowrap;
}

/* ---- Mode label in chat nav ---- */
.ai-mode-label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
    text-align: center;
}

/* ---- Chat nav report button ---- */
.ai-chat-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-report-btn {
    background: none;
    border: none;
    color: #6b7280;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}

.ai-report-btn:hover { color: #dc2626; }

/* ---- Report screen ---- */
.ai-report-body {
    padding: 20px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    flex: 1;
}

.ai-report-intro {
    font-size: 13px;
    color: #4b5563;
    margin: 0 0 4px;
    text-align: center;
}

.ai-field-textarea {
    resize: vertical;
    min-height: 90px;
    border-radius: 8px;
    line-height: 1.5;
    font-family: inherit;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
    .ai-assistant-widget { right: 12px; bottom: 12px; }

    .ai-assistant-panel {
        width: calc(100vw - 24px);
        right: -6px;
        max-height: 75vh;
    }
}
