/* ============================================================
   Auth Bar CSS — Enhanced with Edge-Snap & API Key Support
   ============================================================ */

/* ── Base Layout ─────────────────────────────────────────── */
.floating-user-bar {
    position: fixed;
    top: 80px;
    right: 20px;
    background-color: #ffffff;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    cursor: move;
    z-index: 99999999;
    width: 260px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    opacity: 0.95;
    transform-origin: top right;
    touch-action: none;
    /* Smooth transitions for width/shape changes */
    transition: opacity 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease,
                width 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                height 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-radius 0.35s ease,
                padding 0.3s ease,
                left 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.floating-user-bar.dragging {
    transition: none !important;
    opacity: 1;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.floating-user-bar:not(.dragging):not(.snapped):hover {
    opacity: 1;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: scale(1.02);
}

/* ── Edge-Snap: Collapsed Avatar State ───────────────────── */
.floating-user-bar.snapped {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    padding: 6px !important;
    overflow: hidden;
    cursor: grab !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    opacity: 1;
    /* Subtle pulse to indicate it's interactive */
    animation: snap-breathe 3s ease-in-out infinite;
}

.floating-user-bar.snapped:hover {
    transform: scale(1.08) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22) !important;
    animation: none;
}

/* Left-edge snap: flat left side, round right */
.floating-user-bar.snapped-left {
    border-radius: 0 50% 50% 0 !important;
    left: 0 !important;
}

/* Right-edge snap: round left side, flat right */
.floating-user-bar.snapped-right {
    border-radius: 50% 0 0 50% !important;
}

/* Hide all bar content when snapped */
.floating-user-bar.snapped .user-info,
.floating-user-bar.snapped .user-details,
.floating-user-bar.snapped .login-btn-wrapper,
.floating-user-bar.snapped .refresh-button,
.floating-user-bar.snapped #message-widget-container {
    display: none !important;
    pointer-events: none;
}

.floating-user-bar.snapped .user-mini-profile {
    padding: 0 !important;
    justify-content: center !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;
}

.floating-user-bar.snapped .user-avatar {
    width: 48px !important;
    height: 48px !important;
    margin: 0 !important;
}

/* Small indicator dot on snapped bar */
.floating-user-bar.snapped::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: #4285f4;
    border-radius: 50%;
    border: 1.5px solid #fff;
    bottom: 2px;
    right: 2px;
    z-index: 1;
    animation: indicator-pulse 2s ease-in-out infinite;
}

.floating-user-bar.snapped-right::before {
    right: auto;
    left: 2px;
}

@keyframes snap-breathe {
    0%, 100% { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }
    50%       { box-shadow: 0 4px 20px rgba(66, 133, 244, 0.35); }
}

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

/* Snap hint — shows when bar is near edge during drag */
.snap-ghost {
    position: fixed;
    top: 0;
    width: 60px;
    height: 100%;
    background: linear-gradient(to right, rgba(66, 133, 244, 0.08), transparent);
    pointer-events: none;
    z-index: 99999998;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.snap-ghost.snap-ghost-right {
    background: linear-gradient(to left, rgba(66, 133, 244, 0.08), transparent);
    right: 0;
    left: auto;
}

.snap-ghost.visible {
    opacity: 1;
}

/* ── Mini Profile Row ─────────────────────────────────────── */
.user-mini-profile {
    display: flex;
    align-items: center;
    padding: 5px;
    border-radius: 8px;
    transition: background-color 0.3s ease;
    min-height: 44px;
}

.user-mini-profile:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* ── Avatar ───────────────────────────────────────────────── */
.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-right: 12px;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.user-mini-profile:hover .user-avatar {
    transform: scale(1.05);
}

/* ── Name ─────────────────────────────────────────────────── */
.user-name {
    font-weight: 600;
    font-size: 16px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s ease;
}

.user-mini-profile:hover .user-name {
    color: #007bff;
}

/* ── Detail Panel ─────────────────────────────────────────── */
.user-details {
    margin-top: 12px;
    padding: 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    display: none;
    animation: fadeIn 0.3s ease;
    font-size: 14px;
    line-height: 1.6;
    color: #495057;
}

/* ── Detail Rows ──────────────────────────────────────────── */
.detail-row {
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.3s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.detail-row:last-of-type {
    margin-bottom: 0;
}

.detail-row:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateX(3px);
}

.detail-label {
    font-weight: 500;
    color: #6c757d;
    margin-right: 8px;
    flex-shrink: 0;
}

/* ── API_KEY label with tooltip ───────────────────────────── */
.api-key-label {
    cursor: help;
    border-bottom: 1px dashed #adb5bd;
    position: relative;
    user-select: none;
}

.api-key-label::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 210px;
    background: rgba(33, 37, 41, 0.93);
    color: #f8f9fa;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 400;
    line-height: 1.5;
    white-space: normal;
    z-index: 100000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.api-key-label:hover::after {
    opacity: 1;
    transform: translateY(0);
}

/* ── Value Chips ──────────────────────────────────────────── */
.user-email,
.user-score,
.user-apikey {
    font-weight: 500;
    color: #343a40;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 148px;
    white-space: nowrap;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    font-size: 12.5px;
}

.user-email,
.user-score {
    font-family: inherit;
    font-size: 13px;
}

.user-email:hover,
.user-score:hover,
.user-apikey:hover {
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.user-score {
    color: #28a745;
    animation: pulse-subtle 2s infinite;
}

.user-apikey {
    color: #6610f2;
    letter-spacing: 0.03em;
    cursor: default;
}

/* Pulse for score */
@keyframes pulse-subtle {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.03); }
}

/* ── Buttons ──────────────────────────────────────────────── */
.login-btn-wrapper,
.logout-btn-wrapper {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.login-btn,
.logout-btn {
    padding: 10px 16px;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer !important;
    font-weight: 600;
    font-size: 14px;
    width: 100%;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s ease;
    position: relative;
    z-index: 2;
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.login-btn  { background-color: #4285f4; }
.logout-btn { background-color: #f44336; }

.login-btn:hover,
.login-btn:focus  { background-color: #1a73e8; box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.logout-btn:hover,
.logout-btn:focus { background-color: #d32f2f; box-shadow: 0 4px 8px rgba(0,0,0,0.15); }

.login-btn:active,
.logout-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    opacity: 0.9;
}

/* ── Logged-in / logged-out state ─────────────────────────── */
.logged-in  .login-btn-wrapper  { display: none; }
.logged-out .user-details       { display: none; }
.logged-out .logout-btn-wrapper { display: none; }
.logged-out .login-btn-wrapper  { display: block; }
.logged-in  .user-details       { display: block; }

/* ── Copy Controls ────────────────────────────────────────── */
.copy-button-container {
    display: flex;
    align-items: center;
    position: relative;
    width: 100%;
}

.copy-button {
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    background-color: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
    transform: translateX(-5px);
    margin-left: 6px;
    flex-shrink: 0;
}

.detail-row:hover .copy-button {
    opacity: 0.8;
    transform: translateX(0);
}

.copy-button:hover {
    opacity: 1 !important;
    background-color: rgba(108, 117, 125, 0.2);
    transform: scale(1.1);
}

.copy-button:active {
    transform: scale(0.95);
}

@keyframes copied-flash {
    0%   { background-color: rgba(40, 167, 69, 0.2); }
    100% { background-color: rgba(255, 255, 255, 0.8); }
}

.just-copied {
    animation: copied-flash 1s ease;
}

/* ── Minimize Button （左上角 "−"） ───────────────────────── */
.minimize-btn {
    position: absolute;
    top: 5px;
    left: 7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    color: #6c757d;
    font-size: 15px;
    line-height: 17px;
    text-align: center;
    cursor: pointer;
    z-index: 10;
    user-select: none;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
    /* 悬停前淡显 */
    opacity: 0.4;
}

.floating-user-bar:hover .minimize-btn {
    opacity: 1;
}

.minimize-btn:hover {
    background: rgba(244, 67, 54, 0.12);
    color: #e53935;
    transform: scale(1.18);
}

.minimize-btn:active {
    transform: scale(0.92);
}

/* 吸附状态下隐藏最小化按钮 */
.floating-user-bar.snapped .minimize-btn {
    display: none;
}

/* ── 内联倒计时标签（refresh wrap 内） ───────────────────── */
#refresh-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 5px;
    flex-shrink: 0;
}

/* 吸附状态下隐藏整个刷新区域 */
.floating-user-bar.snapped #refresh-wrap {
    display: none !important;
}

/* ── Refresh Button ───────────────────────────────────────── */
.refresh-button {
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    background-color: rgba(0, 123, 255, 0.1);
    color: #007bff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    /* margin handled by parent flex gap */
    flex-shrink: 0;
}

.refresh-button:hover {
    background-color: rgba(0, 123, 255, 0.2);
    transform: scale(1.1);
}


/* ── Notification System ──────────────────────────────────── */
#notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification {
    padding: 14px 18px;
    border-radius: 8px;
    max-width: 340px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: flex-start;
    transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0;
    transform: translateY(20px);
    position: relative;
}

.notification-icon {
    margin-right: 10px;
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.notification-close {
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.notification-close:hover { opacity: 1; }

.notification-content {
    flex-grow: 1;
    padding-right: 16px;
    font-size: 13.5px;
}

.notification-warning { background: #fff3cd; border-left: 4px solid #ffc107; color: #856404; }
.notification-error   { background: #f8d7da; border-left: 4px solid #dc3545; color: #721c24; }
.notification-success { background: #d4edda; border-left: 4px solid #28a745; color: #155724; }
.notification-info    { background: #d1ecf1; border-left: 4px solid #17a2b8; color: #0c5460; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Truncated name gradient ──────────────────────────────── */
.truncated-name {
    position: relative;
}

.truncated-name::after {
    content: '';
    position: absolute;
    right: 0; top: 0;
    height: 100%;
    width: 18px;
    background: linear-gradient(to right, transparent, #ffffff);
}

/* ── Email tooltip ────────────────────────────────────────── */
.user-email {
    position: relative;
    cursor: default;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .floating-user-bar {
        width: 230px;
        right: 10px;
        top: 70px;
    }

    .user-avatar {
        width: 42px;
        height: 42px;
    }

    .login-btn,
    .logout-btn {
        padding: 12px 16px;
    }

    .floating-user-bar {
        border: 1px solid rgba(0, 0, 0, 0.15);
    }

    .user-mini-profile:active,
    .login-btn:active,
    .logout-btn:active {
        background-color: rgba(0, 0, 0, 0.07);
    }
}