/* ============================================================================
   Aurora Tree — in-chat Files explorer (src/ui/filesExplorer.js).
   A glassmorphism file tree that REPLACES the chat list inside #sidebar while
   open. Two stacked zones: SMART (virtual type buckets) and FOLDERS (real custom
   folders). role=tree semantics; keyboard-navigable; expand state persists.
   All visuals live here (the JS is class-driven) so the diff-coverage gate's
   JS-line burden stays on logic, not styling.
   ============================================================================ */

/* ---- panel shell ---------------------------------------------------------- */
#file-explorer-panel {
    display: none;                 /* JS flips to flex on open() */
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    /* a barely-there aurora wash so the explorer reads as its own surface,
       distinct from the chat list it replaces */
    background:
        radial-gradient(120% 60% at 0% 0%, rgba(34, 211, 238, 0.05), transparent 60%),
        radial-gradient(120% 60% at 100% 0%, rgba(192, 132, 252, 0.05), transparent 60%);
    border-radius: 12px;
    margin: -2px -2px 0;
    padding: 4px 2px 0;
}

/* ---- header --------------------------------------------------------------- */
.fe-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 8px;
}
.fe-back {
    background: none;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 7px;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}
.fe-back:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.fe-back:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.6); }
.fe-title {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.2px;
    background: linear-gradient(100deg, #e2e8f0, #a5b4fc 60%, #67e8f9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.fe-count {
    margin-left: auto;
    color: #7c8aa0;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

/* ---- sort control --------------------------------------------------------- */
.fe-sort {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 0 6px 8px;
    font-size: 0.72rem;
    color: #94a3b8;
}
.fe-sort-label { opacity: 0.8; }
.fe-sort-btn {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid transparent;
    color: #cbd5e1;
    font-size: 0.72rem;
    padding: 3px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.fe-sort-btn:hover { background: rgba(148, 163, 184, 0.16); }
.fe-sort-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.55); }
.fe-sort-btn.active {
    color: #fff;
    border-color: rgba(129, 140, 248, 0.5);
    background: linear-gradient(120deg, rgba(34, 211, 238, 0.22), rgba(129, 140, 248, 0.28));
}

/* ---- tree body ------------------------------------------------------------ */
.fe-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2px 2px 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
.fe-tree::-webkit-scrollbar { width: 8px; }
.fe-tree::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 8px;
}
.fe-tree::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ---- zones ---------------------------------------------------------------- */
.fe-zone { margin-bottom: 6px; }
.fe-zone-label {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 8px 4px;
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: #7c8aa0;
}
.fe-zone-label i { font-size: 0.7rem; color: #818cf8; opacity: 0.85; }
.fe-zone-rule {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(129, 140, 248, 0.25), transparent);
}

/* ---- a node (bucket / folder / domain group / file) ----------------------- */
.fe-node { position: relative; }
.fe-row {
    position: relative; /* containing block for .fe-focus::before — keep the accent bar row-height, not node-height */
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 9px;
    cursor: pointer;
    color: #e2e8f0;
    user-select: none;
    transition: background 0.13s, box-shadow 0.13s;
    /* indentation accrues purely from nested .fe-children margins (no inline vars) */
}
.fe-row:hover { background: rgba(255, 255, 255, 0.05); }
/* roving-tabindex focus → aurora ring + faint fill + accent bar */
.fe-row:focus-visible,
.fe-row.fe-focus {
    outline: none;
    background: linear-gradient(100deg, rgba(34, 211, 238, 0.1), rgba(129, 140, 248, 0.12));
    box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.5);
}
.fe-row.fe-focus::before {
    content: '';
    position: absolute;
    left: 1px;
    top: 6px;
    bottom: 6px;
    width: 2.5px;
    border-radius: 3px;
    background: linear-gradient(180deg, #67e8f9, #818cf8 55%, #c084fc);
}

/* group icon (bucket/folder) vs leaf icon */
.fe-ico {
    width: 26px; /* match the leaf thumb/tile slot so group + leaf labels share a left edge */
    flex-shrink: 0;
    text-align: center;
    color: #818cf8;
}
.fe-row[data-kind="file"] .fe-ico { color: #94a3b8; }

.fe-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
}
.fe-row[data-kind="group"] .fe-label { font-weight: 600; }
.fe-cardinality {
    color: #7c8aa0;
    font-weight: 400;
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
}
.fe-chevron {
    margin-left: auto;
    font-size: 0.66rem;
    color: #7c8aa0;
    transition: transform 0.16s ease;
}
.fe-row[aria-expanded="false"] .fe-chevron { transform: rotate(-90deg); }

/* leaf thumbnail (real image src only; dominant-color falls back to a tinted icon) */
.fe-thumb {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: rgba(148, 163, 184, 0.15);
}
.fe-ico-tile {
    width: 26px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    border-radius: 6px;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.8rem;
}

/* children container + VS-Code-style guide line; nesting accrues the indent */
.fe-children {
    position: relative;
    margin-left: 14px;
    border-left: 1px solid rgba(148, 163, 184, 0.13);
    padding-left: 3px;
}
.fe-children[hidden] { display: none; }

/* empty-state hint (e.g. Folders zone before any folder exists) */
.fe-empty {
    color: #7c8aa0;
    font-size: 0.78rem;
    padding: 6px 8px 8px 14px;
    font-style: italic;
}

/* full-body message (no files / load error / locked) */
.fe-message {
    color: #94a3b8;
    text-align: center;
    padding: 34px 10px;
    font-size: 0.9rem;
}

/* ---- folder-zone actions + glass modal ----------------------------------- */
.fe-zone-action {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 6px;
    margin-left: 6px;
    transition: background 0.13s, color 0.13s;
}
.fe-zone-action:hover { background: rgba(129, 140, 248, 0.18); color: #fff; }
.fe-zone-action:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.55); }

/* per-folder row actions (rename / delete / new-subfolder), revealed on hover/focus */
.fe-row-actions { display: none; align-items: center; gap: 2px; margin-left: 4px; }
.fe-row:hover .fe-row-actions,
.fe-row.fe-focus .fe-row-actions { display: flex; }
.fe-row:hover .fe-cardinality,
.fe-row.fe-focus .fe-cardinality { display: none; }
.fe-row-action {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.72rem;
    padding: 2px 5px;
    border-radius: 5px;
    transition: background 0.12s, color 0.12s;
}
.fe-row-action:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.fe-row-action.fe-danger:hover { background: rgba(248, 113, 113, 0.22); color: #fecaca; }

.fe-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: feFade 0.15s ease-out;
}
@keyframes feFade { from { opacity: 0; } to { opacity: 1; } }
.fe-modal-panel {
    width: min(420px, calc(100vw - 48px));
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.96));
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    padding: 20px;
}
.fe-modal-title { font-weight: 700; font-size: 1rem; color: #e2e8f0; margin-bottom: 12px; }
.fe-modal-message { color: #cbd5e1; font-size: 0.9rem; line-height: 1.5; margin-bottom: 4px; }
.fe-modal-input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 9px;
    color: #f1f5f9;
    font-size: 0.92rem;
    padding: 9px 11px;
    outline: none;
}
.fe-modal-input:focus { border-color: rgba(129, 140, 248, 0.7); box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25); }
.fe-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.fe-modal-btn {
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(148, 163, 184, 0.08);
    color: #cbd5e1;
    border-radius: 9px;
    padding: 7px 16px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.13s, border-color 0.13s, color 0.13s;
}
.fe-modal-btn:hover { background: rgba(148, 163, 184, 0.16); }
.fe-modal-ok {
    border-color: rgba(129, 140, 248, 0.5);
    background: linear-gradient(120deg, rgba(34, 211, 238, 0.25), rgba(129, 140, 248, 0.3));
    color: #fff;
}
.fe-modal-ok:hover { filter: brightness(1.12); }
.fe-modal-ok.fe-danger { border-color: rgba(248, 113, 113, 0.5); background: linear-gradient(120deg, rgba(248, 113, 113, 0.3), rgba(239, 68, 68, 0.35)); }

/* drag-&-drop target highlight (file/folder → folder, or → Folders zone = root) */
.fe-row.fe-drop,
.fe-zone.fe-drop {
    box-shadow: inset 0 0 0 2px rgba(34, 211, 238, 0.6);
    border-radius: 9px;
    background: rgba(34, 211, 238, 0.08);
}

/* ---- mobile --------------------------------------------------------------- */
@media (max-width: 600px) {
    .fe-row { padding-top: 8px; padding-bottom: 8px; }
    .fe-title { font-size: 1rem; }
}

/* ---- live filter (VS-Code style) ------------------------------------------ */
.fe-filter-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 6px 6px;
    padding: 4px 8px;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.07);
    border: 1px solid rgba(148, 163, 184, 0.14);
}
.fe-filter-row:focus-within { border-color: rgba(129, 140, 248, 0.45); }
.fe-filter-ico { font-size: 0.7rem; color: #7c8aa0; }
.fe-filter {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: #e2e8f0;
    font-size: 0.78rem;
    padding: 2px 0;
}
.fe-filter::placeholder { color: #64748b; }
.fe-filter-clear {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 6px;
}
.fe-filter-clear:hover { color: #e2e8f0; background: rgba(148, 163, 184, 0.12); }

/* ---- category tiles (Samsung "My Files" style: round colored icon + label) --- */
.fe-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 12px 2px;
    padding: 4px 4px 12px;
}
.fe-chip {
    flex: 0 0 auto;
    width: 62px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    padding: 2px 0;
    color: #cbd5e1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.fe-chip-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.14);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.fe-chip-icon i { font-size: 1.18rem; }
.fe-chip:hover .fe-chip-icon { transform: translateY(-2px); filter: brightness(1.18); }
.fe-chip:active .fe-chip-icon { transform: scale(0.93); }
.fe-chip-label {
    font-size: 0.7rem;
    line-height: 1.12;
    text-align: center;
    max-width: 62px;
    max-height: 2.3em;
    overflow: hidden;
    word-break: break-word;
    color: #cbd5e1;
}
.fe-chip-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    box-sizing: border-box;
    border-radius: 999px;
    background: #0b1220;
    border: 1px solid rgba(148, 163, 184, 0.4);
    color: #e2e8f0;
    font-size: 0.6rem;
    line-height: 14px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.fe-chip.active .fe-chip-icon {
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.95), 0 0 14px rgba(129, 140, 248, 0.45);
}
.fe-chip.active .fe-chip-label { color: #e0e7ff; font-weight: 600; }

/* per-bucket pastel colors (dark-theme-tinted, echoing Samsung's My Files palette) */
.fe-chip[data-bucket="Images"]    .fe-chip-icon { background: rgba(244, 114, 182, 0.16); color: #f9a8d4; }
.fe-chip[data-bucket="Audios"]    .fe-chip-icon { background: rgba(129, 140, 248, 0.16); color: #a5b4fc; }
.fe-chip[data-bucket="Videos"]    .fe-chip-icon { background: rgba(168, 85, 247, 0.16);  color: #c4b5fd; }
.fe-chip[data-bucket="Documents"] .fe-chip-icon { background: rgba(251, 146, 60, 0.16);  color: #fdba74; }
.fe-chip[data-bucket="Generated"] .fe-chip-icon { background: rgba(52, 211, 153, 0.16);  color: #6ee7b7; }
.fe-chip[data-bucket="Links"]     .fe-chip-icon { background: rgba(56, 189, 248, 0.16);  color: #7dd3fc; }
.fe-chip[data-bucket="Other"]     .fe-chip-icon { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }

/* ---- category grid --------------------------------------------------------- */
.fe-gridwrap { padding: 2px 6px 12px; }
.fe-grid-back {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.74rem;
    cursor: pointer;
    padding: 4px 4px 8px;
}
.fe-grid-back:hover { color: #e2e8f0; }
.fe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 8px;
}
.fe-tile {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 12px;
    padding: 6px;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.fe-tile:hover { background: rgba(148, 163, 184, 0.13); border-color: rgba(129, 140, 248, 0.4); transform: translateY(-1px); }
.fe-tile:focus-visible { outline: 2px solid rgba(129, 140, 248, 0.7); outline-offset: 1px; }
.fe-tile-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.5);
}
.fe-tile-ico {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(51, 65, 85, 0.55);
    color: #cbd5e1;
    font-size: 1.3rem;
}
.fe-tile-name {
    font-size: 0.66rem;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fe-tile-meta { font-size: 0.62rem; color: #7c8aa0; font-variant-numeric: tabular-nums; min-height: 0.8em; }

/* ---- leaf size badge ------------------------------------------------------- */
.fe-leaf-meta {
    margin-left: auto;
    padding-left: 6px;
    font-size: 0.64rem;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Favicon previews for link rows/tiles: favicons are small square glyphs —
   contain them instead of cover-cropping, on a subtle plate. */
.fe-thumb-favicon,
.fe-tile-favicon {
    object-fit: contain;
    padding: 4px;
    background: rgba(255, 255, 255, 0.06);
}

/* Micro text preview inside a grid tile: white "paper" with the file's first
   lines in micro-print (Windows-Explorer-style). */
.fe-tile-textwrap { padding: 0; overflow: hidden; }
.fe-tile-textprev {
    width: 100%;
    height: 100%;
    background: #f4f4f5;
    color: #27272a;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 4.5px;
    line-height: 1.35;
    padding: 5px 6px;
    white-space: pre-wrap;
    word-break: break-all;
    overflow: hidden;
    text-align: left;
    border-radius: inherit;
    pointer-events: none;
}

/* Video tile: thumb + centered play badge (also for YouTube links). */
.fe-tile-vidwrap { position: relative; width: 100%; display: flex; }
.fe-tile-vidwrap .fe-tile-thumb { width: 100%; }
.fe-tile-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.fe-tile-play i {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 11px;
    padding-left: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Favicon on a Links domain header row */
.fe-ico-favicon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: contain;
}
