/**
 * BIC Avaya - Frontend Styles
 *
 * @package BIC_Avaya
 */

/* CSS Variables */
:root {
    --bic-avaya-primary: #c8102e;
    --bic-avaya-primary-hover: #a00d25;
    --bic-avaya-secondary: #1a1a1a;
    --bic-avaya-success: #28a745;
    --bic-avaya-error: #dc3545;
    --bic-avaya-text: #333;
    --bic-avaya-text-light: #666;
    --bic-avaya-border: #ddd;
    --bic-avaya-bg: #fff;
    --bic-avaya-bg-light: #f8f9fa;
    --bic-avaya-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --bic-avaya-radius: 8px;
    --bic-avaya-transition: 0.2s ease;
}

/* Buttons Container */
.bic-avaya-buttons {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9998;
    display: flex;
    flex-direction: row;
    gap: 10px;
}

[dir="rtl"] .bic-avaya-buttons {
    right: auto;
    left: 20px;
}

/* Action Buttons */
.bic-avaya-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--bic-avaya-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--bic-avaya-transition);
    text-decoration: none;
    line-height: 1.4;
    /* Touch device improvements */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    user-select: none;
    -webkit-user-select: none;
}

.bic-avaya-btn:focus {
    outline: 2px solid var(--bic-avaya-primary);
    outline-offset: 2px;
}

.bic-avaya-btn--primary {
    background: var(--bic-avaya-primary);
    color: #fff;
}

.bic-avaya-btn--primary:hover {
    background: var(--bic-avaya-primary-hover);
}

.bic-avaya-btn--secondary {
    background: var(--bic-avaya-bg-light);
    color: var(--bic-avaya-text);
    border: 1px solid var(--bic-avaya-border);
}

.bic-avaya-btn--secondary:hover {
    background: var(--bic-avaya-border);
}

.bic-avaya-btn--chat,
.bic-avaya-btn--voice {
    background: var(--bic-avaya-primary);
    color: #fff;
    box-shadow: var(--bic-avaya-shadow);
    min-width: 120px;
}

.bic-avaya-btn--chat:hover,
.bic-avaya-btn--voice:hover {
    background: var(--bic-avaya-primary-hover);
    transform: translateY(-2px);
}

.bic-avaya-btn__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.bic-avaya-btn--loading {
    opacity: 0.7;
    pointer-events: none;
}

.bic-avaya-btn--loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: bic-avaya-spin 0.8s linear infinite;
    margin-left: 8px;
}

@keyframes bic-avaya-spin {
    to { transform: rotate(360deg); }
}

/* Panel (Slide-out container) */
.bic-avaya-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    height: 100svh; /* iOS: stable height unaffected by URL bar show/hide */
    background: var(--bic-avaya-bg);
    box-shadow: var(--bic-avaya-shadow);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transition: right var(--bic-avaya-transition);
    visibility: hidden;
    pointer-events: none;
    /* iOS: prevent overscroll bounce pushing controls offscreen */
    overscroll-behavior: contain;
}

[dir="rtl"] .bic-avaya-panel {
    right: auto;
    left: -400px;
    transition: left var(--bic-avaya-transition);
}

.bic-avaya-panel--open {
    right: 0;
    visibility: visible;
    pointer-events: auto;
}

[dir="rtl"] .bic-avaya-panel--open {
    right: auto;
    left: 0;
}

/* Panel Header */
.bic-avaya-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bic-avaya-primary);
    color: #fff;
}

.bic-avaya-panel__logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-right: 12px;
}

[dir="rtl"] .bic-avaya-panel__logo {
    margin-right: 0;
    margin-left: 12px;
}

.bic-avaya-panel__title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.bic-avaya-panel__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    border-radius: 4px;
    transition: background var(--bic-avaya-transition);
}

.bic-avaya-panel__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.bic-avaya-panel__close svg {
    width: 20px;
    height: 20px;
}

/* Panel Body */
.bic-avaya-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Chat sections should fill available space */
.bic-avaya-chat__section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.bic-avaya-chat__online,
.bic-avaya-chat__offline {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Chat interface should fill and use flexbox */
.bic-avaya-chat__interface {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Panel Footer */
.bic-avaya-panel__footer {
    padding: 12px 20px;
    border-top: 1px solid var(--bic-avaya-border);
    background: var(--bic-avaya-bg-light);
}

/* Forms */
.bic-avaya-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.bic-avaya-form__group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bic-avaya-form__group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--bic-avaya-text);
}

.bic-avaya-form__group input,
.bic-avaya-form__group select,
.bic-avaya-form__group textarea {
    padding: 10px 12px;
    border: 1px solid var(--bic-avaya-border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color var(--bic-avaya-transition);
}

.bic-avaya-form__group input:focus,
.bic-avaya-form__group select:focus,
.bic-avaya-form__group textarea:focus {
    outline: none;
    border-color: var(--bic-avaya-primary);
}

.bic-avaya-form__actions {
    margin-top: 8px;
}

.bic-avaya-form__actions .bic-avaya-btn {
    width: 100%;
}

.bic-avaya-form__status,
.bic-avaya-form__error {
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 14px;
    text-align: center;
}

.bic-avaya-form__status--error,
.bic-avaya-form__error {
    background: #fce8e8;
    color: var(--bic-avaya-error);
}

.bic-avaya-form__status--success {
    background: #e8f5e9;
    color: var(--bic-avaya-success);
}

/* Chat Specific Styles */
.bic-avaya-chat__messages {
    flex: 1;
    min-height: 150px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bic-avaya-bg-light);
    border-radius: var(--bic-avaya-radius);
}

.bic-avaya-chat__message {
    margin-bottom: 12px;
    max-width: 85%;
}

.bic-avaya-chat__message--user {
    margin-left: auto;
}

[dir="rtl"] .bic-avaya-chat__message--user {
    margin-left: 0;
    margin-right: auto;
}

.bic-avaya-chat__message-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.bic-avaya-chat__message--user .bic-avaya-chat__message-content {
    background: var(--bic-avaya-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .bic-avaya-chat__message--user .bic-avaya-chat__message-content {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

.bic-avaya-chat__message--agent .bic-avaya-chat__message-content {
    background: #fff;
    border: 1px solid var(--bic-avaya-border);
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .bic-avaya-chat__message--agent .bic-avaya-chat__message-content {
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.bic-avaya-chat__message--system .bic-avaya-chat__message-content {
    background: transparent;
    color: var(--bic-avaya-text-light);
    font-size: 12px;
    text-align: center;
    max-width: 100%;
    padding: 8px;
}

.bic-avaya-chat__message-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: var(--bic-avaya-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.bic-avaya-chat__message--user .bic-avaya-chat__message-meta {
    justify-content: flex-end;
}

/* Chat Controls */
.bic-avaya-chat__controls {
    flex-shrink: 0;
    padding: 16px 20px;
    background: var(--bic-avaya-bg);
    border-top: 1px solid var(--bic-avaya-border);
    position: sticky;
    bottom: 0;
    z-index: 1;
}

.bic-avaya-chat__typing {
    font-size: 12px;
    color: var(--bic-avaya-text-light);
    font-style: italic;
    margin-bottom: 8px;
    padding: 0 4px;
}

.bic-avaya-chat__input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 12px;
}

.bic-avaya-chat__input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--bic-avaya-border);
    border-radius: 6px;
    font-size: 14px;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

.bic-avaya-chat__input:focus {
    outline: none;
    border-color: var(--bic-avaya-primary);
}

.bic-avaya-chat__send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    padding: 0;
    background: var(--bic-avaya-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--bic-avaya-transition);
}

.bic-avaya-chat__send:hover {
    background: var(--bic-avaya-primary-hover);
}

.bic-avaya-chat__send svg {
    width: 18px;
    height: 18px;
}

.bic-avaya-chat__end-btn {
    width: 100%;
    padding: 10px;
    background: var(--bic-avaya-bg-light);
    border: 1px solid var(--bic-avaya-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--bic-avaya-text);
    cursor: pointer;
    transition: background var(--bic-avaya-transition);
}

.bic-avaya-chat__end-btn:hover {
    background: var(--bic-avaya-border);
}

/* Participants - shows agent names in chat */
.bic-avaya-chat__participants {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.bic-avaya-chat__participants:empty {
    display: none;
}

.bic-avaya-chat__participant {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bic-avaya-bg-light);
    border: 1px solid var(--bic-avaya-border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--bic-avaya-text);
}

.bic-avaya-chat__participant::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--bic-avaya-success);
    border-radius: 50%;
}

/* Feedback */
.bic-avaya-feedback {
    text-align: center;
}

.bic-avaya-feedback h3 {
    margin: 0 0 20px;
    font-size: 16px;
}

.bic-avaya-feedback__stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.bic-avaya-feedback__star {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--bic-avaya-border);
    transition: color var(--bic-avaya-transition), transform var(--bic-avaya-transition);
}

.bic-avaya-feedback__star:hover {
    color: #ffc107;
    transform: scale(1.1);
}

.bic-avaya-feedback__star--selected {
    color: #ffc107;
}

.bic-avaya-feedback__star--selected svg {
    fill: #ffc107;
}

.bic-avaya-feedback__star svg {
    width: 32px;
    height: 32px;
}

/* Success Message */
.bic-avaya-chat__success {
    text-align: center;
    padding: 40px 20px;
}

.bic-avaya-chat__success svg {
    width: 60px;
    height: 60px;
    color: var(--bic-avaya-success);
    margin-bottom: 16px;
}

.bic-avaya-chat__success p {
    font-size: 16px;
    color: var(--bic-avaya-text);
    margin: 0;
}

/* Offline Notice */
.bic-avaya-offline-notice {
    text-align: center;
    padding: 20px;
    background: var(--bic-avaya-bg-light);
    border-radius: var(--bic-avaya-radius);
    margin-bottom: 20px;
}

.bic-avaya-offline-notice h3 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--bic-avaya-text);
}

.bic-avaya-offline-notice p {
    margin: 0;
    font-size: 14px;
    color: var(--bic-avaya-text-light);
}

/* Mode Toggle */
.bic-avaya-chat__mode-toggle {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--bic-avaya-primary);
    border-radius: 6px;
    font-size: 14px;
    color: var(--bic-avaya-primary);
    cursor: pointer;
    transition: all var(--bic-avaya-transition);
}

.bic-avaya-chat__mode-toggle:hover {
    background: var(--bic-avaya-primary);
    color: #fff;
}

/* Voice Specific Styles */
.bic-avaya-voice__status {
    text-align: center;
    padding: 40px 20px;
}

.bic-avaya-voice__status-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bic-avaya-bg-light);
    border-radius: 50%;
    color: var(--bic-avaya-text);
}

.bic-avaya-voice__status-icon svg {
    width: 40px;
    height: 40px;
}

.bic-avaya-voice__status-icon--connecting {
    animation: bic-avaya-pulse 1.5s ease-in-out infinite;
}

.bic-avaya-voice__status-icon--active {
    background: var(--bic-avaya-success);
    color: #fff;
}

.bic-avaya-voice__status-icon--ended {
    background: var(--bic-avaya-error);
    color: #fff;
}

@keyframes bic-avaya-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.bic-avaya-voice__status-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--bic-avaya-text);
    margin-bottom: 8px;
}

.bic-avaya-voice__timer {
    font-size: 32px;
    font-weight: 300;
    color: var(--bic-avaya-text);
    font-family: monospace;
}

.bic-avaya-voice__final-time {
    font-size: 14px;
    color: var(--bic-avaya-text-light);
    margin-top: 8px;
}

/* Voice Controls */
.bic-avaya-voice__controls {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 20px;
}

.bic-avaya-voice__control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--bic-avaya-bg-light);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--bic-avaya-transition);
    min-width: 80px;
}

.bic-avaya-voice__control-btn:hover {
    background: var(--bic-avaya-border);
}

.bic-avaya-voice__control-btn svg {
    width: 28px;
    height: 28px;
    color: var(--bic-avaya-text);
}

.bic-avaya-voice__control-btn--end {
    background: var(--bic-avaya-error);
    color: #fff;
}

.bic-avaya-voice__control-btn--end:hover {
    background: #c82333;
}

.bic-avaya-voice__control-btn--end svg {
    color: #fff;
}

.bic-avaya-voice__control-btn[data-muted="true"] {
    background: var(--bic-avaya-error);
}

.bic-avaya-voice__control-btn[data-muted="true"] svg {
    color: #fff;
}

.bic-avaya-voice__control-label {
    font-size: 12px;
    color: inherit;
}

/* Call Button Icon */
.bic-avaya-btn--call {
    gap: 10px;
}

.bic-avaya-btn--call .bic-avaya-btn__icon {
    width: 22px;
    height: 22px;
}

/* Responsive */
@media (max-width: 480px) {
    .bic-avaya-panel {
        width: 100%;
        right: -100%;
    }

    .bic-avaya-panel--open {
        right: 0;
    }

    [dir="rtl"] .bic-avaya-panel {
        left: -100%;
    }

    [dir="rtl"] .bic-avaya-panel--open {
        left: 0;
    }

    .bic-avaya-buttons {
        bottom: 20px;
        right: 10px;
    }

    [dir="rtl"] .bic-avaya-buttons {
        right: auto;
        left: 10px;
    }

    .bic-avaya-btn--chat,
    .bic-avaya-btn--voice {
        min-width: 100px;
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* Body class when panel is open */
body.bic-avaya-panel-open {
    overflow: hidden;
}

@media (min-width: 481px) {
    body.bic-avaya-panel-open {
        overflow: auto;
    }
}

/* WordPress Admin Bar Offset */
.admin-bar .bic-avaya-panel {
    top: 32px;
    height: calc(100vh - 32px);
    height: calc(100svh - 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar .bic-avaya-panel {
        top: 46px;
        height: calc(100vh - 46px);
        height: calc(100svh - 46px);
    }
}

/* Form Intro Text */
.bic-avaya-form__intro {
    font-size: 14px;
    margin: 0 0 16px;
    color: var(--bic-avaya-text);
}

.bic-avaya-form__intro strong {
    color: var(--bic-avaya-secondary);
}

.bic-avaya-chat__mode-link {
    color: var(--bic-avaya-primary);
    text-decoration: none;
}

.bic-avaya-chat__mode-link:hover {
    text-decoration: underline;
}

/* Checkbox Group */
.bic-avaya-form__group--checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    clear: both;
    overflow: hidden;
}

.bic-avaya-form__group--checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.bic-avaya-form__group--checkbox label {
    font-size: 13px;
    font-weight: 400;
    margin: 0;
    padding-left: 4px;
}

[dir="rtl"] .bic-avaya-form__group--checkbox label {
    padding-left: 0;
    padding-right: 4px;
}

/* Form Error Styling */
.bic-avaya-form__error {
    display: none;
    font-size: 12px;
    color: var(--bic-avaya-error);
    padding: 4px 0;
}

.bic-avaya-form__error:not(:empty) {
    display: block;
}

/* Form Input/Select Base */
.bic-avaya-form__input,
.bic-avaya-form__select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--bic-avaya-border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color var(--bic-avaya-transition);
    box-sizing: border-box;
}

.bic-avaya-form__input:focus,
.bic-avaya-form__select:focus {
    outline: none;
    border-color: var(--bic-avaya-primary);
}

/* No Agents Message */
.bic-avaya-chat__no-agents {
    padding: 16px;
    background: var(--bic-avaya-bg-light);
    border-radius: var(--bic-avaya-radius);
    text-align: center;
    font-size: 14px;
    color: var(--bic-avaya-text);
}
