/* ==========================================================================
   ST. LAWRENCE JUNIOR SCHOOL KABOWA — CHATBOT UI (PHASE 3 REDESIGN)
   Role: Digital School Receptionist
   Strict School Branding:
   - Primary: Solid School Blue (#003366)
   - Secondary/Accent: School Red (#dc3545)
   - Clean White (#ffffff)
   - Light Neutral Backgrounds (#f8fafc, #f1f5f9)
   - Dark Readable Text (#1e293b, #334155)
   - NO gradients | NO green | NO neon | NO glassmorphism | NO excessive glow
   ========================================================================== */

:root {
    --sl-blue: #003366;
    --sl-blue-dark: #002244;
    --sl-blue-light: #e8f0fe;
    --sl-red: #dc3545;
    --sl-red-dark: #bd2130;
    --sl-white: #ffffff;
    --sl-bg-page: #f8fafc;
    --sl-bg-subtle: #f1f5f9;
    --sl-border: #e2e8f0;
    --sl-border-dark: #cbd5e1;
    --sl-text-primary: #1e293b;
    --sl-text-secondary: #475569;
    --sl-text-muted: #94a3b8;
    --sl-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ==========================================================================
   1. FLOATING CHAT LAUNCHER
   ========================================================================== */
.chat-button {
    position: fixed;
    bottom: 90px;
    right: 28px;
    width: 60px;
    height: 60px;
    background: var(--sl-white);
    border: 2.5px solid var(--sl-blue);
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(0, 51, 102, 0.18);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    padding: 0;
    box-sizing: border-box;
}

.chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 51, 102, 0.25);
    border-color: var(--sl-blue-dark);
}

.chat-button img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

/* Red notification dot */
.chat-unread-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--sl-red);
    border: 2px solid var(--sl-white);
    border-radius: 50%;
    pointer-events: none;
}

/* Launcher Tooltip */
.chat-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    background: var(--sl-white);
    color: var(--sl-blue);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--sl-font);
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(0, 51, 102, 0.12);
    border: 1px solid var(--sl-border);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 9999;
}

.chat-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    right: 24px;
    width: 8px;
    height: 8px;
    background: var(--sl-white);
    border-right: 1px solid var(--sl-border);
    border-bottom: 1px solid var(--sl-border);
    transform: rotate(45deg);
}

.chat-button:hover .chat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chat-button.active .chat-tooltip {
    opacity: 0;
    visibility: hidden;
    display: none;
}

.chat-button.active .chat-unread-dot {
    display: none;
}

/* ==========================================================================
   2. CHAT WIDGET WINDOW
   ========================================================================== */
.chat-widget {
    position: fixed;
    bottom: 165px;
    right: 28px;
    width: 390px;
    height: 570px;
    max-height: calc(100vh - 185px);
    background: var(--sl-white);
    border: 1px solid var(--sl-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 51, 102, 0.16);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--sl-font);
    box-sizing: border-box;
}

.chat-widget.active {
    display: flex;
    animation: chatWidgetFadeIn 0.2s ease forwards;
}

@keyframes chatWidgetFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   3. CHAT HEADER
   ========================================================================== */
.chat-header {
    background: var(--sl-blue);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--sl-white);
    border-top-left-radius: 11px;
    border-top-right-radius: 11px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.chat-header-logo {
    width: 36px;
    height: 36px;
    background: var(--sl-white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 2px;
    box-sizing: border-box;
}

.chat-header-logo img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: contain;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header-title {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    color: var(--sl-white);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-status {
    font-size: 11px;
    color: #e2e8f0;
    margin-top: 2px;
    line-height: 1.2;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chat-header-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--sl-white);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: background-color 0.15s ease;
    padding: 0;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.chat-header-btn:focus-visible {
    outline: 2px solid var(--sl-white);
    outline-offset: 1px;
}

/* ==========================================================================
   4. CHAT STATUS BAR (Voice/Processing State)
   ========================================================================== */
.chat-status-bar {
    background: var(--sl-bg-subtle);
    border-bottom: 1px solid var(--sl-border);
    padding: 6px 14px;
    font-size: 12px;
    color: var(--sl-blue);
    display: none;
    align-items: center;
    justify-content: space-between;
    min-height: 28px;
    flex-shrink: 0;
    box-sizing: border-box;
}

.chat-status-bar.active {
    display: flex;
}

.chat-status-bar.listening {
    display: flex;
    background: #fff5f5;
    color: var(--sl-red);
    border-bottom: 1px solid #fed7d7;
}

.chat-status-bar.speaking {
    display: flex;
    background: var(--sl-blue-light);
    color: var(--sl-blue);
    border-bottom: 1px solid #bfdbfe;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status-stop-btn {
    background: var(--sl-red);
    color: var(--sl-white);
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.status-stop-btn:hover {
    background: var(--sl-red-dark);
}

/* ==========================================================================
   5. CHAT BODY & MESSAGES
   ========================================================================== */
.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: var(--sl-bg-page);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-sizing: border-box;
    scroll-behavior: smooth;
}

/* Welcome Card */
.chat-welcome-card {
    background: var(--sl-white);
    border: 1px solid var(--sl-border);
    border-radius: 10px;
    padding: 14px;
    color: var(--sl-text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chat-welcome-card h4 {
    margin: 0 0 6px 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--sl-blue);
}

.chat-welcome-card p {
    margin: 0 0 8px 0;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--sl-text-secondary);
}

.chat-welcome-card p:last-of-type {
    margin-bottom: 6px;
}

.chat-welcome-card strong {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--sl-blue);
    margin-top: 6px;
}

/* Welcome quick action grid */
.welcome-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.welcome-action-btn {
    background: var(--sl-white);
    border: 1.5px solid var(--sl-blue);
    color: var(--sl-blue);
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    font-family: var(--sl-font);
}

.welcome-action-btn:hover {
    background: var(--sl-blue);
    color: var(--sl-white);
}

.welcome-action-btn:focus-visible {
    outline: 2px solid var(--sl-blue);
    outline-offset: 1px;
}

/* Messages */
.chat-message {
    display: flex;
    gap: 8px;
    max-width: 88%;
    box-sizing: border-box;
}

.chat-message.bot {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sl-white);
    border: 1px solid var(--sl-border-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 1px;
    box-sizing: border-box;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: contain;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.message-content {
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    box-sizing: border-box;
}

.chat-message.bot .message-content {
    background: var(--sl-white);
    color: var(--sl-text-primary);
    border: 1px solid var(--sl-border);
    border-radius: 10px 10px 10px 2px;
}

.chat-message.bot .message-content a {
    color: var(--sl-blue);
    text-decoration: underline;
    font-weight: 600;
}

.chat-message.user .message-content {
    background: var(--sl-blue);
    color: var(--sl-white);
    border-radius: 10px 10px 2px 10px;
    border: 1px solid var(--sl-blue);
}

.message-time {
    font-size: 10.5px;
    color: var(--sl-text-muted);
    margin-top: 3px;
}

.chat-message.bot .message-time {
    margin-left: 2px;
}

.chat-message.user .message-time {
    margin-right: 2px;
    text-align: right;
}

/* ==========================================================================
   6. QUICK-ACTION SUGGESTIONS (Chips)
   ========================================================================== */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 2px 0 6px 36px;
}

.quick-action-btn {
    background: var(--sl-white);
    border: 1px solid var(--sl-blue);
    color: var(--sl-blue);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
    font-family: var(--sl-font);
    text-align: left;
}

.quick-action-btn:hover {
    background: var(--sl-blue);
    color: var(--sl-white);
}

.quick-action-btn:active {
    transform: scale(0.97);
}

.quick-action-btn:focus-visible {
    outline: 2px solid var(--sl-blue);
    outline-offset: 1px;
}

/* ==========================================================================
   7. TYPING / PROCESSING INDICATOR
   ========================================================================== */
.typing-bubble {
    background: var(--sl-white);
    border: 1px solid var(--sl-border);
    border-radius: 10px 10px 10px 2px;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sl-text-secondary);
    display: inline-block;
    animation: typingBlink 1.4s infinite both;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingBlink {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================================================
   8. MESSAGE INPUT BAR
   ========================================================================== */
.chat-footer {
    padding: 10px 12px;
    background: var(--sl-white);
    border-top: 1px solid var(--sl-border);
    display: flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--sl-border-dark);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    color: var(--sl-text-primary);
    background: var(--sl-white);
    outline: none;
    font-family: var(--sl-font);
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.chat-input::placeholder {
    color: var(--sl-text-muted);
}

.chat-input:focus {
    border-color: var(--sl-blue);
}

.chat-mic-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--sl-border-dark);
    background: var(--sl-bg-subtle);
    color: var(--sl-blue);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.chat-mic-btn:hover {
    background: var(--sl-border);
    color: var(--sl-blue-dark);
}

.chat-mic-btn.listening {
    background: var(--sl-red);
    color: var(--sl-white);
    border-color: var(--sl-red);
}

.chat-mic-btn:focus-visible {
    outline: 2px solid var(--sl-blue);
    outline-offset: 1px;
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    background: var(--sl-blue);
    color: var(--sl-white);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease;
    padding: 0;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--sl-blue-dark);
}

.chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-send-btn:focus-visible {
    outline: 2px solid var(--sl-blue-dark);
    outline-offset: 1px;
}

.chat-mic-btn i,
.chat-send-btn i,
.chat-header-btn i,
.voice-main-mic i,
.voice-action-btn i {
    pointer-events: none;
}

/* ==========================================================================
   9. DEDICATED VOICE CHAT INTERFACE
   ========================================================================== */
.voice-interface {
    flex: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--sl-bg-page);
    padding: 16px 14px;
    box-sizing: border-box;
    overflow-y: auto;
}

.voice-interface.active {
    display: flex;
    animation: voiceFadeIn 0.2s ease forwards;
}

@keyframes voiceFadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

.voice-card {
    width: 100%;
    max-width: 340px;
    background: var(--sl-white);
    border: 1px solid var(--sl-border);
    border-radius: 12px;
    padding: 18px 16px 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 51, 102, 0.05);
}

.voice-avatar-wrap {
    position: relative;
    width: 72px;
    height: 72px;
    margin-bottom: 10px;
}

.voice-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--sl-white);
    border: 2.5px solid var(--sl-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 3px;
    box-sizing: border-box;
}

.voice-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.voice-school-name {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--sl-blue);
    margin: 0 0 2px 0;
    font-family: var(--sl-font);
}

.voice-role-title {
    font-size: 11.5px;
    color: var(--sl-text-secondary);
    margin: 0 0 12px 0;
}

/* Status badge */
.voice-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--sl-bg-subtle);
    border: 1px solid var(--sl-border);
    border-radius: 20px;
    padding: 5px 13px;
    margin-bottom: 12px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.voice-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sl-blue);
    flex-shrink: 0;
}

.voice-status-badge.listening {
    background: #fff5f5;
    border-color: #fed7d7;
}

.voice-status-badge.listening .voice-status-dot {
    background: var(--sl-red);
}

.voice-status-badge.listening .voice-status-text {
    color: var(--sl-red);
}

.voice-status-badge.processing {
    background: var(--sl-bg-subtle);
    border-color: var(--sl-border);
}

.voice-status-badge.speaking {
    background: var(--sl-blue-light);
    border-color: #bfdbfe;
}

.voice-status-badge.speaking .voice-status-dot {
    background: var(--sl-blue);
}

.voice-status-badge.speaking .voice-status-text {
    color: var(--sl-blue);
}

.voice-status-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--sl-blue);
    line-height: 1.2;
}

/* Live transcript box */
.voice-transcript-box {
    width: 100%;
    min-height: 56px;
    max-height: 180px;
    background: var(--sl-bg-page);
    border: 1px solid var(--sl-border);
    border-radius: 8px;
    padding: 9px 11px;
    box-sizing: border-box;
    overflow-y: auto;
    margin-bottom: 14px;
    text-align: left;
}

.voice-transcript-lead {
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
    color: var(--sl-text-primary);
    word-break: break-word;
}

/* Big Mic Button */
.voice-mic-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-bottom: 14px;
}

.voice-main-mic {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--sl-blue);
    border: 3px solid #ffffff;
    box-shadow: 0 3px 12px rgba(0, 51, 102, 0.2);
    color: var(--sl-white);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    padding: 0;
}

.voice-main-mic:hover {
    background: var(--sl-blue-dark);
    transform: scale(1.04);
}

.voice-main-mic.listening {
    background: var(--sl-red);
    box-shadow: 0 4px 14px rgba(220, 53, 69, 0.3);
}

.voice-main-mic.listening:hover {
    background: var(--sl-red-dark);
}

.voice-mic-hint {
    font-size: 11px;
    font-weight: 600;
    color: var(--sl-text-secondary);
}

/* Action buttons */
.voice-actions-bar {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.voice-action-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--sl-font);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    box-sizing: border-box;
}

.voice-stop-btn {
    background: #ffffff;
    border: 1.5px solid var(--sl-red);
    color: var(--sl-red);
}

.voice-stop-btn:hover {
    background: var(--sl-red);
    color: #ffffff;
}

.voice-switch-chat-btn {
    background: #ffffff;
    border: 1.5px solid var(--sl-blue);
    color: var(--sl-blue);
}

.voice-switch-chat-btn:hover {
    background: var(--sl-blue);
    color: #ffffff;
}

/* ==========================================================================
   10. MOBILE RESPONSIVENESS
   ========================================================================== */
@media (max-width: 640px) {
    .chat-button {
        bottom: 20px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .chat-button img {
        width: 38px;
        height: 38px;
    }

    .chat-tooltip {
        display: none !important;
    }

    .chat-widget {
        bottom: 80px;
        right: 12px;
        left: 12px;
        width: auto;
        height: calc(100vh - 96px);
        max-height: 560px;
        border-radius: 10px;
    }

    .chat-header {
        padding: 10px 12px;
    }

    .chat-header-title {
        font-size: 13.5px;
    }

    .chat-body {
        padding: 12px;
        gap: 10px;
    }

    .welcome-actions-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .welcome-action-btn {
        padding: 9px 12px;
        font-size: 13px;
    }

    .quick-actions {
        margin-left: 0;
    }

    .chat-footer {
        padding: 8px 10px;
    }

    .chat-input {
        font-size: 16px; /* Prevents auto-zoom in mobile Safari */
        padding: 8px 10px;
    }

    .chat-mic-btn,
    .chat-send-btn {
        width: 40px;
        height: 40px;
    }

    .voice-interface {
        padding: 12px 10px;
    }

    .voice-card {
        padding: 14px 12px;
    }

    .voice-avatar-wrap {
        width: 60px;
        height: 60px;
        margin-bottom: 8px;
    }

    .voice-avatar {
        width: 60px;
        height: 60px;
    }

    .voice-main-mic {
        width: 54px;
        height: 54px;
    }
}
