/**
 * 🎨 أنماط لوحة المفاتيح الافتراضية المتقدمة
 * Advanced Virtual Keyboard Styles
 */

/* ==================== متغيرات CSS ==================== */
:root {
    --keyboard-primary: #667eea;
    --keyboard-secondary: #764ba2;
    --keyboard-light: #1e1e2e;
    --keyboard-border: #3a3a4a;
    --keyboard-text: #e0e0e0;
    --keyboard-hover: rgba(102, 126, 234, 0.2);
    --keyboard-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* ==================== الحاوية الرئيسية ==================== */
.advanced-keyboard-container {
    display: none;
    flex-direction: column;
    background: #1a1a2e;
    border-radius: 12px;
    box-shadow: var(--keyboard-shadow);
    backdrop-filter: blur(15px);
    border: 1px solid var(--keyboard-border);
    padding: 0.5rem;
    gap: 0.3rem;
    position: fixed;
    z-index: 9999;
    width: 550px;
    color: var(--keyboard-text);
    direction: rtl;
}

.advanced-keyboard-container[dir="ltr"] {
    direction: ltr;
}

.advanced-keyboard-container[dir="rtl"] {
    direction: rtl;
}

/* ==================== رأس لوحة المفاتيح ==================== */
.keyboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.5rem;
    background: linear-gradient(135deg, var(--keyboard-primary) 0%, var(--keyboard-secondary) 100%);
    border-radius: 6px;
    color: white;
    font-weight: 600;
    letter-spacing: 0.3px;
    touch-action: none;
    user-select: none;
}

.keyboard-title {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
}

.keyboard-title i {
    font-size: 0.8rem;
}

/* ==================== عناصر التحكم ==================== */
.keyboard-controls {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    direction: inherit;
}

.lang-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.6rem;
    transition: all 0.2s ease;
    min-width: 22px;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.lang-btn.active {
    background: rgba(255, 255, 255, 0.35);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

.theme-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.6rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
}

.theme-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.keyboard-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 0.05rem;
}

.keyboard-close-btn:hover {
    transform: rotate(90deg);
}

/* ==================== محتوى لوحة المفاتيح ==================== */
.keyboard-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    direction: inherit;
}

/* ==================== صفوف المفاتيح ==================== */
.keyboard-row {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    flex-wrap: nowrap;
    direction: inherit;
}

.advanced-keyboard-container[dir="rtl"] .keyboard-row {
    flex-direction: row-reverse;
}

.advanced-keyboard-container[dir="ltr"] .keyboard-row {
    flex-direction: row;
}

.symbols-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    width: 100%;
    direction: inherit;
}

.numbers-row {
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
    padding: 0.2rem;
    border-radius: 6px;
    border: 1px solid var(--keyboard-border);
    gap: 0.2rem !important;
    flex-wrap: nowrap;
}

.advanced-keyboard-container[dir="rtl"] .numbers-row {
    flex-direction: row-reverse;
}

.symbols-row {
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.03) 0%, transparent 100%);
    padding: 0.2rem;
    border-radius: 6px;
    border: 1px solid var(--keyboard-border);
    gap: 0.2rem !important;
    flex: 1;
    justify-content: center;
    flex-wrap: nowrap;
}

.advanced-keyboard-container[dir="rtl"] .symbols-row {
    flex-direction: row-reverse;
}

.letters-row {
    justify-content: center;
}

.control-row {
    margin-top: 0.15rem;
    gap: 0.3rem;
}

/* ==================== المفاتيح ==================== */
.keyboard-key {
    background: #2a2a3e;
    border: 1px solid var(--keyboard-border);
    color: var(--keyboard-text);
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.65rem;
    width: 36px;
    height: 30px;
    flex: 0 0 auto;
    min-width: 32px;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    user-select: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* تأثيرات المفاتيح */
.keyboard-key:hover {
    border-color: var(--keyboard-primary);
    background: #3a3a4e;
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.2);
}

.keyboard-key:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.keyboard-key.active {
    background: linear-gradient(135deg, var(--keyboard-primary) 0%, var(--keyboard-secondary) 100%);
    color: white;
    border-color: var(--keyboard-secondary);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(102, 126, 234, 0.3);
    transform: scale(0.95);
}

.keyboard-key.hover {
    border-color: var(--keyboard-primary);
    background: #3a3a4e;
}

/* مفاتيح التحكم */
.key-caps,
.key-space,
.key-backspace {
    font-weight: 700;
    letter-spacing: 0.3px;
}

.key-caps {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
    color: white;
    border: none;
    flex: 0 0 56px;
    width: 56px;
    padding: 0.5rem 0.6rem;
}

.key-caps:hover {
    box-shadow: 0 3px 10px rgba(255, 107, 107, 0.3);
    transform: translateY(-2px);
}

.key-caps:active {
    transform: translateY(0);
}

.key-caps.active-caps {
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 107, 107, 0.3);
}

.key-space {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    font-size: 0.65rem;
    flex: 1 1 70px;
    width: 70px;
    min-width: 70px;
    padding: 0.25rem 0.3rem;
}

.key-space:hover {
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.key-space:active {
    transform: translateY(0);
}

.key-backspace {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border: none;
    flex: 0 0 65px;
    width: 65px;
    padding: 0.25rem 0.3rem;
    font-size: 0.65rem;
}

.key-backspace:hover {
    box-shadow: 0 3px 10px rgba(245, 158, 11, 0.3);
    transform: translateY(-2px);
}

.key-backspace:active {
    transform: translateY(0);
}

.key-shift {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border: none;
    flex: 0 0 48px;
    width: 48px;
    padding: 0.25rem 0.3rem;
    font-size: 0.65rem;
}

.key-shift:hover {
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.3);
    transform: translateY(-2px);
}

.key-shift.active-shift {
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.3), 0 0 10px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
}

.key-enter {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    flex: 0 0 55px;
    width: 55px;
    padding: 0.25rem 0.3rem;
    font-size: 0.65rem;
}

.key-enter:hover {
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
    transform: translateY(-2px);
}

.key-enter:active {
    transform: translateY(0);
}

.hidden-key {
    display: none !important;
}

/* ==================== أزرار الملاحة للرموز ==================== */
.symbol-nav-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 4px;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    user-select: none;
}

/* ==================== مقبض تغيير الحجم ==================== */
.keyboard-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 40px;
    height: 40px;
    cursor: nwse-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    font-size: 1.2rem;
    background: linear-gradient(135deg, transparent 0%, rgba(102, 126, 234, 0.2) 100%);
    border-radius: 0 0 12px 0;
    transition: all 0.2s ease;
    user-select: none;
    touch-action: none;
}

.keyboard-resize-handle:hover {
    background: linear-gradient(135deg, transparent 0%, rgba(102, 126, 234, 0.4) 100%);
    color: #764ba2;
}

.symbol-nav-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.symbol-nav-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.key-number {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    font-weight: 700;
    width: 36px;
    flex: 0 0 36px;
    padding: 0.25rem 0.3rem;
    font-size: 0.65rem;
}

.key-number:hover {
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
    transform: translateY(-2px);
}

.key-number:active {
    transform: translateY(0);
}

.key-symbol {
    background: linear-gradient(135deg, #9333ea 0%, #7e22ce 100%);
    color: white;
    border: none;
    font-weight: 600;
    width: 36px;
    flex: 0 0 36px;
    padding: 0.25rem 0.3rem;
    font-size: 0.65rem;
}

.key-symbol:hover {
    box-shadow: 0 3px 10px rgba(147, 51, 234, 0.3);
    transform: translateY(-2px);
}

.key-symbol:active {
    transform: translateY(0);
}

/* ==================== أيقونة لوحة المفاتيح الصغيرة ==================== */
.keyboard-icon-mini {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--keyboard-primary);
    font-size: 1rem;
    opacity: 0.6;
    transition: all 0.2s ease;
    z-index: 10;
    padding: 0.5rem;
}

.keyboard-icon-mini:hover {
    opacity: 1;
    transform: translateY(-50%) scale(1.15);
    color: var(--keyboard-secondary);
}

/* ==================== الحقول مع لوحة المفاتيح ==================== */
.keyboard-field-wrapper {
    transition: all 0.2s ease;
}

.keyboard-field-wrapper input,
.keyboard-field-wrapper textarea {
    padding-left: 35px !important;
    transition: all 0.2s ease;
}

.keyboard-field-wrapper.has-content input,
.keyboard-field-wrapper.has-content textarea {
    border-color: var(--keyboard-primary) !important;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
}

.keyboard-input-active {
    animation: inputPulse 0.3s ease;
}

@keyframes inputPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    100% {
        box-shadow: 0 0 0 8px rgba(102, 126, 234, 0);
    }
}

/* ==================== الرسوميات والتأثيرات ==================== */
@keyframes slideUpKeyboard {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.keyboard-show {
    display: flex !important;
    animation: slideUpKeyboard 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* تأثير الموجة على المفاتيح */
.keyboard-key::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* ==================== الاستجابة للشاشات الصغيرة ==================== */
@media (max-width: 768px) {
    .advanced-keyboard-container {
        width: 90vw;
        max-width: 500px;
        padding: 0.6rem;
        bottom: 5px;
    }
    
    .keyboard-key {
        width: 40px;
        height: 32px;
        flex: 0 0 40px;
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .keyboard-row {
        gap: 0.35rem;
    }
    
    .keyboard-content {
        gap: 0.35rem;
    }
    
    .symbols-container {
        gap: 0.25rem;
    }
    
    .symbol-nav-btn {
        width: 34px;
        height: 32px;
        flex: 0 0 34px;
        font-size: 0.85rem;
    }
    
    .keyboard-header {
        padding: 0.4rem 0.6rem;
    }
    
    .keyboard-title {
        font-size: 0.8rem;
    }
    
    .keyboard-title i {
        font-size: 0.9rem;
    }
    
    .key-caps,
    .key-shift {
        width: 50px;
        flex: 0 0 50px;
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .key-backspace {
        width: 80px;
        flex: 0 0 80px;
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .key-enter {
        width: 65px;
        flex: 0 0 65px;
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .key-space {
        width: 90px;
        min-width: 90px;
        flex: 1 1 90px;
        padding: 0.4rem;
        font-size: 0.7rem;
    }
}

@media (max-width: 768px) {
    .keyboard-resize-handle {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .advanced-keyboard-container {
        width: calc(100vw - 8px);
        max-width: 95vw;
        padding: 0.5rem;
        bottom: 3px;
    }
    
    .keyboard-row {
        gap: 0.25rem;
    }
    
    .symbols-container {
        gap: 0.2rem;
    }
    
    .symbol-nav-btn {
        width: 32px;
        height: 32px;
        flex: 0 0 32px;
        font-size: 0.8rem;
    }
    
    .keyboard-resize-handle {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .keyboard-key {
        width: 35px;
        height: 30px;
        flex: 0 0 35px;
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .keyboard-title {
        font-size: 0.75rem;
    }
    
    .keyboard-header {
        padding: 0.3rem 0.5rem;
    }
    
    .lang-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
        min-width: 24px;
    }
    
    .keyboard-controls {
        gap: 0.3rem;
    }
    
    .key-caps,
    .key-shift {
        width: 45px;
        flex: 0 0 45px;
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .key-backspace {
        width: 70px;
        flex: 0 0 70px;
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .key-enter {
        width: 60px;
        flex: 0 0 60px;
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .key-space {
        width: 70px;
        min-width: 70px;
        flex: 1 1 70px;
        padding: 0.3rem;
        font-size: 0.65rem;
    }
    
    .key-number {
        width: 35px;
        flex: 0 0 35px;
        padding: 0.3rem 0.4rem;
        font-size: 0.7rem;
    }
}

/* ==================== موضع بديل للفيديو ==================== */
.advanced-keyboard-container.top-position {
    bottom: auto;
    top: 100px;
}

/* ==================== وضع الشاشة الكاملة ==================== */
.advanced-keyboard-container.fullscreen-mode {
    width: 95vw;
    max-width: 1200px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    bottom: 30px;
}

/* ==================== تأثيرات الاهتزاز والنبض ==================== */
@keyframes keyboardVibrate {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.keyboard-vibrate {
    animation: keyboardVibrate 0.3s ease;
}

/* ==================== نمط مظلم ==================== */
@media (prefers-color-scheme: dark) {
    .advanced-keyboard-container {
        background: #1a1a2e;
        border-color: #3a3a4a;
    }
    
    .keyboard-key {
        background: #2a2a3e;
        border-color: #3a3a4a;
        color: #e0e0e0;
    }
    
    .keyboard-key:hover {
        background: #3a3a4e;
        border-color: #667eea;
    }
    
    .keyboard-icon-mini {
        color: var(--keyboard-primary);
    }
    
    .numbers-row {
        background: rgba(102, 126, 234, 0.08);
        border-color: #3a3a4a;
    }
}

/* ==================== الثيمات: ليلي / نهاري ==================== */

/* الوضع الليلي (الافتراضي) */
.advanced-keyboard-container.dark-theme {
    background: #1a1a2e;
    border-color: #3a3a4a;
    color: #e0e0e0;
}

.dark-theme .keyboard-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.dark-theme .keyboard-key {
    background: #2a2a3e;
    border-color: #3a3a4a;
    color: #e0e0e0;
}

.dark-theme .keyboard-key:hover {
    background: #3a3a4e;
    border-color: #667eea;
}

.dark-theme .numbers-row,
.dark-theme .symbols-row {
    background: rgba(102, 126, 234, 0.05);
    border-color: #3a3a4a;
}

.dark-theme .key-number {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.dark-theme .key-symbol {
    background: linear-gradient(135deg, #9333ea 0%, #7e22ce 100%);
}

.dark-theme .key-space {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.dark-theme .key-backspace {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.dark-theme .key-shift {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
}

.dark-theme .key-enter {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* الوضع النهاري */
.advanced-keyboard-container.light-theme {
    background: #f5f5f7;
    border-color: #d0d0d5;
    color: #333333;
}

.light-theme .keyboard-header {
    background: linear-gradient(135deg, #5567d8 0%, #6c5b93 100%);
    color: white;
}

.light-theme .keyboard-title {
    color: white;
}

.light-theme .keyboard-key {
    background: #ffffff;
    border-color: #d0d0d5;
    color: #333333;
}

.light-theme .keyboard-key:hover {
    background: #e8e8ed;
    border-color: #5567d8;
}

.light-theme .numbers-row,
.light-theme .symbols-row {
    background: rgba(85, 103, 216, 0.05);
    border-color: #d0d0d5;
}

.light-theme .key-number {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
}

.light-theme .key-symbol {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    color: white;
}

.light-theme .key-space {
    background: linear-gradient(135deg, #5567d8 0%, #6c5b93 100%);
    color: white;
}

.light-theme .key-backspace {
    background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    color: white;
}

.light-theme .key-shift {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
}

.light-theme .key-enter {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
}

.light-theme .lang-btn,
.light-theme .theme-btn {
    background: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.15);
    color: white;
}

.light-theme .lang-btn:hover,
.light-theme .theme-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.light-theme .symbol-nav-btn {
    background: linear-gradient(135deg, #5567d8 0%, #6c5b93 100%);
    color: white;
}

/* ==================== طباعة الطباعة ==================== */
@media print {
    .advanced-keyboard-container {
        display: none !important;
    }
}