/* ========================================
   CLAVIER MATHÉMATIQUE COMPACT & PUISSANT
   École Préparatoire ضفاف البحيرة
   Par Faouzi Gharbi
   ======================================== */

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --bg-light: #ecf0f1;
    --bg-dark: #34495e;
    --text-dark: #2c3e50;
    --border-color: #bdc3c7;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 15px rgba(0,0,0,0.2);
}

/* ========================================
   CONTENEUR PRINCIPAL COMPACT
   ======================================== */

.math-keyboard-compact {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    direction: rtl;
    position: relative;
    overflow: hidden;
}

/* Version flottante (optionnelle) */
.math-keyboard-compact.floating {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    max-width: 380px;
}

/* ========================================
   EN-TÊTE COMPACT
   ======================================== */

.mkc-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
}

.mkc-title {
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mkc-controls {
    display: flex;
    gap: 5px;
}

.mkc-btn-mini {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: rgba(255,255,255,0.2);
    color: white;
}

.mkc-btn-mini:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* ========================================
   BARRE D'ACCÈS RAPIDE ULTRA-COMPACT
   ======================================== */

.mkc-quick-bar {
    background: #f8f9fa;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.mkc-quick-bar.show {
    max-height: 150px;
}

.mkc-quick-section {
    margin-bottom: 8px;
}

.mkc-quick-section:last-child {
    margin-bottom: 0;
}

.mkc-quick-label {
    font-size: 10px;
    color: var(--primary-color);
    margin-bottom: 4px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mkc-quick-items {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.mkc-quick-symbol {
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid var(--secondary-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    position: relative;
}

.mkc-quick-symbol:hover {
    background: var(--secondary-color);
    color: white;
    transform: scale(1.15);
}

.mkc-quick-symbol .remove-x {
    position: absolute;
    top: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    font-size: 8px;
    display: none;
    align-items: center;
    justify-content: center;
}

.mkc-quick-symbol:hover .remove-x {
    display: flex;
}

.mkc-empty {
    font-size: 9px;
    color: #95a5a6;
    font-style: italic;
}

/* ========================================
   STATS MINI PANEL
   ======================================== */

.mkc-stats {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.mkc-stats.show {
    max-height: 200px;
}

.mkc-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.mkc-stat-item {
    background: rgba(255,255,255,0.2);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
}

.mkc-stat-label {
    font-size: 8px;
    opacity: 0.9;
    margin-bottom: 4px;
}

.mkc-stat-value {
    font-size: 18px;
    font-weight: bold;
}

.mkc-badge {
    background: rgba(255,255,255,0.2);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.mkc-badge-icon {
    font-size: 24px;
}

.mkc-badge-icon.locked {
    opacity: 0.3;
    filter: grayscale(100%);
}

.mkc-badge-text {
    font-size: 9px;
    flex: 1;
}

/* ========================================
   ONGLETS COMPACTS (ICÔNES)
   ======================================== */

.mkc-tabs {
    display: flex;
    background: var(--bg-light);
    border-bottom: 2px solid var(--secondary-color);
    overflow-x: auto;
    scrollbar-width: thin;
}

.mkc-tabs::-webkit-scrollbar {
    height: 3px;
}

.mkc-tabs::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.mkc-tab {
    flex: 0 0 auto;
    padding: 8px 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    position: relative;
}

.mkc-tab:hover {
    background: rgba(52, 152, 219, 0.1);
}

.mkc-tab.active {
    background: white;
    color: var(--secondary-color);
    border-bottom-color: var(--secondary-color);
}

.mkc-tab.suggested {
    animation: pulse-tab 1.5s infinite;
}

@keyframes pulse-tab {
    0%, 100% { background: rgba(52, 152, 219, 0.1); }
    50% { background: rgba(52, 152, 219, 0.3); }
}

.mkc-tab-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    margin-bottom: 5px;
}

.mkc-tab:hover .mkc-tab-tooltip {
    opacity: 1;
}

/* ========================================
   GRILLE DE SYMBOLES COMPACTE
   ======================================== */

.mkc-content {
    padding: 10px;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.mkc-content::-webkit-scrollbar {
    width: 6px;
}

.mkc-content::-webkit-scrollbar-track {
    background: var(--bg-light);
}

.mkc-content::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.mkc-symbols-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.mkc-symbol {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    position: relative;
}

.mkc-symbol:hover {
    background: var(--secondary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border-color: var(--secondary-color);
}

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

/* Étoile de favori */
.mkc-fav-star {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 10px;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
}

.mkc-symbol:hover .mkc-fav-star {
    opacity: 0.4;
}

.mkc-fav-star.active {
    opacity: 1 !important;
    color: var(--warning-color);
}

/* Raccourci clavier */
.mkc-symbol.has-shortcut::after {
    content: attr(data-shortcut);
    position: absolute;
    bottom: 1px;
    left: 1px;
    font-size: 7px;
    background: var(--warning-color);
    color: white;
    padding: 1px 3px;
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}

.mkc-symbol:hover.has-shortcut::after {
    opacity: 1;
}

/* ========================================
   TOOLTIP AMÉLIORÉ
   ======================================== */

.mkc-tooltip {
    position: fixed;
    background: var(--primary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 11px;
    z-index: 10000;
    box-shadow: var(--shadow-hover);
    max-width: 200px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.mkc-tooltip.show {
    opacity: 1;
}

.mkc-tooltip-name {
    font-weight: bold;
    margin-bottom: 3px;
    font-size: 12px;
}

.mkc-tooltip-example {
    font-style: italic;
    opacity: 0.9;
    font-size: 10px;
}

.mkc-tooltip-shortcut {
    margin-top: 3px;
    padding-top: 3px;
    border-top: 1px solid rgba(255,255,255,0.3);
    font-size: 9px;
    color: var(--warning-color);
}

/* ========================================
   APERÇU COMPACT
   ======================================== */

.mkc-preview {
    background: #fff9e6;
    border-top: 2px solid var(--warning-color);
    padding: 8px 10px;
    display: none;
    align-items: center;
    gap: 8px;
}

.mkc-preview.show {
    display: flex;
}

.mkc-preview-label {
    font-size: 11px;
    font-weight: bold;
    color: var(--primary-color);
}

.mkc-preview-display {
    flex: 1;
    padding: 6px 10px;
    background: white;
    border: 2px solid var(--warning-color);
    border-radius: 4px;
    font-size: 18px;
    text-align: center;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   TUTORIEL OVERLAY
   ======================================== */

.mkc-tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.mkc-tutorial-overlay.show {
    display: flex;
}

.mkc-tutorial {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.mkc-tutorial-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 15px;
    text-align: center;
    border-radius: 12px 12px 0 0;
}

.mkc-tutorial-header h2 {
    font-size: 18px;
    margin-bottom: 3px;
}

.mkc-tutorial-header p {
    font-size: 11px;
    opacity: 0.9;
}

.mkc-tutorial-body {
    padding: 20px;
}

.mkc-tutorial-step {
    margin-bottom: 15px;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    border-right: 3px solid var(--secondary-color);
}

.mkc-tutorial-step h3 {
    color: var(--secondary-color);
    margin-bottom: 6px;
    font-size: 14px;
}

.mkc-tutorial-step p {
    line-height: 1.5;
    color: var(--text-dark);
    font-size: 12px;
    margin-bottom: 5px;
}

.mkc-tutorial-step p:last-child {
    margin-bottom: 0;
}

.mkc-tutorial-example {
    background: white;
    padding: 8px;
    border-radius: 4px;
    margin-top: 6px;
    font-family: monospace;
    font-size: 14px;
    text-align: center;
}

.mkc-tutorial-footer {
    padding: 15px;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

.mkc-btn-tutorial {
    padding: 10px 25px;
    border: none;
    border-radius: 6px;
    background: var(--success-color);
    color: white;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.mkc-btn-tutorial:hover {
    background: #229954;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes slideInBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.math-keyboard-compact.floating {
    animation: slideInBottom 0.4s ease-out;
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.1); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

.mkc-badge-icon.unlocked {
    animation: bounceIn 0.5s ease-out;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
    .math-keyboard-compact {
        max-width: 100%;
        border-radius: 0;
    }
    
    .math-keyboard-compact.floating {
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        border-radius: 12px 12px 0 0;
    }
    
    .mkc-symbols-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }
    
    .mkc-symbol {
        min-height: 38px;
        font-size: 16px;
    }
}

/* ========================================
   MODE RÉDUIT (COLLAPSED)
   ======================================== */

.math-keyboard-compact.collapsed .mkc-tabs,
.math-keyboard-compact.collapsed .mkc-content,
.math-keyboard-compact.collapsed .mkc-preview,
.math-keyboard-compact.collapsed .mkc-quick-bar,
.math-keyboard-compact.collapsed .mkc-stats {
    display: none !important;
}

.math-keyboard-compact.collapsed {
    max-width: 200px;
}

.math-keyboard-compact.collapsed .mkc-header {
    cursor: pointer;
}

/* ========================================
   DRAGGABLE (si flottant)
   ======================================== */

.math-keyboard-compact.dragging {
    opacity: 0.8;
    cursor: move;
}

/* ========================================
   THÈMES SUPPLÉMENTAIRES (Optionnel)
   ======================================== */

/* Thème sombre */
.math-keyboard-compact.dark-theme {
    background: #1e1e1e;
    color: #e0e0e0;
}

.math-keyboard-compact.dark-theme .mkc-tabs {
    background: #2a2a2a;
}

.math-keyboard-compact.dark-theme .mkc-symbol {
    background: #2a2a2a;
    border-color: #3a3a3a;
    color: #e0e0e0;
}

.math-keyboard-compact.dark-theme .mkc-symbol:hover {
    background: var(--secondary-color);
    color: white;
}

/* Thème minimal */
.math-keyboard-compact.minimal-theme {
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.math-keyboard-compact.minimal-theme .mkc-header {
    background: var(--secondary-color);
}

.math-keyboard-compact.minimal-theme .mkc-symbol {
    border: 1px solid #ddd;
}
