/**
 * SD Gifts — Frontend Styles
 *
 * Modal, gift grid, confirmation, trigger button, admin styles.
 * Uses SD CSS design system variables.
 *
 * @package SD_Gifts
 */

/* ── Modal Root ──────────────────────────────────────────── */

.sd-gifts-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 16px;
}

.sd-gifts-modal--open {
    opacity: 1;
    visibility: visible;
}

/* ── Modal Overlay (dark backdrop) ───────────────────────── */

.sd-gifts-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

/* ── Modal Container ─────────────────────────────────────── */

.sd-gifts-modal__container {
    position: relative;
    background: #fff;
    border-radius: var(--sd-radius-lg, 16px);
    width: 100%;
    max-width: 460px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    transform: scale(0.92) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    z-index: 1;
}

.sd-gifts-modal--open .sd-gifts-modal__container {
    transform: scale(1) translateY(0);
}

/* ── Header ──────────────────────────────────────────────── */

.sd-gifts-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--sd-gray-200, #eee);
    flex-shrink: 0;
}

.sd-gifts-modal__title {
    font-size: 18px;
    font-weight: 600;
    color: var(--sd-gray-800, #424242);
    margin: 0;
    line-height: 1.3;
}

.sd-gifts-modal__close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--sd-gray-100, #f5f5f5);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
    padding: 0;
    font-size: 18px;
    color: var(--sd-gray-500, #9e9e9e);
    line-height: 1;
}

.sd-gifts-modal__close:hover {
    background: var(--sd-gray-200, #eee);
    color: var(--sd-gray-800, #424242);
}

/* ── Gift Grid ───────────────────────────────────────────── */

.sd-gifts-modal__body {
    overflow-y: auto;
    flex: 1;
    padding: 16px 20px;
    overscroll-behavior: contain;
}

.sd-gifts-modal__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* ── Gift Item ───────────────────────────────────────────── */

.sd-gifts-modal__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 6px 10px;
    border-radius: var(--sd-radius-sm, 8px);
    cursor: pointer;
    border: 2px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    user-select: none;
    position: relative;
}

.sd-gifts-modal__item:hover {
    background: var(--sd-gray-100, #f5f5f5);
    transform: translateY(-2px);
}

.sd-gifts-modal__item--selected {
    border-color: var(--sd-primary, #ff4081);
    background: rgba(255, 64, 129, 0.06);
}

.sd-gifts-modal__item--sending {
    pointer-events: none;
    opacity: 0.5;
}

.sd-gifts-modal__item--premium::after {
    content: '\2605';
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    color: #ffc107;
}

.sd-gifts-modal__item-image {
    width: 60px;
    height: 60px;
    object-fit: contain;
    flex-shrink: 0;
}

.sd-gifts-modal__item-emoji {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    line-height: 1;
    flex-shrink: 0;
}

.sd-gifts-modal__item-price {
    margin-top: 6px;
    font-size: 12px;
    color: var(--sd-gray-500, #9e9e9e);
    text-align: center;
    line-height: 1.3;
    white-space: nowrap;
}

.sd-gifts-modal__item--selected .sd-gifts-modal__item-price {
    color: var(--sd-primary, #ff4081);
    font-weight: 600;
}

/* ── Footer ──────────────────────────────────────────────── */

.sd-gifts-modal__footer {
    border-top: 1px solid var(--sd-gray-200, #eee);
    padding: 14px 20px;
    background: var(--sd-gray-100, #f5f5f5);
    flex-shrink: 0;
    border-radius: 0 0 var(--sd-radius-lg, 16px) var(--sd-radius-lg, 16px);
    text-align: center;
}

.sd-gifts-modal__credits {
    font-size: 14px;
    color: var(--sd-gray-500, #9e9e9e);
}

.sd-gifts-modal__credits-value {
    font-weight: 700;
    color: var(--sd-gray-800, #424242);
}

/* ── Confirmation Bar ────────────────────────────────────── */

.sd-gifts-modal__confirm {
    display: none;
    flex-direction: column;
    gap: 12px;
    border-top: 1px solid var(--sd-gray-200, #eee);
    padding: 16px 20px;
    background: #fff;
    flex-shrink: 0;
}

.sd-gifts-modal__confirm--visible {
    display: flex;
}

.sd-gifts-modal__confirm-text {
    font-size: 14px;
    color: var(--sd-gray-800, #424242);
    text-align: center;
}

.sd-gifts-modal__confirm-text strong {
    color: var(--sd-primary, #ff4081);
}

.sd-gifts-modal__confirm-actions {
    display: flex;
    gap: 10px;
}

.sd-gifts-modal__confirm-btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.sd-gifts-modal__confirm-btn--send {
    background: var(--sd-primary, #ff4081);
    color: #fff;
}

.sd-gifts-modal__confirm-btn--send:hover {
    background: var(--sd-primary-dark, #c51162);
}

.sd-gifts-modal__confirm-btn--send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sd-gifts-modal__confirm-btn--cancel {
    background: var(--sd-gray-200, #eee);
    color: var(--sd-gray-800, #424242);
}

.sd-gifts-modal__confirm-btn--cancel:hover {
    background: var(--sd-gray-300, #ddd);
}

/* ── Success / Error Messages ────────────────────────────── */

.sd-gifts-modal__message {
    text-align: center;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    display: none;
    flex-shrink: 0;
}

.sd-gifts-modal__message--visible {
    display: block;
}

.sd-gifts-modal__message--success {
    background: #e8f5e9;
    color: #2e7d32;
    border-top: 1px solid #c8e6c9;
}

.sd-gifts-modal__message--error {
    background: #ffebee;
    color: #c62828;
    border-top: 1px solid #ffcdd2;
}

/* ── Spinner ─────────────────────────────────────────────── */

.sd-gifts-modal__spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: sd-gifts-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes sd-gifts-spin {
    to { transform: rotate(360deg); }
}

/* ── Gift Sent Animation ─────────────────────────────────── */

@keyframes sd-gifts-sent-pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.sd-gifts-modal__item--sent {
    animation: sd-gifts-sent-pulse 0.5s ease;
}

.sd-gifts-modal__item--sent .sd-gifts-modal__item-price {
    color: #2e7d32;
    font-weight: 600;
}

/* ── Trigger Button (on user profile) ────────────────────── */

.sd-gift-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    color: var(--sd-primary, #ff4081);
    border: 1.5px solid var(--sd-primary, #ff4081);
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}

.sd-gift-trigger:hover {
    background: var(--sd-primary, #ff4081);
    color: #fff;
}

.sd-gift-trigger svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ── Loading State (grid placeholder) ────────────────────── */

.sd-gifts-modal__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--sd-gray-500, #9e9e9e);
    font-size: 14px;
    gap: 8px;
}

.sd-gifts-modal__loading .sd-gifts-modal__spinner {
    border-color: var(--sd-gray-400, #bbb);
    border-top-color: transparent;
}

/* ── Empty State ─────────────────────────────────────────── */

.sd-gifts-modal__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--sd-gray-500, #9e9e9e);
    font-size: 14px;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .sd-gifts-modal {
        padding: 10px;
        align-items: flex-end;
    }

    .sd-gifts-modal__container {
        max-width: 100%;
        max-height: 85vh;
        border-radius: var(--sd-radius-lg, 16px) var(--sd-radius-lg, 16px) 0 0;
        transform: translateY(100%);
    }

    .sd-gifts-modal--open .sd-gifts-modal__container {
        transform: translateY(0);
    }

    .sd-gifts-modal__grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .sd-gifts-modal__item {
        padding: 10px 4px 8px;
    }

    .sd-gifts-modal__item-image,
    .sd-gifts-modal__item-emoji {
        width: 50px;
        height: 50px;
    }

    .sd-gifts-modal__item-emoji {
        font-size: 34px;
    }

    .sd-gifts-modal__footer {
        border-radius: 0;
    }
}

@media (max-width: 400px) {
    .sd-gifts-modal__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Gift Item Name ──────────────────────────────────────── */

.sd-gifts-modal__item-name {
    margin-top: 4px;
    font-size: 11px;
    color: var(--sd-gray-600, #757575);
    text-align: center;
    line-height: 1.2;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Gift Item Visual Wrapper ────────────────────────────── */

.sd-gifts-modal__item-visual {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Premium Badge on Gift Item ──────────────────────────── */

.sd-gifts-modal__item-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 9px;
    font-weight: 600;
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    color: #5d4600;
    padding: 1px 4px;
    border-radius: 4px;
    line-height: 1.3;
}

/* ── Flash Messages (inline in modal body) ───────────────── */

.sd-gifts-modal__flash {
    padding: 10px 16px;
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 12px;
    text-align: center;
}

.sd-gifts-modal__flash--error {
    background: #ffebee;
    color: #c62828;
}

.sd-gifts-modal__flash--info {
    background: #e3f2fd;
    color: #1565c0;
}

/* ── Message Wrap (optional textarea in modal) ───────────── */

.sd-gifts-modal__message-wrap {
    margin-top: 12px;
}

.sd-gifts-modal__message-wrap textarea.sd-gifts-modal__message {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--sd-gray-200, #eee);
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 14px;
    color: var(--sd-gray-800, #424242);
    background: var(--sd-gray-50, #fafafa);
    resize: none;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    min-height: 60px;
    display: block;
}

.sd-gifts-modal__message-wrap textarea.sd-gifts-modal__message:focus {
    outline: none;
    border-color: var(--sd-primary, #ff4081);
    background: #fff;
}

/* ── Actions Row in Footer ───────────────────────────────── */

.sd-gifts-modal__actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.sd-gifts-modal__cancel-btn,
.sd-gifts-modal__send-btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.sd-gifts-modal__cancel-btn {
    background: var(--sd-gray-200, #eee);
    color: var(--sd-gray-800, #424242);
}

.sd-gifts-modal__cancel-btn:hover {
    background: var(--sd-gray-300, #ddd);
}

.sd-gifts-modal__send-btn {
    background: var(--sd-primary, #ff4081);
    color: #fff;
}

.sd-gifts-modal__send-btn:hover {
    background: var(--sd-primary-dark, #c51162);
}

.sd-gifts-modal__send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Admin Styles ────────────────────────────────────────── */

.sd-gifts-admin__preview {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
    background: #f9f9f9;
    border: 1px solid #ddd;
}

.sd-gifts-admin__emoji-preview {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    font-size: 36px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.sd-gifts-admin__image-upload {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sd-gifts-admin__image-upload img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid #ddd;
}

/* ── Admin Status Badges ────────────────────────────────── */

.sd-gifts-admin__status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}

.sd-gifts-admin__status--active {
    background: #e8f5e9;
    color: #2e7d32;
}

.sd-gifts-admin__status--inactive {
    background: #f5f5f5;
    color: #9e9e9e;
}

.sd-gifts-admin__premium-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    color: #5d4600;
}

/* ═══════════════════════════════════════════════════════════
   RECEIVED GIFTS DISPLAY (on user profile views)
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-received {
    padding: 0 var(--sd-spacing-lg, 24px) var(--sd-spacing-md, 16px);
}

.sd-gifts-received__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--sd-gray-800, #424242);
    margin: var(--sd-spacing-lg, 24px) 0 var(--sd-spacing-sm, 8px);
}

.sd-gifts-received__grid {
    display: flex;
    gap: var(--sd-spacing-sm, 8px);
    overflow-x: auto;
    padding-bottom: var(--sd-spacing-sm, 8px);
    -webkit-overflow-scrolling: touch;
}

.sd-gifts-received__grid::-webkit-scrollbar {
    height: 4px;
}

.sd-gifts-received__grid::-webkit-scrollbar-thumb {
    background: var(--sd-gray-200, #eee);
    border-radius: 2px;
}

.sd-gifts-received__item {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--sd-spacing-sm, 8px);
    background: var(--sd-gray-50, #fafafa);
    border-radius: var(--sd-radius-sm, 8px);
    min-width: 72px;
    transition: transform 0.15s ease;
}

.sd-gifts-received__item:hover {
    transform: translateY(-2px);
}

.sd-gifts-received__item-image {
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin-bottom: 4px;
}

.sd-gifts-received__item-emoji {
    font-size: 28px;
    line-height: 1;
    margin-bottom: 4px;
}

.sd-gifts-received__item-from {
    font-size: 11px;
    color: var(--sd-gray-500, #9e9e9e);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px;
}

.sd-gifts-received__empty {
    font-size: 13px;
    color: var(--sd-gray-400, #bdbdbd);
    font-style: italic;
}

/* ═══════════════════════════════════════════════════════════
   CATEGORY TABS (filter within modal)
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-modal__categories {
    display: flex;
    gap: 4px;
    padding: 0 20px 8px;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.sd-gifts-modal__categories::-webkit-scrollbar {
    display: none;
}

.sd-gifts-modal__category-tab {
    padding: 5px 12px;
    border: 1px solid var(--sd-gray-200, #eee);
    border-radius: 16px;
    background: #fff;
    color: var(--sd-gray-600, #757575);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.sd-gifts-modal__category-tab:hover {
    background: var(--sd-gray-100, #f5f5f5);
}

.sd-gifts-modal__category-tab--active {
    background: var(--sd-primary, #ff4081);
    color: #fff;
    border-color: var(--sd-primary, #ff4081);
}

/* ═══════════════════════════════════════════════════════════
   SENDING OVERLAY (blocks modal during API call)
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-modal__sending-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 5;
    border-radius: var(--sd-radius-lg, 16px);
}

.sd-gifts-modal__sending-overlay .sd-gifts-modal__spinner {
    width: 32px;
    height: 32px;
    border-width: 3px;
    border-color: var(--sd-gray-200, #eee);
    border-top-color: var(--sd-primary, #ff4081);
}

.sd-gifts-modal__sending-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--sd-gray-800, #424242);
}

/* ═══════════════════════════════════════════════════════════
   SUCCESS STATE (replaces grid on success)
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-modal__success {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    text-align: center;
}

.sd-gifts-modal__success-icon {
    width: 64px;
    height: 64px;
    background: #e8f5e9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    animation: sd-gifts-bounce 0.5s ease;
}

.sd-gifts-modal__success-icon svg {
    width: 32px;
    height: 32px;
    color: #4caf50;
}

@keyframes sd-gifts-bounce {
    0%   { transform: scale(0); }
    50%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.sd-gifts-modal__success-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--sd-gray-800, #424242);
    margin: 0 0 8px;
}

.sd-gifts-modal__success-text {
    font-size: 14px;
    color: var(--sd-gray-500, #9e9e9e);
    margin: 0 0 24px;
}

.sd-gifts-modal__success-btn {
    padding: 10px 32px;
    border: none;
    border-radius: 24px;
    background: var(--sd-primary, #ff4081);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sd-gifts-modal__success-btn:hover {
    background: var(--sd-primary-dark, #c51162);
    box-shadow: 0 4px 16px rgba(255, 64, 129, 0.35);
}

/* ═══════════════════════════════════════════════════════════
   ERROR STATE
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-modal__error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    text-align: center;
}

.sd-gifts-modal__error-icon {
    width: 48px;
    height: 48px;
    background: #ffebee;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.sd-gifts-modal__error-icon svg {
    width: 24px;
    height: 24px;
    color: #f44336;
}

.sd-gifts-modal__error-text {
    font-size: 14px;
    color: #f44336;
    margin: 0 0 16px;
}

.sd-gifts-modal__error-retry {
    padding: 8px 24px;
    border: 1px solid var(--sd-gray-200, #eee);
    border-radius: 20px;
    background: #fff;
    color: var(--sd-gray-800, #424242);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.sd-gifts-modal__error-retry:hover {
    background: var(--sd-gray-100, #f5f5f5);
}

/* ═══════════════════════════════════════════════════════════
   GIFT SENT ANIMATION OVERLAY (floating emoji)
   ═══════════════════════════════════════════════════════════ */

.sd-gift-anim-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sd-gift-anim-overlay__emoji {
    font-size: 80px;
    animation: sd-gifts-fly-up 1.5s ease-out forwards;
}

@keyframes sd-gifts-fly-up {
    0%   { transform: scale(0.5) translateY(40px); opacity: 0; }
    30%  { transform: scale(1.2) translateY(0); opacity: 1; }
    70%  { transform: scale(1) translateY(-20px); opacity: 1; }
    100% { transform: scale(0.8) translateY(-80px); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════
   OPTIONAL MESSAGE INPUT (in confirm section)
   ═══════════════════════════════════════════════════════════ */

.sd-gifts-modal__msg-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--sd-gray-200, #eee);
    border-radius: var(--sd-radius-sm, 8px);
    font-size: 14px;
    color: var(--sd-gray-800, #424242);
    background: var(--sd-gray-50, #fafafa);
    resize: none;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
    margin-bottom: 10px;
}

.sd-gifts-modal__msg-input:focus {
    outline: none;
    border-color: var(--sd-primary, #ff4081);
    background: #fff;
}

.sd-gifts-modal__msg-input::placeholder {
    color: var(--sd-gray-400, #bdbdbd);
}

/* ═══════════════════════════════════════════════════════════
   PRINT — Hide modals & overlays
   ═══════════════════════════════════════════════════════════ */

@media print {
    .sd-gifts-modal,
    .sd-gift-anim-overlay {
        display: none !important;
    }
}
