/**
 * librarian.css — KAAI Librarian Panel Styles
 * Designed by: Johnny Black | KAAI v1.0
 *
 * Dark-theme file-tree panel with split layout:
 *   Left  → recursive tree with expand/collapse, search highlight, new-file glow
 *   Right → detail pane with breadcrumb, stats, drill-in
 */

/* ── Root container ─────────────────────────────────────────────────────────── */
.lib-panel {
    display:        flex;
    flex-direction: column;
    height:         calc(100vh - 120px);
    min-height:     400px;
    background:     var(--bg-primary, #0d0d0d);
    color:          var(--text-primary, #eee);
    font-family:    'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size:      0.85rem;
    overflow:       hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.lib-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         0.6rem 1rem;
    background:      var(--bg-card, #1a1a1a);
    border-bottom:   1px solid var(--border-color, #2a2a2a);
    flex-shrink:     0;
    gap:             0.75rem;
}

.lib-header-left,
.lib-header-right {
    display:     flex;
    align-items: center;
    gap:         0.6rem;
}

.lib-title {
    font-size:   1rem;
    font-weight: 600;
    color:       var(--text-primary, #eee);
    white-space: nowrap;
}

/* Live badge */
.lib-live-badge {
    display:        inline-flex;
    align-items:    center;
    gap:            0.35rem;
    padding:        0.15rem 0.55rem;
    background:     rgba(16, 185, 129, 0.12);
    border:         1px solid rgba(16, 185, 129, 0.35);
    border-radius:  9999px;
    font-size:      0.7rem;
    font-weight:    600;
    color:          #10b981;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition:     background 0.3s;
}

.lib-live-dot {
    width:         7px;
    height:        7px;
    background:    #10b981;
    border-radius: 50%;
    animation:     lib-pulse-dot 2s ease-in-out infinite;
}

@keyframes lib-pulse-dot {
    0%, 100% { opacity: 1;   transform: scale(1);   }
    50%       { opacity: 0.4; transform: scale(0.7); }
}

.lib-live-pulse { background: rgba(16, 185, 129, 0.25) !important; }

.lib-updated {
    font-size:   0.72rem;
    color:       var(--text-muted, #555);
    white-space: nowrap;
}

/* ── Stats bar ──────────────────────────────────────────────────────────────── */
.lib-stats-bar {
    display:       flex;
    align-items:   center;
    flex-wrap:     wrap;
    gap:           0.5rem;
    padding:       0.5rem 1rem;
    background:    var(--bg-secondary, #141414);
    border-bottom: 1px solid var(--border-color, #2a2a2a);
    flex-shrink:   0;
    min-height:    36px;
}

.lib-stat {
    display:     inline-flex;
    align-items: center;
    gap:         0.3rem;
    font-size:   0.78rem;
    color:       var(--text-muted, #555);
    white-space: nowrap;
}

.lib-stat-icon { font-size: 0.9rem; }

.lib-stat b,
.lib-stat span[id] {
    color:       var(--text-primary, #eee);
    font-weight: 600;
}

.lib-ext-bar {
    display:     flex;
    align-items: center;
    flex-wrap:   wrap;
    gap:         0.3rem;
    margin-left: auto;
}

.lib-ext-pill {
    display:       inline-flex;
    align-items:   center;
    gap:           0.25rem;
    padding:       0.1rem 0.5rem;
    border-radius: 9999px;
    font-size:     0.7rem;
    font-weight:   500;
    white-space:   nowrap;
    cursor:        default;
}

.lib-ext-pill b { font-weight: 700; }

/* ── Controls row ───────────────────────────────────────────────────────────── */
.lib-controls {
    display:       flex;
    align-items:   center;
    flex-wrap:     wrap;
    gap:           0.5rem;
    padding:       0.5rem 1rem;
    background:    var(--bg-card, #1a1a1a);
    border-bottom: 1px solid var(--border-color, #2a2a2a);
    flex-shrink:   0;
}

.lib-search-wrap {
    display:       flex;
    align-items:   center;
    flex:          1 1 200px;
    max-width:     340px;
    background:    var(--bg-secondary, #141414);
    border:        1px solid var(--border-color, #2a2a2a);
    border-radius: var(--radius, 0.5rem);
    padding:       0 0.5rem;
    gap:           0.35rem;
    transition:    border-color 0.2s, box-shadow 0.2s;
}

.lib-search-wrap:focus-within {
    border-color: var(--accent, #7c6fcd);
    box-shadow:   0 0 0 2px rgba(124, 111, 205, 0.15);
}

.lib-search-icon {
    font-size:   0.9rem;
    flex-shrink: 0;
    color:       var(--text-muted, #555);
}

.lib-search {
    flex:       1;
    background: transparent;
    border:     none;
    outline:    none;
    color:      var(--text-primary, #eee);
    font-size:  0.82rem;
    padding:    0.35rem 0;
    min-width:  0;
}

.lib-search::placeholder { color: var(--text-muted, #555); }

.lib-search-clear {
    background:  transparent;
    border:      none;
    cursor:      pointer;
    color:       var(--text-muted, #555);
    font-size:   0.85rem;
    padding:     0 0.15rem;
    line-height: 1;
    flex-shrink: 0;
    transition:  color 0.2s;
}

.lib-search-clear:hover { color: var(--text-primary, #eee); }

.lib-depth-wrap {
    display:     flex;
    align-items: center;
    gap:         0.35rem;
    white-space: nowrap;
}

.lib-depth-label {
    font-size: 0.78rem;
    color:     var(--text-muted, #555);
}

.lib-depth-select {
    background:    var(--bg-secondary, #141414);
    border:        1px solid var(--border-color, #2a2a2a);
    border-radius: var(--radius-sm, 0.25rem);
    color:         var(--text-primary, #eee);
    font-size:     0.8rem;
    padding:       0.2rem 0.4rem;
    cursor:        pointer;
    outline:       none;
    transition:    border-color 0.2s;
}

.lib-depth-select:focus { border-color: var(--accent, #7c6fcd); }

/* Generic button */
.lib-btn {
    display:       inline-flex;
    align-items:   center;
    gap:           0.3rem;
    padding:       0.3rem 0.7rem;
    background:    var(--bg-secondary, #141414);
    border:        1px solid var(--border-color, #2a2a2a);
    border-radius: var(--radius-sm, 0.25rem);
    color:         var(--text-primary, #eee);
    font-size:     0.78rem;
    font-weight:   500;
    cursor:        pointer;
    white-space:   nowrap;
    transition:    background 0.15s, border-color 0.15s, color 0.15s;
}

.lib-btn:hover {
    background:   var(--bg-hover, #222);
    border-color: var(--accent, #7c6fcd);
    color:        var(--accent, #7c6fcd);
}

.lib-btn:active { transform: translateY(1px); }

/* ── Split body ─────────────────────────────────────────────────────────────── */
.lib-body {
    display:    flex;
    flex:       1 1 0;
    overflow:   hidden;
    min-height: 0;
}

/* ── Tree pane (left) ───────────────────────────────────────────────────────── */
.lib-tree-pane {
    flex:            1 1 0;
    min-width:       0;
    overflow-y:      auto;
    overflow-x:      hidden;
    padding:         0.5rem 0;
    border-right:    1px solid var(--border-color, #2a2a2a);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color, #2a2a2a) transparent;
}

.lib-tree-pane::-webkit-scrollbar       { width: 5px; }
.lib-tree-pane::-webkit-scrollbar-track { background: transparent; }
.lib-tree-pane::-webkit-scrollbar-thumb {
    background:    var(--border-color, #2a2a2a);
    border-radius: 3px;
}

/* ── Loading / error ────────────────────────────────────────────────────────── */
.lib-loading {
    display:         flex;
    align-items:     center;
    justify-content: center;
    gap:             0.5rem;
    padding:         2rem;
    color:           var(--text-muted, #555);
    font-size:       0.85rem;
}

.lib-spin {
    display:   inline-block;
    animation: lib-spin 1s linear infinite;
    font-size: 1.1rem;
}

@keyframes lib-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.lib-error {
    padding:       1rem 1.2rem;
    margin:        0.5rem 0.75rem;
    background:    rgba(239, 68, 68, 0.1);
    border:        1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius, 0.5rem);
    color:         #ef4444;
    font-size:     0.82rem;
}

/* ── Tree list ──────────────────────────────────────────────────────────────── */
.lib-tree-root,
.lib-subtree {
    list-style: none;
    margin:     0;
    padding:    0;
}

/* Root dir row is invisible — only its children are shown */
.lib-dir-root > .lib-toggle,
.lib-dir-root > .lib-icon,
.lib-dir-root > .lib-name,
.lib-dir-root > .lib-dir-meta {
    display: none;
}

.lib-dir-root {
    padding-left: 0;
    cursor:       default;
}

/* Progressive indentation for nested levels */
.lib-subtree > .lib-node                                             { padding-left: 1.25rem; }
.lib-subtree .lib-subtree > .lib-node                               { padding-left: 2.5rem; }
.lib-subtree .lib-subtree .lib-subtree > .lib-node                  { padding-left: 3.75rem; }
.lib-subtree .lib-subtree .lib-subtree .lib-subtree > .lib-node     { padding-left: 5rem; }

/* Node row */
.lib-node {
    display:       flex;
    align-items:   center;
    gap:           0.3rem;
    padding:       0.22rem 0.75rem;
    cursor:        pointer;
    position:      relative;
    transition:    background 0.1s;
    user-select:   none;
    white-space:   nowrap;
    overflow:      hidden;
}

.lib-node:hover           { background: var(--bg-hover, #222); }
.lib-node-selected        { background: var(--accent-muted, #2e2b4a) !important; }

.lib-node-selected::before {
    content:       '';
    position:      absolute;
    left:          0; top: 0; bottom: 0;
    width:         3px;
    background:    var(--accent, #7c6fcd);
    border-radius: 0 2px 2px 0;
}

/* Recently-modified pulse */
.lib-node-new { animation: lib-new-glow 3s ease-in-out 1; }

@keyframes lib-new-glow {
    0%   { box-shadow: none; }
    20%  { box-shadow: inset 0 0 0 1px rgba(251,191,36,.4), 0 0 8px rgba(251,191,36,.2); }
    80%  { box-shadow: inset 0 0 0 1px rgba(251,191,36,.15); }
    100% { box-shadow: none; }
}

/* Toggle arrow */
.lib-toggle {
    display:     inline-flex;
    align-items: center;
    width:       0.85rem;
    flex-shrink: 0;
    font-size:   0.62rem;
    color:       var(--text-muted, #555);
    transition:  color 0.15s;
}

.lib-node:hover .lib-toggle { color: var(--text-primary, #eee); }

/* Icon */
.lib-icon {
    flex-shrink: 0;
    font-size:   0.95rem;
    line-height: 1;
    width:       1.2rem;
    text-align:  center;
}

/* Name */
.lib-name {
    flex:          1 1 0;
    min-width:     0;
    overflow:      hidden;
    text-overflow: ellipsis;
    font-size:     0.82rem;
    font-weight:   400;
    color:         var(--text-primary, #eee);
}

.lib-dir-name { font-weight: 500; }

/* Size badge */
.lib-size-badge {
    flex-shrink:   0;
    font-size:     0.7rem;
    color:         var(--text-muted, #555);
    background:    var(--bg-tertiary, #111);
    border:        1px solid var(--border-subtle, #1e1e1e);
    border-radius: 9999px;
    padding:       0.05rem 0.4rem;
    margin-left:   auto;
}

/* Age */
.lib-age {
    flex-shrink: 0;
    font-size:   0.68rem;
    color:       var(--text-muted, #555);
    min-width:   3.5rem;
    text-align:  right;
}

/* Dir meta */
.lib-dir-meta {
    flex-shrink: 0;
    font-size:   0.7rem;
    color:       var(--text-muted, #555);
    margin-left: auto;
    white-space: nowrap;
}

/* Truncation indicator */
.lib-truncated {
    flex-shrink: 0;
    font-size:   0.75rem;
    color:       var(--text-muted, #555);
    cursor:      help;
}

/* Search match highlight */
mark.lib-match {
    background:    rgba(251, 191, 36, 0.3);
    color:         #fbbf24;
    border-radius: 2px;
    padding:       0 1px;
}

/* ── Detail pane (right) ────────────────────────────────────────────────────── */
.lib-detail-pane {
    width:           280px;
    min-width:       220px;
    max-width:       340px;
    flex-shrink:     0;
    overflow-y:      auto;
    padding:         1rem;
    background:      var(--bg-card, #1a1a1a);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color, #2a2a2a) transparent;
}

.lib-detail-pane::-webkit-scrollbar       { width: 4px; }
.lib-detail-pane::-webkit-scrollbar-track { background: transparent; }
.lib-detail-pane::-webkit-scrollbar-thumb {
    background:    var(--border-color, #2a2a2a);
    border-radius: 3px;
}

/* Empty state */
.lib-detail-empty {
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             0.75rem;
    height:          100%;
    min-height:      180px;
    text-align:      center;
    color:           var(--text-muted, #555);
    font-size:       0.82rem;
    line-height:     1.5;
}

.lib-detail-empty-icon {
    font-size: 2.5rem;
    opacity:   0.35;
}

/* Detail card */
.lib-detail-card {
    display:        flex;
    flex-direction: column;
    gap:            0.5rem;
}

.lib-detail-icon {
    font-size:     2.5rem;
    line-height:   1;
    text-align:    center;
    margin-bottom: 0.25rem;
}

.lib-detail-name {
    font-size:   0.95rem;
    font-weight: 600;
    word-break:  break-all;
    text-align:  center;
    line-height: 1.3;
}

/* Breadcrumb */
.lib-detail-breadcrumb {
    display:         flex;
    flex-wrap:       wrap;
    align-items:     center;
    justify-content: center;
    gap:             0.15rem;
    font-size:       0.72rem;
    color:           var(--text-muted, #555);
    margin-bottom:   0.25rem;
}

.lib-bc-current {
    color:       var(--text-primary, #eee);
    font-weight: 500;
}

.lib-bc-sep { color: var(--text-muted, #555); }

/* Type badge */
.lib-detail-type-badge {
    display:       inline-block;
    align-self:    center;
    padding:       0.15rem 0.6rem;
    border-radius: 9999px;
    font-size:     0.72rem;
    font-weight:   600;
    text-align:    center;
}

/* Divider */
.lib-detail-divider {
    height:     1px;
    background: var(--border-subtle, #1e1e1e);
    margin:     0.25rem 0;
}

/* Key-value rows */
.lib-detail-row {
    display:         flex;
    justify-content: space-between;
    align-items:     baseline;
    gap:             0.5rem;
    font-size:       0.78rem;
    padding:         0.22rem 0;
    border-bottom:   1px solid var(--border-subtle, #1e1e1e);
}

.lib-detail-row:last-of-type { border-bottom: none; }

.lib-detail-row > span:first-child {
    color:       var(--text-muted, #555);
    flex-shrink: 0;
}

.lib-detail-row > span:last-child {
    color:      var(--text-primary, #eee);
    text-align: right;
    word-break: break-all;
}

/* Full path */
.lib-detail-path {
    display:        flex;
    flex-direction: column;
    gap:            0.3rem;
    margin-top:     0.25rem;
}

.lib-detail-path-label {
    font-size:      0.72rem;
    color:          var(--text-muted, #555);
    font-weight:    500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lib-detail-path-value {
    font-family:       'Consolas', 'Fira Code', monospace;
    font-size:         0.72rem;
    color:             var(--text-primary, #eee);
    background:        var(--bg-tertiary, #111);
    border:            1px solid var(--border-subtle, #1e1e1e);
    border-radius:     var(--radius-sm, 0.25rem);
    padding:           0.35rem 0.5rem;
    word-break:        break-all;
    line-height:       1.4;
    overflow:          hidden;
    display:           -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* Drill-in button */
.lib-detail-drill {
    width:           100%;
    justify-content: center;
    margin-top:      0.5rem;
    padding:         0.45rem 0.75rem;
    font-size:       0.8rem;
    background:      var(--accent-muted, #2e2b4a);
    border-color:    var(--accent, #7c6fcd);
    color:           var(--accent, #7c6fcd);
}

.lib-detail-drill:hover {
    background: var(--accent, #7c6fcd);
    color:      #fff;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .lib-detail-pane { display: none; }
}

