/* --- Base Layout --- */
body { font-family: -apple-system, sans-serif; background: #f0f2f5; padding: 15px; overflow-y: scroll; }
h1 { text-align: center; }
.container { max-width: 1100px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.input-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; width: 100%; }
input[type="text"] { padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px; flex: 1; font-size: 14px; outline: none; }
button, .btn-link { padding: 6px 12px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; background: #1877f2; color: #fff; font-size: 13px; height: 35px; box-sizing: border-box; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* --- Loading Overlay --- */
#loading-overlay { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh; 
    background: rgba(255,255,255,0.9); 
    z-index: 10000; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center;
}
.spinner { 
    width: 50px; 
    height: 50px; 
    border: 5px solid #f3f3f3; 
    border-top: 5px solid #1877f2; 
    border-radius: 50%; 
    animation: spin 1s linear infinite; 
    margin-bottom: 15px;
}
#loading-overlay span {
    font-weight: bold;
    color: #1877f2;
    font-family: 'Courier New', monospace;
    font-size: 16px;
}

/* --- Console --- */
#console { 
    background: #000000 !important; 
    color: #00ff00 !important; 
    padding: 10px 15px; 
    font-family: 'Courier New', monospace; 
    font-size: 12px; 
    line-height: 1.5; 
    height: 180px;    
    border-radius: 4px; 
    margin-bottom: 20px; 
    white-space: pre-wrap; 
    border-left: 5px solid #007acc; 
    overflow-y: auto; 
    box-sizing: border-box;
}

/* --- Grid & Cards --- */
.group-container { margin: 10px 0; background: #fafafa; padding: 10px; border: 1px solid #eee; border-radius: 6px; }
.group-header { font-size: 15px; border-bottom: 1px solid #eee; padding-bottom: 5px; font-weight: bold; text-align: left; }

.file-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); 
    row-gap: 15px; 
    column-gap: 5px; 
    list-style: none; 
    padding: 0; 
    margin-top: 10px; 
}

.file-card { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; }
.thumb-link { display: flex; width: 130px; height: 130px; align-items: center; justify-content: center; text-decoration: none; margin-bottom: 2px; position: relative; }
.thumb-img { max-width: 130px; max-height: 130px; width: auto; height: auto; border: 0; }
.file-label { font-family: sans-serif; font-size: 13px; line-height: 1.2; width: 100%; word-wrap: break-word; color: #333; }

/* --- Metadata Tooltip --- */
.meta-tooltip {
    display: none;
    background: #000000 !important;
    color: #ffffff !important;
    padding: 10px;
    border-radius: 4px;
    z-index: 9999;
    width: 260px;
    font-size: 11px;
    text-align: left;
    border: 1px solid #444; 
    box-shadow: 0 4px 15px rgba(0,0,0,1);
    word-wrap: break-word;
    pointer-events: none;
    white-space: normal;
    position: absolute;
    top: 132px;
    left: 0;
}

/* Flip class added via JS */
.meta-tooltip.flip-up {
    top: auto;
    bottom: 132px;
}

.meta-tags-line { display: block; font-size: 11px; border-bottom: 1px solid #444; padding-bottom: 4px; margin-bottom: 6px; font-weight: bold; }
.host-span { color: #00d4ff; }
.keyword-span { color: #00ff00; }
.count-span { color: #ffffff; }

.tt-list { margin: 5px 0 0 0; padding: 0 0 0 15px; list-style: disc; }
.tt-list li { 
    font-size: 11px; 
    border-bottom: 1px solid #333; 
    padding: 4px 0; 
    white-space: normal; 
    word-break: break-all;
    line-height: 1.4; 
}

/* --- (i) Info Button --- */
.info-btn {
    display: flex; 
    position: absolute;
    top: 5px;
    left: 5px;
    background: #ffffff !important; 
    color: #000000 !important;      
    border: 1px solid #000000 !important;
    border-radius: 50% !important;  
    width: 24px;
    height: 24px;
    z-index: 50;
    font-family: serif;
    font-style: italic;
    font-weight: bold;
    font-size: 16px;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* --- Interaction Logic --- */
@media (hover: hover) and (pointer: fine) {
    .info-btn { display: none; } 
    .file-card:hover .meta-tooltip {
        display: block;
    }
    /* Right column alignment logic */
    .file-card:nth-last-child(-n+4) .meta-tooltip {
        left: auto;
        right: 0;
    }
}

@media (pointer: coarse) {
    .info-btn { display: flex; }
    .info-btn:active + .meta-tooltip,
    .info-btn:focus + .meta-tooltip { 
        display: block; 
    }
    .meta-tooltip { 
        position: absolute; 
        top: 35px; 
        left: 5px; 
    }
    @media (max-width: 600px) {
        .meta-tooltip {
            position: fixed;
            top: auto;
            bottom: 0;
            left: 0;
            right: 0;
            width: 100%;
            border-radius: 12px 12px 0 0;
            max-height: 50vh;
            overflow-y: auto;
        }
    }
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
