/* Calculator Floating Styles */
.calc-floating-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: var(--bg-button);
    color: var(--text-button);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
    border: 2px solid var(--border-color);
}

.calc-floating-btn:hover {
    transform: scale(1.1);
    background: var(--bg-button-hover);
}

.calc-floating-btn.active {
    transform: rotate(180deg) scale(0);
    opacity: 0;
    pointer-events: none;
}

.calculator-container {
    display: none; /* Hidden by default */
    position: fixed;
    bottom: 80px; /* Above the button */
    right: 20px;
    z-index: 1000;
    width: 200px;
    background: var(--bg-form);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Cairo', sans-serif;
    direction: ltr;
    text-align: left;
}

.calculator-container.show {
    display: block;
    animation: calcSlideUp 0.3s ease;
}

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

/* Desktop - تكبير 25% */
@media (min-width: 768px) {
    .calc-floating-btn {
        width: 60px;
        height: 60px;
        font-size: 30px;
        bottom: 25px;
        right: 25px;
    }

    .calculator-container {
        width: 400px;
        /* 200px + 25% = 250px */
        bottom: 95px; /* 25px + 60px + 10px */
        right: 25px;
    }

    .calc-btn {
        height: 50px;
        /* 32px + 25% = 40px */
        font-size: 15px;
        /* 12px + 25% = 15px */
    }

    .calculator-display {
        height: 50px;
        /* 40px + 25% = 50px */
        font-size: 20px;
        /* 16px + 25% = 20px */
    }

    .calculator-history {
        min-height: 25px;
        font-size: 12px;
    }

    .calculator-header {
        padding: 10px 15px;
        /* زيادة الـ padding */
        font-size: 15px;
        /* 12px + 25% = 15px */
    }

    .calculator-body {
        padding: 10px;
        /* زيادة الـ padding */
    }
}

/* Tablet - تكبير 15% */
@media (min-width: 768px) and (max-width: 1023px) {
    .calc-floating-btn {
        width: 55px;
        height: 55px;
        font-size: 26px;
        bottom: 23px;
        right: 23px;
    }

    .calculator-container {
        width: 230px;
        /* 200px + 15% = 230px */
        bottom: 88px; /* 23px + 55px + 10px */
        right: 23px;
    }

    .calc-btn {
        height: 37px;
        /* 32px + 15% = 37px */
        font-size: 14px;
        /* 12px + 15% = 14px */
    }

    .calculator-display {
        height: 46px;
        /* 40px + 15% = 46px */
        font-size: 18px;
        /* 16px + 15% = 18px */
    }

    .calculator-history {
        min-height: 23px;
        font-size: 11px;
    }

    .calculator-header {
        padding: 9px 14px;
        /* زيادة الـ padding */
        font-size: 14px;
        /* 12px + 15% = 14px */
    }

    .calculator-body {
        padding: 9px;
        /* زيادة الـ padding */
    }
}

.calculator-header {
    background: var(--bg-button);
    color: var(--text-button);
    padding: 8px 12px;
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.calculator-body {
    padding: 8px;
    display: none;
}

.calculator-body.show {
    display: block;
}

.calculator-display-container {
    position: relative;
    margin-bottom: 8px;
}

.calculator-history {
    width: 100%;
    min-height: 20px;
    height: 30px;
    background: var(--bg-form-alt);
    border: 1px solid var(--border-color);
    border-radius: 4px 4px 0 0;
    padding: 4px 8px;
    font-size: 16px;
    text-align: left;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
    direction: ltr;
    box-sizing: border-box;
    border-bottom: none;
}

.calculator-display {
    width: 100%;
    height: 55px;
    background: var(--bg-form-alt);
    border: 1px solid var(--border-color);
    border-radius: 0 0 4px 4px;
    padding: 8px;
    font-size: 20px;
    text-align: right;
    color: var(--text-main);
    font-family: 'Courier New', monospace;
    direction: ltr;
    box-sizing: border-box;
    outline: none;
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.calc-btn {
    height: 50px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-form);
    color: var(--text-main);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    box-sizing: border-box;
    min-width: 0;
}

.calc-btn:hover {
    background: var(--table-row-hover);
}

.calc-btn:active {
    transform: scale(0.95);
}

.calc-btn.operator {
    background: var(--bg-button);
    color: var(--text-button);
}

.calc-btn.operator:hover {
    background: #1d4ed8;
}

.calc-btn.equals {
    background: var(--text-greens);
    color: white;
}

.calc-btn.equals:hover {
    background: #15803d;
}

.calc-btn.clear {
    background: var(--text-reds);
    color: white;
}

.calc-btn.clear:hover {
    background: #991b1b;
}

/* Mobile - الحجم الأصلي */
@media (max-width: 767px) {
    .calculator-container {
        width: 200px;
        /* الحجم الأصلي */
        bottom: 80px;
        right: 20px;
    }

    .calc-btn {
        height: 32px;
        /* الحجم الأصلي */
        font-size: 12px;
    }

    .calculator-display {
        height: 40px;
        /* الحجم الأصلي */
        font-size: 16px;
    }

    .calculator-history {
        min-height: 20px;
        font-size: 10px;
    }
}

/* Small Mobile - تصغير للشاشات الصغيرة جداً */
@media (max-width: 480px) {
    .calculator-container {
        width: 160px;
        bottom: 70px;
        right: 10px;
    }

    .calc-btn {
        height: 26px;
        font-size: 10px;
    }

    .calculator-display {
        height: 32px;
        font-size: 12px;
    }

    .calculator-history {
        min-height: 16px;
        font-size: 8px;
    }
}

/* Dark theme adjustments */
.theme-dark .calculator-container {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Ensure calculator is always visible */
.calculator-container {
    pointer-events: auto;
}

.calculator-container * {
    pointer-events: auto;
}

/* Pin button styles */
.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.calc-title {
    flex: 1;
    text-align: center;
}

.calc-pin-btn {
    background: none;
    border: none;
    font-size: 10px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.calc-pin-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.calc-pin-btn.pinned {
    opacity: 1;
    color: #fbbf24;
    /* لون ذهبي للدبوس المثبت */
    text-shadow: 0 0 4px rgba(251, 191, 36, 0.5);
}

/* Desktop adjustments for pin button */
@media (min-width: 1024px) {
    .calc-pin-btn {
        font-size: 12px;
        padding: 6px;
    }
}

/* Tablet adjustments for pin button */
@media (min-width: 768px) and (max-width: 1023px) {
    .calc-pin-btn {
        font-size: 15px;
        padding: 5px;
    }
}

/* Header buttons container */
.calc-header-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* History button styles */
.calc-history-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.calc-history-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Desktop adjustments for history button */
@media (min-width: 1024px) {
    .calc-history-btn {
        font-size: 18px;
        padding: 6px;
    }
}

/* Tablet adjustments for history button */
@media (min-width: 768px) and (max-width: 1023px) {
    .calc-history-btn {
        font-size: 17px;
        padding: 5px;
    }
}

/* Close button styles */
.calc-close-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
    color: var(--text-reds);
}

.calc-close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Desktop adjustments for close button */
@media (min-width: 1024px) {
    .calc-close-btn {
        font-size: 18px;
        padding: 6px;
    }
}

/* Tablet adjustments for close button */
@media (min-width: 768px) and (max-width: 1023px) {
    .calc-close-btn {
        font-size: 17px;
        padding: 5px;
    }
}

/* History Modal Styles */
.calc-history-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.calc-history-modal.show {
    display: flex;
}

.calc-history-modal-content {
    background: var(--bg-form);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    font-family: 'Cairo', sans-serif;
}

.calc-history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-button);
    color: var(--text-button);
    border-radius: 12px 12px 0 0;
}

.calc-history-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: bold;
}

.calc-history-modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.calc-history-clear-btn,
.calc-history-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s ease;
    color: white;
}

.calc-history-clear-btn:hover {
    background: var(--text-reds);
    transform: scale(1.1);
}

.calc-history-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.calc-history-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    direction: rtl;
}

.calc-history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 16px;
    padding: 40px 20px;
}

.calc-history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.calc-history-item {
    background: var(--bg-form-alt);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    direction: ltr;
}

.calc-history-item:hover {
    background: var(--table-row-hover);
    border-color: var(--bg-button);
    transform: translateX(-4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.calc-history-item-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calc-history-item-operation {
    font-family: 'Courier New', monospace;
    font-size: 16px;
    color: var(--text-main);
    font-weight: 500;
}

.calc-history-item-result {
    font-family: 'Courier New', monospace;
    font-size: 20px;
    color: var(--text-greens);
    font-weight: bold;
}

.calc-history-item-timestamp {
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'Cairo', sans-serif;
    direction: rtl;
}

/* Mobile adjustments for modal */
@media (max-width: 767px) {
    .calc-history-modal {
        padding: 10px;
    }

    .calc-history-modal-content {
        max-height: 90vh;
    }

    .calc-history-modal-header h3 {
        font-size: 16px;
    }

    .calc-history-item-operation {
        font-size: 14px;
    }

    .calc-history-item-result {
        font-size: 18px;
    }
}

/* Dark theme adjustments for modal */
.theme-dark .calc-history-modal {
    background: rgba(0, 0, 0, 0.7);
}

.theme-dark .calc-history-modal-content {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}