/* ============================================================
   Research Library — bookmarks / notes / history
   A quiet, ledger-like reading room for saved research.
   Palette + radii follow the Browse shell (zinc + violet).
   Every row carries its practice-area accent as a left spine
   (--row-accent), matching the domain colors in domain-home.css.
   ============================================================ */

.lib-shell {
    --lib-ink: #18181b;
    --lib-slate: #52525b;
    --lib-faint: #a1a1aa;
    --lib-line: #e4e4e7;
    --lib-paper: #ffffff;
    --lib-wash: #fafafa;
    --lib-accent: #5b21b6;
    --lib-accent-hover: #4c1d95;
    --lib-accent-soft: #f5f3ff;
    --lib-danger: #b91c1c;

    max-width: 1080px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 4.5rem;
    color: var(--lib-ink);
}

/* ---------- header ---------- */

.lib-head {
    margin-bottom: 1.25rem;
}

.lib-eyebrow {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--lib-accent);
    margin: 0 0 0.375rem;
}

.lib-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--lib-ink);
    margin: 0 0 0.375rem;
}

.lib-summary {
    font-size: 0.95rem;
    color: var(--lib-slate);
    margin: 0;
}

/* ---------- section tabs ---------- */

.lib-tabs {
    display: flex;
    gap: 0.25rem;
    margin-top: 1.5rem;
    border-bottom: 1px solid var(--lib-line);
}

.lib-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--lib-slate);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s;
}

.lib-tab i {
    font-size: 0.95em;
}

.lib-tab:hover {
    color: var(--lib-ink);
    text-decoration: none;
}

.lib-tab.active {
    color: var(--lib-accent);
    border-bottom-color: var(--lib-accent);
}

.lib-tab:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: -2px;
    border-radius: 0.375rem;
}

/* ---------- toolbar: search + filter pills ---------- */

.lib-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0 0.875rem;
}

.lib-search {
    position: relative;
    flex: 1 1 260px;
    max-width: 420px;
}

.lib-search i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--lib-faint);
    font-size: 0.9rem;
    pointer-events: none;
}

.lib-search input {
    width: 100%;
    height: 42px;
    padding: 0 1rem 0 2.5rem;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--lib-ink);
    background: var(--lib-paper);
    border: 1px solid var(--lib-line);
    border-radius: 0.625rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.lib-search input::placeholder {
    color: var(--lib-faint);
}

.lib-search input:focus {
    outline: none;
    border-color: var(--lib-accent);
    box-shadow: 0 0 0 3px rgba(91, 33, 182, 0.12);
}

.lib-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.lib-pill {
    --pill-accent: var(--lib-slate);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.375rem 0.875rem;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--lib-slate);
    background: var(--lib-paper);
    border: 1px solid var(--lib-line);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.lib-pill .lib-pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pill-accent);
    flex-shrink: 0;
}

.lib-pill .lib-pill-count {
    color: var(--lib-faint);
    font-weight: 500;
}

.lib-pill:hover {
    border-color: var(--pill-accent);
    color: var(--lib-ink);
}

.lib-pill.active {
    color: var(--pill-accent);
    border-color: var(--pill-accent);
    background: color-mix(in srgb, var(--pill-accent) 7%, #ffffff);
}

.lib-pill.active .lib-pill-count {
    color: var(--pill-accent);
    opacity: 0.75;
}

.lib-pill:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
}

/* ---------- stat strip (history) ---------- */

.lib-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin-top: 0.625rem;
    font-size: 0.85rem;
    color: var(--lib-slate);
}

.lib-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 0.375rem;
}

.lib-stat strong {
    font-size: 1rem;
    font-weight: 700;
    color: var(--lib-ink);
    font-variant-numeric: tabular-nums;
}

/* ---------- the ledger ---------- */

.lib-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--lib-paper);
    border: 1px solid var(--lib-line);
    border-radius: 0.75rem;
    overflow: hidden;
}

.lib-row {
    --row-accent: var(--lib-slate);
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.875rem 1.125rem 0.875rem 1.375rem;
    border-bottom: 1px solid var(--lib-line);
    transition: background 0.15s;
}

.lib-row:last-child {
    border-bottom: none;
}

/* the practice-area spine */
.lib-row::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--row-accent);
    opacity: 0.85;
}

.lib-row:hover,
.lib-row:focus-within {
    background: var(--lib-wash);
}

.lib-row-main {
    flex: 1;
    min-width: 0;
}

.lib-row-title {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 0;
    margin: 0 0 0.25rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--lib-ink);
    cursor: pointer;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.lib-row-title:hover {
    color: var(--lib-accent);
}

.lib-row-title:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

.lib-row-desc {
    font-size: 0.85rem;
    color: var(--lib-slate);
    margin: 0 0 0.3rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.lib-row-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--lib-faint);
    margin: 0;
}

.lib-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    color: var(--row-accent);
}

.lib-chip .lib-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--row-accent);
}

.lib-sep {
    color: var(--lib-line);
}

/* note body inside a row */
.lib-note-text {
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--lib-slate);
    background: var(--lib-wash);
    border: 1px solid var(--lib-line);
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    margin: 0.375rem 0 0.45rem;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.lib-row.expanded .lib-note-text {
    display: block;
    -webkit-line-clamp: unset;
}

.lib-note-toggle {
    background: none;
    border: 0;
    padding: 0;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--lib-accent);
    cursor: pointer;
}

.lib-note-toggle:hover {
    color: var(--lib-accent-hover);
    text-decoration: underline;
}

.lib-note-toggle:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* ---------- row actions ---------- */

.lib-row-acts {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
    padding-top: 0.125rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.lib-row:hover .lib-row-acts,
.lib-row:focus-within .lib-row-acts {
    opacity: 1;
}

@media (hover: none) {
    .lib-row-acts {
        opacity: 1;
    }
}

.lib-act {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 32px;
    min-width: 32px;
    padding: 0 0.5rem;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--lib-slate);
    background: var(--lib-paper);
    border: 1px solid var(--lib-line);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.lib-act:hover {
    background: var(--lib-wash);
    color: var(--lib-ink);
    border-color: #d4d4d8;
}

.lib-act--open {
    color: var(--lib-accent);
    border-color: color-mix(in srgb, var(--lib-accent) 35%, #ffffff);
    background: var(--lib-accent-soft);
    padding: 0 0.75rem;
}

.lib-act--open:hover {
    background: #ede9fe;
    color: var(--lib-accent-hover);
    border-color: var(--lib-accent);
}

.lib-act--danger:hover {
    color: var(--lib-danger);
    border-color: #fca5a5;
    background: #fef2f2;
}

.lib-act:focus-visible {
    outline: 2px solid var(--lib-accent);
    outline-offset: 2px;
}

/* ---------- history: day groups ---------- */

.lib-day {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin: 1.75rem 0 0.625rem;
}

.lib-day:first-of-type {
    margin-top: 0.25rem;
}

.lib-day-label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--lib-slate);
    white-space: nowrap;
}

.lib-day-count {
    font-size: 0.78rem;
    color: var(--lib-faint);
    white-space: nowrap;
}

.lib-day-rule {
    flex: 1;
    height: 1px;
    background: var(--lib-line);
}

.lib-time {
    flex-shrink: 0;
    width: 52px;
    padding-top: 0.2rem;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    color: var(--lib-faint);
}

.lib-type {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.1rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--lib-slate);
    background: var(--lib-wash);
    border: 1px solid var(--lib-line);
    border-radius: 999px;
}

/* ---------- states: skeleton / empty / error ---------- */

.lib-skel {
    background: var(--lib-paper);
    border: 1px solid var(--lib-line);
    border-radius: 0.75rem;
    overflow: hidden;
}

.lib-skel-row {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--lib-line);
}

.lib-skel-row:last-child {
    border-bottom: none;
}

.lib-skel-bar {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f4f4f5 25%, #e4e4e7 50%, #f4f4f5 75%);
    background-size: 200% 100%;
    animation: lib-shimmer 1.4s ease infinite;
    margin-bottom: 0.625rem;
}

.lib-skel-bar:last-child {
    margin-bottom: 0;
    width: 45%;
}

@keyframes lib-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .lib-skel-bar {
        animation: none;
    }

    .lib-row,
    .lib-row-acts,
    .lib-tab,
    .lib-pill,
    .lib-act {
        transition: none;
    }
}

.lib-empty {
    text-align: center;
    padding: 4rem 1.5rem;
    background: var(--lib-paper);
    border: 1px dashed var(--lib-line);
    border-radius: 0.75rem;
}

.lib-empty i {
    font-size: 2rem;
    color: var(--lib-faint);
}

.lib-empty h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--lib-ink);
    margin: 0.875rem 0 0.375rem;
}

.lib-empty p {
    font-size: 0.9rem;
    color: var(--lib-slate);
    max-width: 42ch;
    margin: 0 auto 1.25rem;
}

.lib-cta {
    display: inline-block;
    padding: 0.55rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #ffffff;
    background: var(--lib-accent);
    border: 0;
    border-radius: 0.5rem;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.lib-cta:hover {
    background: var(--lib-accent-hover);
    color: #ffffff;
    text-decoration: none;
}

.lib-cta--ghost {
    color: var(--lib-accent);
    background: transparent;
    border: 1px solid var(--lib-line);
}

.lib-cta--ghost:hover {
    color: var(--lib-accent-hover);
    background: var(--lib-accent-soft);
}

.lib-error {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1.125rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #7f1d1d;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.625rem;
}

/* ---------- load more ---------- */

.lib-more {
    display: flex;
    justify-content: center;
    margin-top: 1.25rem;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
    .lib-shell {
        padding: 1.75rem 1rem 3.5rem;
    }

    .lib-title {
        font-size: 1.45rem;
    }

    .lib-tabs {
        overflow-x: auto;
        scrollbar-width: none;
    }

    .lib-tabs::-webkit-scrollbar {
        display: none;
    }

    .lib-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .lib-row-acts {
        opacity: 1;
        padding-top: 0;
    }

    .lib-time {
        width: auto;
    }

    .lib-search {
        max-width: none;
    }
}
