/* ============================================================================
   STORY LIBRARY (phase 1). The save panel on Success Stories and the library
   page. Its own sheet, like success-stories.css; colors come from the tool
   tokens (data-tool="stories"), nothing here hard-codes a tool color.
   ============================================================================ */

/* Success Stories: the way in, and the save panel under the versions. */
.story-library-entry {
    margin: 0.75rem 0 0;
}
.story-library-entry .btn {
    min-height: 44px;
}

.story-save {
    border: 1px solid var(--border);
    border-left: 4px solid var(--tool);
    border-radius: var(--radius-md);
    background: var(--white);
    padding: 1rem 1.25rem;
    margin: 1.5rem 0;
}
.story-save h3 {
    margin: 0 0 0.5rem;
    color: var(--primary);
}
.story-save-uses {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin: 0 0 1rem;
}
.story-save-uses legend {
    font-weight: 600;
    color: var(--primary);
    padding: 0 0.35rem;
}
.story-save-use-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem 1rem;
}
.story-save-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    cursor: pointer;
}
.story-save-check input {
    width: 1.15rem;
    height: 1.15rem;
    flex: none;
    accent-color: var(--tool);
}

/* Library page. */
.library-off {
    max-width: 64ch;
}

.library-gaps {
    margin: 0 0 1.5rem;
}
.library-gap-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem;
}
.library-gap {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.library-gap.is-gap {
    border-color: var(--tool);
    background: var(--tool-tint);
}
.library-gap-name {
    font-weight: 600;
    color: var(--text-primary);
}
.library-gap-count {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.library-filters {
    margin: 0 0 1rem;
}
.library-filter-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0 1rem;
}
.library-filter-row select,
.library-filter-row input,
.library-search input {
    min-height: 44px;
}
.library-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1.5rem;
}
.library-checks label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    cursor: pointer;
}
.library-checks input {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--tool);
}

.library-count {
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}
.library-results {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.75rem;
}
.library-item {
    border-left: 4px solid var(--tool);
}
.library-item.is-withdrawn {
    border-left-color: var(--border-dark);
    background: var(--bg-warm);
}
.library-item-head,
.library-detail-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}
.library-item-title,
.library-detail-title {
    margin: 0;
    color: var(--primary);
    overflow-wrap: anywhere;
}
.library-item-person {
    margin: 0.35rem 0 0;
    font-weight: 600;
}
.library-item-facts,
.library-item-use {
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}
.library-item .btn {
    margin-top: 0.75rem;
    min-height: 44px;
}

.library-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.library-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border-dark);
    background: var(--white);
    color: var(--text-secondary);
}
.library-badge.is-ok {
    border-color: #1a7f54;
    color: #145f40;
    background: rgba(46, 182, 125, 0.1);
}
.library-badge.is-stop {
    border-color: #b91c1c;
    color: #991b1b;
    background: rgba(220, 38, 38, 0.07);
}
.library-badge.is-note {
    border-color: #b45309;
    color: #92400e;
    background: rgba(217, 119, 6, 0.08);
}

.library-empty {
    color: var(--text-muted);
    padding: 1rem 0;
}

/* One story. */
.library-detail > .btn {
    min-height: 44px;
    margin: 0 0 1rem;
}
.library-section {
    margin: 0 0 1rem;
}
.library-section-title {
    margin: 0 0 0.75rem;
    color: var(--primary);
    font-size: 1.125rem;
}
.library-facts {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.35rem 1rem;
    margin: 0;
}
.library-facts dt {
    font-weight: 600;
    color: var(--text-secondary);
}
.library-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.library-quote {
    border-left: 3px solid var(--tool);
    margin: 0 0 1rem;
    padding: 0.25rem 0 0.25rem 1rem;
    font-style: italic;
}
.library-story-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0;
}
.library-version {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin: 0 0 0.75rem;
}
.library-version-headline {
    font-weight: 600;
    margin: 0 0 0.35rem;
}
.library-version .btn {
    min-height: 44px;
}

.library-uses {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}
.library-use {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.library-use.is-planned {
    background: var(--tool-tint);
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}
.library-use-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
.library-use .link-button {
    min-height: 44px;
}
.library-log {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}
.library-log select option:disabled {
    color: var(--text-muted);
}

.library-confirm {
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    background: rgba(220, 38, 38, 0.05);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0 0;
}
.library-confirm .btn {
    min-height: 44px;
    margin: 0.5rem 0.5rem 0 0;
}

@media (max-width: 640px) {
    .story-save-use-list {
        grid-template-columns: minmax(0, 1fr);
    }
    .library-facts {
        grid-template-columns: minmax(0, 1fr);
    }
    .library-facts dd {
        margin-bottom: 0.35rem;
    }
}
