/* ===================================================================
   TECH Menuiserie — Site Auth Widget
   Unified auth + role-based app-switcher (Atlassian-style)
   Prefix: sa- (site-auth) to avoid collisions
   =================================================================== */

/* ── Trigger Button ── */
.sa-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1.5px solid rgba(0, 49, 104, 0.2);
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    margin-left: 12px;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.sa-trigger:hover {
    border-color: #003168;
    background: rgba(0, 49, 104, 0.06);
    transform: translateY(-1px);
}

.sa-trigger svg {
    width: 18px;
    height: 18px;
    stroke: #003168;
    fill: none;
    stroke-width: 1.8;
}

/* Logged-in: avatar with initials */
.sa-trigger.sa-logged-in {
    background: #ef7c1a;
    border-color: #ef7c1a;
    color: white;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0.5px;
}

.sa-trigger.sa-logged-in:hover {
    background: #d06810;
    border-color: #d06810;
}

.sa-trigger.sa-logged-in svg {
    display: none;
}

/* Green online dot */
.sa-trigger.sa-logged-in::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 9px;
    height: 9px;
    background: #22c55e;
    border: 2px solid white;
    border-radius: 50%;
}

/* ── Panel ── */
.sa-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 300px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 49, 104, 0.12), 0 1px 3px rgba(0, 0, 0, 0.06);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    z-index: 10010;
    overflow: hidden;
}

.sa-panel.sa-active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ── User Header ── */
.sa-user-header {
    padding: 16px;
    background: linear-gradient(135deg, #003168 0%, #004a9f 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sa-avatar-lg {
    width: 40px;
    height: 40px;
    background: #ef7c1a;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.sa-user-info {
    min-width: 0;
}

.sa-user-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sa-user-email {
    font-size: 12px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sa-role-badge {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
}

/* ── Section ── */
.sa-section {
    padding: 12px 16px 4px;
}

.sa-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6b7280;
    margin-bottom: 8px;
}

/* ── App Grid (Atlassian-style) ── */
.sa-app-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 0 12px 12px;
}

.sa-app-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    border-radius: 8px;
    text-decoration: none;
    color: #374151;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    transition: background 0.15s ease;
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    line-height: 1.3;
}

.sa-app-tile:hover {
    background: #f3f4f6;
}

.sa-app-tile.sa-tile-active {
    background: rgba(0, 49, 104, 0.08);
    color: #003168;
    font-weight: 600;
}

.sa-tile-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 18px;
}

/* Tile icon color themes */
.sa-tile-icon[data-theme="blue"] { background: #dbeafe; color: #1d4ed8; }
.sa-tile-icon[data-theme="orange"] { background: #ffedd5; color: #c2410c; }
.sa-tile-icon[data-theme="green"] { background: #dcfce7; color: #15803d; }
.sa-tile-icon[data-theme="purple"] { background: #ede9fe; color: #6d28d9; }
.sa-tile-icon[data-theme="rose"] { background: #ffe4e6; color: #be123c; }
.sa-tile-icon[data-theme="teal"] { background: #ccfbf1; color: #0f766e; }

/* ── Language Bar ── */
.sa-lang-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 13px;
    color: #374151;
}

.sa-lang-bar svg {
    flex-shrink: 0;
    stroke: #6b7280;
}

.sa-lang-select {
    margin-left: auto;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 4px 24px 4px 8px;
    font-size: 13px;
    font-family: inherit;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 6px center;
    appearance: none;
    cursor: pointer;
    color: #1f2937;
}

.sa-lang-select:focus {
    outline: 2px solid #003168;
    outline-offset: -1px;
    border-color: #003168;
}

/* ── Avatar Image ── */
.sa-avatar-img,
.sa-trigger-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* ── Avatar Upload Overlay ── */
.sa-avatar-upload {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 22px;
    height: 22px;
    background: #003168;
    border-radius: 50%;
    border: 2px solid white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.sa-avatar-upload:hover {
    background: #004a9f;
}

.sa-avatar-upload svg {
    width: 11px;
    height: 11px;
    stroke: white;
    fill: none;
}

/* ── Divider ── */
.sa-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0 16px;
}

/* ── Logout / Actions ── */
.sa-actions {
    padding: 8px 12px;
}

.sa-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    text-decoration: none;
}

.sa-action-btn:hover {
    background: #fef2f2;
    color: #dc2626;
}

.sa-action-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ── Logged Out Panel ── */
.sa-guest-panel {
    padding: 16px;
}

.sa-guest-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    border: none;
}

.sa-guest-btn:active {
    transform: scale(0.98);
}

.sa-guest-btn-primary {
    background: #003168;
    color: white;
    margin-bottom: 8px;
}

.sa-guest-btn-primary:hover {
    background: #004a9f;
}

.sa-guest-btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.sa-guest-btn-secondary:hover {
    background: #e5e7eb;
}

/* ── Wrapper (positioning context) ── */
.sa-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sa-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 80vh;
        overflow-y: auto;
    }

    .sa-panel.sa-active {
        transform: translateY(0);
    }

    .sa-panel:not(.sa-active) {
        transform: translateY(100%);
    }

    /* Backdrop for mobile */
    .sa-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 10009;
    }

    .sa-backdrop.sa-active {
        display: block;
    }
}

@media (min-width: 769px) {
    .sa-backdrop {
        display: none !important;
    }
}
