/* Reusable UI components: Category cards, File/Folder cards, and Search. */
/* ─── Home Category Cards ─── */
#card1 a, #card2 a, #card3 a, #card4 a {
    display: flex;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 20px;
    margin-right: 60%;
    border-radius: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s, color 1s;
    color: white;
    font-size: 20px;
    text-decoration: none;
}

#card1 a { background-color: var(--card1-bg); }
#card2 a { background-color: var(--card2-bg); }
#card3 a { background-color: var(--card3-bg); }
#card4 a { background-color: var(--card4-bg); }

#card1 img, #card2 img, #card3 img, #card4 img {
    margin: 5px;
}

#card1 a:hover, #card2 a:hover, #card3 a:hover, #card4 a:hover {
    transform: translateY(-5px);
    background-color: #e0e0ff;
    color: black;
}

.cover {
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
    height: 150px;
    width: auto;
}

h2 {
    background-color: rgb(255, 255, 255);
}

@media (max-width: 720px) {    
    #card1 a, #card2 a, #card3 a, #card4 a {
        margin-right: 0;
    } 
}

/* ─── Level Filter Segmented Control (Preview) ─── */
.level-selector-wrap {
    display: flex;
    align-items: center;
    margin: 16px 0 8px 0;
}

.level-segmented-bar {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 3px;
    gap: 3px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.level-chip-btn {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: transparent;
    padding: 6px 20px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    color: rgba(255, 255, 255, 0.95);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.level-chip-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.2);
}

.level-chip-btn.active {
    background: #ffffff;
    color: #1565c0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

html.dark .level-segmented-bar {
    background: rgba(30, 36, 48, 0.85);
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

html.dark .level-chip-btn {
    color: #94a3b8;
}

html.dark .level-chip-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

html.dark .level-chip-btn.active {
    background: #3b82f6;
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.5);
}

.folder-meta-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0 10px 4px;
}

.folder-level-wrap {
    margin: 0;
}

/* ─── Search Bar ─── */
.search-container {
    margin-bottom: 10px;
    text-align: center;
}

.search-input-wrapper {
    position: relative;
    display: inline-block;
    width: 80%;
    max-width: 400px;
}

#searchInput {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 32px 6px 10px;
    font-size: 14px;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    border-radius: 5px;
    outline: none;
    transition: 0.2s;
}

#searchInput:focus {
    border-color: #0073e6;
    box-shadow: 0 0 3px rgba(0,115,230,0.5);
}

.search-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, opacity 0.15s;
}

.search-clear-btn:hover {
    color: var(--text-main);
    opacity: 1;
}

.search-clear-btn.hidden {
    display: none !important;
}

/* ─── Explorer Cards & Actions ─── */
.folder-actions-bar {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

#downloadSelected {
    background-color: #007BFF;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

#downloadSelected:hover:not(:disabled) {
    background-color: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

#downloadSelected:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.select-all-toggle {
    background: #f0f4f8;
    color: #1e88e5;
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid #d1d9e6;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
    user-select: none;
}

.select-all-toggle:hover {
    background: #e1e9f1;
    border-color: #b8c5d6;
}

.folder-card {
    background: var(--bg-folder);
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s ease;
    margin: 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.folder-card:hover {
    background: var(--bg-folder-hover);
}

.file-card {
    background: var(--bg-card);
    padding: 8px;
    border-radius: 5px;
    margin: 5px;
}

.folder-top, .file-top {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.folder-checkbox {
    width: 17px;
    height: 17px;
    cursor: pointer;
}

.file-card span {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ---- Badges & Meta ---- */
.card-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 16px;
    gap: 6px;
}

.file-count {
    font-size: 0.78rem;
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.28);   /* dark pill => white text reads clearly on every card colour */
    color: white;
    padding: 2px 10px;
    border-radius: 20px;
    display: inline-block;
    width: fit-content;
    letter-spacing: 0.3px;
}

.folder-count-badge {
    font-size: 0.75rem;
    background-color: var(--badge-bg);
    color: var(--badge-color);
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
    margin-left: 8px;
}

.folder-meta {
    margin: 6px 0 10px 4px;
}

.folder-file-count {
    font-size: 0.82rem;
    color: var(--text-secondary);
    background-color: var(--bg-meta);
    padding: 3px 10px;
    border-radius: 10px;
}

/* ─── Skeletons & Shimmer ─── */
@keyframes shimmer {
    0%   { background-color: var(--skeleton-a); }
    50%  { background-color: var(--skeleton-b); }
    100% { background-color: var(--skeleton-a); }
}

.skeleton-pulse {
    animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-line {
    background: var(--skeleton-base);
    border-radius: 4px;
    display: block;
}

.skeleton-home-card {
    pointer-events: none;
    cursor: default;
}

.skeleton-cover {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    background: var(--skeleton-base);
    margin-bottom: 10px;
}

.skeleton-count {
    display: inline-block;
    width: 60px;
    height: 12px;
    border-radius: 4px;
    background: var(--skeleton-base);
    vertical-align: middle;
}

.skeleton-file-card {
    background: var(--skeleton-file);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 80px;
}

/* ─── File Card Action Buttons ─── */
.file-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.file-actions a, 
.file-actions button {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Mobile: fit the 4 buttons on one line evenly */
@media (max-width: 480px) {
    .file-actions {
        gap: clamp(4px, 1.6vw, 8px);
        flex-wrap: nowrap;
    }
    .file-actions a, 
    .file-actions button {
        flex: 1 1 auto;
        padding: 6px clamp(4px, 1.8vw, 10px);
        font-size: clamp(0.76rem, 3.4vw, 0.86rem);
    }
}

/* Open button (PDFs, docs, office) - consistent forest green */
.file-actions a.open-link,
.file-actions a[target="_blank"] {
    background-color: #2e7d32;
    color: #fff;
}
.file-actions a.open-link:hover,
.file-actions a[target="_blank"]:hover {
    background-color: #1b5e20;
}

/* Download / View Contents - primary cobalt blue */
.file-actions a[download],
.file-actions .open-zip-btn {
    background-color: #0069d9;
    color: #fff;
}
.file-actions a[download]:hover,
.file-actions .open-zip-btn:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Share - vibrant sky/cyan blue, distinct from Download's dark cobalt */
.file-actions a.share-link,
.file-actions a[onclick*="shareFile"] {
    background-color: #0284c7;
    color: #fff;
}
.file-actions a.share-link:hover,
.file-actions a[onclick*="shareFile"]:hover {
    background-color: #0369a1;
}

/* ─── Save for offline ─── */
.file-actions .btn-save-offline {
    background-color: #00695c;
    color: #fff;
    min-width: 6.4em;                   /* keeps its size when the label changes (Saved / 62% / Update) */
}
.file-actions .btn-save-offline[data-mode="save"]:hover:not(:disabled) {
    background-color: #004d40;
}
.file-actions .btn-save-offline:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.file-actions .btn-save-offline[data-mode="remove"] {
    background-color: #e8f5e9;
    color: #1b5e20;
}
.file-actions .btn-save-offline[data-mode="remove"]:hover {
    background-color: #c8e6c9;
}
.file-actions .btn-save-offline[data-mode="update"] {
    background-color: #b45309;
    color: #fff;
}
.file-actions .btn-save-offline[data-mode="update"]:hover:not(:disabled) {
    background-color: #92400e;
}
.file-actions a.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.file-actions .btn-remove-saved {
    background-color: #e2e8f0;
    color: #b91c1c;
}
.file-actions .btn-remove-saved:hover {
    background-color: #fecaca;
}

/* ─── My Saved Books ─── */
.saved-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 20px 0 0;
    padding: 12px 18px;
    border-radius: 14px;
    background-color: var(--bg-about);
    box-shadow: var(--shadow-card);
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}
.saved-link .saved-count {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 20px;
    background-color: var(--badge-bg);
    color: var(--badge-color);
}

.saved-folder {
    margin-top: 4px;
    font-size: 0.8rem;
    opacity: 0.75;
}
.saved-badge {
    margin-top: 6px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    width: fit-content;
}
.saved-badge.warn { background-color: #fee2e2; color: #991b1b; }
.saved-badge.info { background-color: #fef3c7; color: #92400e; }

.offline-banner .banner-link {
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
}


/* ─── Deep-link highlight (#/file/<id>) ─────────────────────────────────── */
.file-card.shared-highlight {
    position: relative;
    outline: 3px solid #2563eb !important;
    outline-offset: 3px;
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.35), 0 8px 25px rgba(37, 99, 235, 0.25) !important;
    animation: sharedPulse 1.8s ease-in-out infinite;
    z-index: 10;
}

.file-card.shared-highlight::before {
    content: "👉 Shared resource";
    position: absolute;
    top: -12px;
    right: 12px;
    background: #2563eb;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    z-index: 20;
    pointer-events: none;
}

@keyframes sharedPulse {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.25), 0 4px 15px rgba(37, 99, 235, 0.15);
        transform: scale(1.01);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(37, 99, 235, 0.5), 0 10px 30px rgba(37, 99, 235, 0.35);
        transform: scale(1.025);
    }
}

html.dark .file-card.shared-highlight {
    outline: 3px solid #60a5fa !important;
    box-shadow: 0 0 0 6px rgba(96, 165, 250, 0.4), 0 8px 25px rgba(96, 165, 250, 0.3) !important;
}

html.dark .file-card.shared-highlight::before {
    background: #3b82f6;
}

@media (prefers-reduced-motion: reduce) {
    .file-card.shared-highlight { animation: none; transform: none; }
}

/* ─── Level badges (shown in the All view) ─── */
.level-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    vertical-align: middle;
}
.level-badge.level-jce  { background: #e1f2e4; color: #14532d; }
.level-badge.level-msce { background: #e3ecfb; color: #0d3b8a; }
.level-badge.level-both { background: #efe3fa; color: #4a148c; }
html.dark .level-badge.level-jce  { background: #1c3d2a; color: #9fe0b4; }
html.dark .level-badge.level-msce { background: #1e3060; color: #9cc4ff; }
html.dark .level-badge.level-both { background: #3a2459; color: #d9b8ff; }

/* ─── Friendly empty state when a level has nothing here ─── */
.level-empty {
    grid-column: 1 / -1;
    margin-top: 12px;
    padding: 22px 16px;
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    text-align: center;
}
.level-empty-icon { font-size: 2.6rem; }
.level-empty b { display: block; margin: 6px 0; font-size: 1.15rem; }
.level-empty p { margin: 0 0 14px; color: var(--text-secondary); font-size: 0.9rem; }
.level-empty .level-empty-hint { margin: 12px 0 0; font-size: 0.8rem; opacity: 0.82; }
.level-empty-btn {
    height: 40px;
    padding: 0 20px;
    border: 0;
    border-radius: 10px;
    background: #0b63d6;
    color: #fff;
    font: 700 0.9rem sans-serif;
    cursor: pointer;
}
