/* =========================================================
   CHATBOT PAGE
   Works on top of the shared style.css
   (navbar, footer, theme and base colors come from there)
========================================================= */

/* Page-only tokens (scoped so the shared navbar/footer are not affected) */
.chat-page {
    --surface-2: var(--surface-soft);
    --primary-soft: var(--tint-blue);
    --hover: var(--tint-blue);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    --transition: 0.3s;
    --rec: #e5484d;

    min-height: calc(100vh - 74px);
    padding: 45px 20px;
    display: flex;
    justify-content: center;
    font-family: Arial, Helvetica, sans-serif;
    line-height: normal;
}

:root[data-theme="dark"] .chat-page {
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.chat-page * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.chat-page button,
.chat-page input,
.chat-page textarea,
.chat-page select {
    font: inherit;
}

/* :where() keeps this reset weaker than any button class, so borders still show */
:where(.chat-page) button {
    border: none;
}

.chat-page a {
    text-decoration: none;
}


/* CHAT CARD */

.chat-container {
    width: 100%;
    max-width: 900px;
    height: calc(100vh - 166px);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.chat-header {
    position: relative;
    z-index: 5;
    min-height: 82px;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    border-radius: 22px 22px 0 0;
    background: var(--surface);
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 13px;
}

.chat-header h1 {
    margin-bottom: 5px;
    font-size: 17px;
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.back-button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    transition: background-color var(--transition), color var(--transition);
}

.back-button:hover {
    background: var(--surface-2);
    color: var(--ink-blue);
}

.back-button svg {
    width: 15px;
}


/* MESSAGES */

.chat-messages {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background: var(--surface-2);
    transition: background-color var(--transition);
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 22px;
}

.message-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--primary-soft);
}

.message-avatar img.bot-avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

.message-content {
    max-width: 72%;
}

.message-bubble {
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 5px 17px 17px 17px;
    background: var(--surface);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.03);
}

.message-bubble p {
    color: var(--text);
    font-size: 14px;
    line-height: 1.65;
}

.message-bubble p+p {
    margin-top: 8px;
}

.message-time {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 10px;
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.user-message .message-bubble {
    border-color: var(--primary);
    border-radius: 17px 5px 17px 17px;
    background: var(--primary);
}

.user-message .message-bubble p {
    color: #fff;
}

.user-message .message-time {
    text-align: right;
}


/* SUGGESTIONS */

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    max-width: 750px;
    margin: 5px 0 20px 44px;
}

.suggestion-button {
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background-color var(--transition), border-color var(--transition),
        color var(--transition), transform var(--transition);
}

.suggestion-button:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--ink-blue);
    transform: translateY(-2px);
}


/* TYPING */

.typing-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 22px;
}

.typing-bubble {
    padding: 14px 17px;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 5px 17px 17px 17px;
    background: var(--surface);
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: typing 1.2s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}


/* VOICE STATUS */

.voice-status {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--primary-soft);
    color: var(--ink-blue);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.voice-status.active {
    display: flex;
}

.voice-animation {
    height: 18px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.voice-animation span {
    width: 3px;
    height: 8px;
    border-radius: 4px;
    background: var(--primary);
    animation: voiceWave 0.8s infinite ease-in-out;
}

.voice-animation span:nth-child(2) {
    animation-delay: 0.1s;
}

.voice-animation span:nth-child(3) {
    animation-delay: 0.2s;
}

.voice-animation span:nth-child(4) {
    animation-delay: 0.3s;
}

.voice-animation span:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes voiceWave {

    0%,
    100% {
        height: 6px;
    }

    50% {
        height: 17px;
    }
}


/* INPUT */

.chat-input-area {
    padding: 17px 20px 15px;
    border-top: 1px solid var(--border);
    border-radius: 0 0 22px 22px;
    background: var(--surface);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 7px 7px 7px 15px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface-2);
    transition: border-color var(--transition), background-color var(--transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary);
}

#chat-input {
    flex: 1;
    min-width: 0;
    max-height: 120px;
    padding: 8px 0;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

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

.voice-button,
.send-button {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition), transform var(--transition);
}

.voice-button {
    position: relative;
    background: var(--primary-soft);
    color: var(--ink-blue);
}

.voice-button:hover {
    background: var(--primary);
    color: #fff;
}

.voice-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.voice-button.listening {
    background: var(--rec);
    color: #fff;
    animation: micPulse 1.2s infinite;
}

@keyframes micPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.45);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(229, 72, 77, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(229, 72, 77, 0);
    }
}

.send-button {
    background: var(--primary);
    color: #fff;
}

.send-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.voice-button svg,
.send-button svg {
    width: 18px;
}

.input-note {
    margin-top: 8px;
    color: var(--muted);
    text-align: center;
    font-size: 10px;
}

.chat-messages::-webkit-scrollbar {
    width: 7px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: var(--border);
}


/* AVATAR */

.avatar-area {
    position: relative;
}

.avatar-button {
    width: 48px;
    height: 48px;
    padding: 0;
    overflow: hidden;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.avatar-button:hover {
    transform: scale(1.05);
}

.avatar-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-menu {
    position: absolute;
    top: 58px;
    left: 0;
    z-index: 1000;
    display: none;
    width: 340px;
    max-height: calc(100vh - 140px);
    padding: 20px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.18);
}

.avatar-menu.active {
    display: block;
}

.avatar-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.avatar-menu-header h3 {
    color: var(--text);
    font-size: 18px;
}

#closeAvatarMenu {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
}

#closeAvatarMenu:hover {
    background: var(--surface-2);
}

.avatar-preview {
    width: 100px;
    height: 100px;
    margin: 5px auto 20px;
    overflow: hidden;
    border: 3px solid var(--primary);
    border-radius: 50%;
    background: var(--surface-2);
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-section {
    margin-bottom: 20px;
}

.avatar-section h4 {
    margin-bottom: 12px;
    color: var(--text);
    font-size: 14px;
}

/* Avatar categories */

.avatar-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    padding-bottom: 4px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.avatar-tab {
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.avatar-tab:hover {
    color: var(--ink-blue);
    border-color: var(--primary);
}

.avatar-tab.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

/* Avatar choices */

.avatar-options {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.avatar-option {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: var(--surface-2);
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.avatar-option:hover {
    transform: scale(1.08);
    border-color: var(--primary);
}

.avatar-option.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft), 0 4px 12px rgba(23, 105, 224, 0.3);
    transform: scale(1.06);
}

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

/* Check mark on the chosen avatar */
.avatar-option.selected::after {
    content: "";
    position: absolute;
    right: -4px;
    bottom: -4px;
    width: 18px;
    height: 18px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--primary) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12l5 5L20 7'/></svg>") center / 10px no-repeat;
}

.upload-avatar {
    width: 100%;
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.upload-avatar:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.upload-avatar input {
    display: none;
}

.avatar-note {
    min-height: 18px;
    margin-bottom: 10px;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
}

.save-avatar {
    width: 100%;
    min-height: 45px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.save-avatar:hover {
    background: var(--primary-dark);
}

.chat-page :focus-visible {
    outline: 3px solid #f2b630;
    outline-offset: 2px;
}


/* RESPONSIVE */

@media (max-width: 700px) {

    .chat-page {
        min-height: calc(100vh - 70px);
        padding: 0;
    }

    .chat-container {
        height: calc(100vh - 70px);
        min-height: 0;
        border: none;
        border-radius: 0;
    }

    .chat-header {
        min-height: 72px;
        padding: 12px 16px;
        border-radius: 0;
    }

    .chat-input-area {
        padding: 12px;
        border-radius: 0;
    }

    .chat-header h1 {
        font-size: 15px;
    }

    .back-button span {
        display: none;
    }

    .back-button {
        width: 36px;
        height: 36px;
        padding: 0;
        justify-content: center;
    }

    .chat-messages {
        padding: 22px 16px;
    }

    .message-content {
        max-width: 82%;
    }

    .suggestions {
        margin-left: 43px;
    }

    .suggestion-button {
        font-size: 11px;
    }

    .input-note {
        display: none;
    }
}

@media (max-width: 560px) {

    .chat-input-wrapper {
        flex-wrap: wrap;
    }

    .lang-switch {
        order: -1;
        flex: 0 0 100%;
        width: 100%;
        margin-bottom: 4px;
    }

    .lang-option {
        padding: 8px 10px;
    }

    #chat-input {
        flex: 1 1 120px;
    }
}

@media (max-width: 500px) {

    .avatar-menu {
        position: fixed;
        top: 80px;
        right: 15px;
        left: 15px;
        width: auto;
        max-height: calc(100vh - 100px);
    }
}

@media (max-width: 430px) {

    .message-content {
        max-width: 85%;
    }

    .suggestions {
        margin-left: 0;
    }

    .suggestion-button {
        flex: 1;
    }

    .chat-input-wrapper {
        padding-left: 12px;
    }

    .voice-button,
    .send-button {
        width: 38px;
        height: 38px;
    }
}

@media (prefers-reduced-motion: reduce) {

    .chat-page * {
        animation: none !important;
        transition: none !important;
    }
}


/* =========================================================
   LANGUAGE SWITCHER (English / አማርኛ)
========================================================= */

.lang-switch {
    position: relative;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-self: center;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.06);
}

/* The sliding highlight behind the active language */
.lang-thumb {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc((100% - 8px) / 2);
    border-radius: 999px;
    background: linear-gradient(135deg, #1769e0, #4a94f8);
    box-shadow: 0 3px 10px rgba(23, 105, 224, 0.35);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.lang-switch[data-lang="am-ET"] .lang-thumb {
    transform: translateX(100%);
}

.lang-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.lang-option {
    position: relative;
    z-index: 1;
    min-width: 62px;
    padding: 7px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-family: "Noto Sans Ethiopic", Nyala, "Abyssinica SIL", Arial, Helvetica, sans-serif;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: color 0.25s ease, background-color 0.25s ease;
}

.lang-input:not(:checked)+.lang-option:hover {
    background: rgba(23, 105, 224, 0.1);
    color: var(--ink-blue);
}

.lang-input:checked+.lang-option {
    color: #fff;
}

.lang-input:focus-visible+.lang-option {
    outline: 3px solid #f2b630;
    outline-offset: 1px;
}


/* =========================================================
   MICROPHONE BUTTON
========================================================= */

.voice-button .icon-off,
.voice-button.blocked .icon-mic,
.voice-button:disabled .icon-mic {
    display: none;
}

.voice-button.blocked .icon-off,
.voice-button:disabled .icon-off {
    display: block;
}

.voice-button.blocked {
    color: var(--rec);
}

/* Small red recording dot while listening */
.voice-button.listening::after {
    content: "";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
    animation: recBlink 1s infinite;
}

@keyframes recBlink {
    50% {
        opacity: 0.25;
    }
}


/* =========================================================
   VOICE STATUS BAR: STOP BUTTON AND NOTICES
========================================================= */

.voice-status-text {
    max-width: 640px;
    line-height: 1.5;
}

.voice-status[data-state="notice"] .voice-animation {
    display: none;
}

.voice-stop {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--rec);
    border-radius: 999px;
    background: transparent;
    color: var(--rec);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.voice-stop[hidden] {
    display: none;
}

.voice-stop:hover {
    background: var(--rec);
    color: #fff;
}

.voice-stop svg {
    width: 11px;
    height: 11px;
    fill: currentColor;
}


/* =========================================================
   LISTEN BUTTON ON REPLIES
========================================================= */

.message-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.message-meta .message-time {
    margin-top: 0;
}

.listen-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.listen-button[hidden] {
    display: none;
}

.listen-button:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--ink-blue);
}

.listen-button svg {
    width: 12px;
    height: 12px;
}

.listen-button .icon-stop {
    display: none;
    fill: currentColor;
}

.listen-button.speaking {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.listen-button.speaking .icon-play {
    display: none;
}

.listen-button.speaking .icon-stop {
    display: block;
}