/* knowledge.css — Knowledge dashboard styles */

/* ── Quick-add form ─────────────────────────────────────────────────────── */
.k-add-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
}

.k-add-card h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: var(--space-sm);
}

.k-add-row {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.k-add-row input,
.k-add-row select {
    padding: 7px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
}

.k-add-row input[name="title"],
.k-add-row input#qa-title {
    flex: 2;
    min-width: 160px;
}

.k-add-row input[name="url"],
.k-add-row input#qa-url {
    flex: 2;
    min-width: 140px;
}

.k-add-row select {
    flex: 1;
    min-width: 110px;
}

.k-add-row input:focus,
.k-add-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.k-add-row .btn-primary {
    flex-shrink: 0;
}

/* ── Feed cards ─────────────────────────────────────────────────────────── */
#feed-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.k-feed-card {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-md);
    transition: border-color var(--transition);
}

.k-feed-card:hover {
    border-color: var(--accent);
}

.k-feed-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.k-feed-body {
    flex: 1;
    min-width: 0;
}

.k-feed-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.k-feed-meta {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.k-feed-link {
    font-size: 11px;
    color: var(--accent);
    text-decoration: none;
    display: block;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.k-feed-del {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.5;
    transition: opacity var(--transition);
    flex-shrink: 0;
}

.k-feed-del:hover {
    opacity: 1;
    color: var(--danger);
}

/* ── Library hero card ──────────────────────────────────────────────────── */
.k-lib-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.k-lib-hero {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-xl) var(--space-lg);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
}

.k-lib-icon {
    font-size: 3rem;
    line-height: 1;
}

.k-lib-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.k-lib-sub {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 380px;
}

.k-lib-url {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: -var(--space-sm);
}

/* ── Library Grid ───────────────────────────────────────────────────────── */
.k-lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 130px);
    justify-content: flex-start;
    gap: var(--space-xl) var(--space-md);
    margin-top: var(--space-xl);
}

.k-book-card {
    display: flex;
    flex-direction: column;
    background: transparent;
    text-decoration: none !important;
    transition: transform var(--transition);
    width: 130px;
    min-width: 130px;
    max-width: 130px;
}

.k-book-card:hover {
    transform: translateY(-4px);
}

.k-book-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    background-color: var(--bg-hover);
    background-size: cover;
    background-position: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    margin-bottom: var(--space-sm);
    overflow: hidden;
    position: relative;
    /* Anchor for absolute children */
}

.k-book-title-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    opacity: 0.6;
    text-align: center;
    word-break: break-word;
}

.k-book-info {
    padding: 0 2px;
}

.k-book-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    line-height: 1.3;
    /* Enforce standardized 2-line height */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 31px;
}

.k-book-author {
    font-size: 11px;
    color: var(--text-faint);
    /* Enforce 1-line truncation */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Edit Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    opacity: 0;
    transition: opacity var(--transition);
}

.modal-overlay.open {
    display: block;
    opacity: 1;
}

.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -45%);
    width: 90%;
    max-width: 440px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    z-index: 201;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: all 0.2s ease-out;
}

.modal.open {
    display: block;
    transform: translate(-50%, -50%);
    opacity: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 16px;
    cursor: pointer;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-lg);
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color var(--transition);
}

.form-group textarea {
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.k-book-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: transparent;
    text-decoration: none !important;
    transition: transform var(--transition);
}

.k-book-edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--borderStrong);
    color: var(--text-primary);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.9);
    transition: all var(--transition);
    z-index: 10;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.k-book-card:hover .k-book-edit-btn {
    opacity: 1;
    transform: scale(1);
}

.k-book-edit-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg-elevated);
}

.k-book-tags {
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.k-book-series {
    font-size: 11px;
    color: var(--accent);
    font-style: italic;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Books Tracking Tab ─────────────────────────────────────────────────── */
.k-books-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.k-books-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ── Condensed Single-Line Filter Toolbar ───────────────────────────────── */
.k-books-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 8px 14px;
    box-shadow: inset 0 0 0 1px var(--accent-glow);
    transition: border-color var(--transition);
}

.k-books-toolbar:focus-within {
    border-color: var(--accent);
}

.k-toolbar-search {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 140px;
}

/* All chips + sort grouped on the right */
.k-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.k-toolbar-icon {
    display: block;
    flex-shrink: 0;
    color: var(--text-faint);
    pointer-events: none;
}

.k-toolbar-search input[type="search"] {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    min-width: 80px;
    caret-color: var(--accent);
}

.k-toolbar-search input[type="search"]::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.k-toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 2px;
}

.k-type-chip {
    padding: 4px 12px;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.k-type-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.k-type-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 700;
}

.k-toolbar-select {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 28px 4px 10px;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition), color var(--transition);
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%238888a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.k-toolbar-select:focus,
.k-toolbar-select:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.k-status-check {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-faint);
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition);
}

.k-status-check:hover {
    color: var(--text-primary);
}

.k-status-check input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.filter-chip {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-faint);
    font-family: var(--font);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
}

.filter-chip:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.filter-chip.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}

/* ── Book Details Modal ─────────────────────────────────────────────────── */
.book-details {
    max-width: 800px;
    width: 90%;
}

.book-details-body {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    max-height: 80vh;
    overflow-y: auto;
}

@media (min-width: 600px) {
    .book-details-body {
        flex-direction: row;
        align-items: stretch;
    }
}

.k-detail-hero {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    flex: 0 0 250px;
    max-height: 100%;
    overflow-y: auto;
    padding-right: 8px;
    /* space for scrollbar */
}

/* Custom scrollbar for hero */
.k-detail-hero::-webkit-scrollbar {
    width: 6px;
}

.k-detail-hero::-webkit-scrollbar-track {
    background: transparent;
}

.k-detail-hero::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

.detail-cover {
    width: 100%;
    max-width: 200px;
    aspect-ratio: 2/3;
    margin-bottom: 0;
    margin: 0 auto;
    flex-shrink: 0;
}

.bd-summary {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    margin-top: var(--space-md);
    border-left: 2px solid var(--accent);
}

#bd-status-buttons .filter-chip {
    flex: 1;
    text-align: center;
    border-color: var(--border);
}

#bd-status-buttons .filter-chip.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.k-detail-info {
    display: flex;
    flex-direction: column;
}

#bd-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 4px;
}

.k-detail-tags {
    margin-top: 8px;
    white-space: normal;
}

.bd-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.bd-tracking-section {
    flex: 1;
    /* Takes remaining space on the left */
    background: var(--bg-elevated);
    padding: var(--space-md);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.bd-tracking-section select,
.bd-tracking-section textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    resize: vertical;
}

.bd-tracking-section select:focus,
.bd-tracking-section textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.w-full {
    width: 100%;
    justify-content: center;
}

/* ── Star Rating ─────────────────────────────────────────────────────────── */
.star-rating {
    display: flex;
    gap: 4px;
    font-size: 24px;
    color: var(--border-strong);
    cursor: pointer;
    user-select: none;
}

.star-rating span {
    transition: color 150ms ease;
}

.star-rating span.active,
.star-rating span.hover-active {
    color: var(--accent);
}

/* ── Grouped Books Sections ──────────────────────────────────────────────── */
.k-books-sections {
    display: flex;
    flex-direction: column;
    gap: var(--space-2xl);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.k-book-list-section {
    width: 100%;
    max-width: 100%;
}

.k-book-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.k-book-list-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.k-book-scroll-actions {
    display: flex;
    gap: 8px;
}

.scroll-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-faint);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
}

.scroll-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.k-book-list-section h3 .badge-count {
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-faint);
    border: 1px solid var(--border);
}

.k-book-row-grid {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    scroll-snap-type: x mandatory;
    gap: var(--space-md);
    padding-bottom: var(--space-md);
    /* space for scrollbar */
    /* Hide scrollbar for a cleaner look but keep functionality */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.k-book-row-grid::-webkit-scrollbar {
    display: none;
}

.k-book-row-grid>.k-book-card {
    flex: 0 0 130px;
    scroll-snap-align: start;
}

/* ── Toggle Switch ───────────────────────────────────────────────────────── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-strong);
    transition: .4s;
    border-radius: 22px;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.toggle-switch input:checked+.slider {
    background-color: var(--accent);
}

.toggle-switch input:checked+.slider:before {
    transform: translateX(18px);
}

.k-track-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    z-index: 5;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.k-track-badge.reading {
    color: var(--warning);
    border-color: rgba(251, 191, 36, 0.3);
}

.k-track-badge.read {
    color: var(--success);
    border-color: rgba(74, 222, 128, 0.3);
}

.k-book-card.clickable-card {
    cursor: pointer;
}

/* ============================================================
   LIBRARY OVERVIEW — Unified knowledge dashboard
   ============================================================ */

/* Scroll row for preview items */
.k-lib-scroll-row {
  display: flex;
  gap: var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-sm);
  scrollbar-width: none;
  min-width: 0;
}
.k-lib-scroll-row::-webkit-scrollbar { display: none; }

/* Ensure grid-2 children don't overflow */
.grid-2 > .card { min-width: 0; overflow: hidden; }

/* Mini card used in overview rows */
.k-lib-mini-card {
  flex: 0 0 120px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.k-lib-mini-card:hover {
  transform: translateY(-2px);
}
.k-lib-mini-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--bg-elevated);
  background-size: cover;
  background-position: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  position: relative;
  overflow: hidden;
}
.k-lib-mini-cover.landscape {
  aspect-ratio: 16 / 9;
}
.k-lib-mini-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-faint);
}
.k-lib-mini-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.k-lib-mini-sub {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.k-lib-mini-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-size: 8px;
  font-weight: 600;
  color: var(--text-muted);
}
.k-lib-mini-badge.active { color: var(--warning); border-color: rgba(251,191,36,0.3); }
.k-lib-mini-badge.done   { color: var(--success); border-color: rgba(74,222,128,0.3); }

/* Currently Consuming — list style */
.k-lib-current-list {
  display: flex;
  flex-direction: column;
}
.k-lib-current-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s ease;
}
.k-lib-current-item:last-child { border-bottom: none; }
.k-lib-current-item:hover { background: var(--bg-hover); margin: 0 calc(-1 * var(--space-md)); padding-left: var(--space-md); padding-right: var(--space-md); border-radius: var(--radius-sm); }
.k-lib-current-icon { font-size: 20px; flex-shrink: 0; width: 32px; text-align: center; }
.k-lib-current-body { flex: 1; min-width: 0; }
.k-lib-current-title { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.k-lib-current-meta { font-size: 11px; color: var(--text-muted); }
.k-lib-current-status {
  font-size: 10px;
  font-weight: 600;
  text-transform: capitalize;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(251,191,36,0.15);
  color: var(--warning);
  flex-shrink: 0;
}

/* Empty state for overview sections */
.k-lib-section-empty {
  padding: var(--space-md);
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
}

/* Landscape mini cards (articles, videos) */
.k-lib-mini-card.landscape { flex: 0 0 180px; }

@media (max-width: 768px) {
  .k-lib-mini-card { flex: 0 0 100px; }
  .k-lib-mini-card.landscape { flex: 0 0 150px; }
}

/* ============================================================
   MEDIA LIBRARY — Podcasts, Articles, TV/Movies, Videos
   ============================================================ */

/* ─── Tab bar horizontal scroll (8 tabs) ────────────────── */
.tabs {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { white-space: nowrap; flex-shrink: 0; }

/* ─── Media tab header ──────────────────────────────────── */
.k-media-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}
.k-media-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.k-media-count {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ─── Media toolbar (reuses book toolbar pattern) ───────── */
.k-media-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

/* ─── Media card grid ───────────────────────────────────── */
.k-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-md);
}
.k-media-grid.landscape {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* ─── Media card ────────────────────────────────────────── */
.k-media-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.k-media-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

/* Portrait cover (podcasts, shows, movies) */
.k-media-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--bg-elevated);
  background-size: cover;
  background-position: center;
  position: relative;
}

/* Landscape cover (articles, videos) */
.k-media-cover.landscape {
  aspect-ratio: 16 / 9;
}

/* Placeholder when no cover */
.k-media-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--text-faint);
  background: var(--bg-elevated);
}

/* Fallback icon behind <img> — shows when image fails to load */
.k-cover-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 32px;
  color: var(--text-faint);
}

/* Platform badge on cover */
.k-media-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Status badge on cover */
.k-media-status-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
}
.k-media-status-badge.active {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.3);
}
.k-media-status-badge.done {
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}
.k-media-status-badge.dropped {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

/* Card body */
.k-media-body {
  padding: 8px 10px 10px;
}
.k-media-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  margin-bottom: 3px;
}
.k-media-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.k-media-card-rating {
  font-size: 10px;
  color: var(--accent);
  margin-top: 4px;
  letter-spacing: 1px;
}

/* ─── AI Enrichment row in modal ────────────────────────── */
.k-enrich-row {
  display: flex;
  gap: 8px;
}
.k-enrich-row input {
  flex: 1;
}
.k-enrich-btn {
  white-space: nowrap;
  border: 1px solid var(--accent) !important;
  color: var(--accent) !important;
}
.k-enrich-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

@keyframes enrich-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.k-enrich-btn.loading {
  animation: enrich-pulse 1.2s infinite;
}

/* ─── Media Detail Modal (review-website layout) ─────────── */
.k-media-hero {
  flex: 0 0 280px;
  flex-shrink: 0;
}

/* Poster — always shows full, never gets cut off */
.mm-cover-wrap {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
  position: relative;
  margin-bottom: var(--space-md);
  flex-shrink: 0;
}

.mm-cover-wrap::before {
  content: '';
  display: block;
  padding-bottom: 150%; /* 2:3 portrait */
}

.mm-cover-wrap.landscape-cover::before {
  padding-bottom: 56.25%; /* 16:9 */
}

.mm-cover-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
}

/* Placeholder sits behind img — only visible when no image or image fails */
.mm-cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: var(--text-faint);
  z-index: 1;
}

/* Hide placeholder entirely when image is loaded */
.mm-cover-wrap.has-image .mm-cover-placeholder {
  display: none;
}

/* Title row — title + rating + recommended inline */
.mm-title-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.mm-title-display {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
}

.mm-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 2px;
}

.mm-inline-rating {
  font-size: 18px;
}

.mm-rec-toggle {
  margin: 0;
  transform: scale(0.85);
}

/* Small uppercase labels on the left column */
.mm-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  font-weight: 600;
}

.mm-left-group {
  margin-bottom: 0;
}

/* Summary with show-more collapse */
.mm-summary-text {
  max-height: 80px;
  overflow: hidden;
  position: relative;
  transition: max-height 0.3s ease;
}

.mm-summary-text.expanded {
  max-height: none;
}

.mm-summary-toggle {
  padding: 2px 0;
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
}

/* Right column — scrollable */
.mm-details-section {
  overflow-y: auto;
  max-height: 100%;
}

.mm-section {
  margin-bottom: var(--space-md);
}

.mm-section:last-of-type {
  margin-bottom: 0;
}

/* AI Enrichment input — match dark theme */
.mm-enrich-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--transition);
}
.mm-enrich-input:focus {
  outline: none;
  border-color: var(--accent);
}
.mm-enrich-input::placeholder {
  color: var(--text-faint);
}

/* Collapsible edit details */
.mm-edit-details {
  margin-bottom: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mm-edit-details summary {
  padding: 10px var(--space-md);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-hover);
  user-select: none;
}

.mm-edit-details summary:hover {
  color: var(--text-primary);
}

.mm-edit-details[open] summary {
  border-bottom: 1px solid var(--border);
}

.mm-edit-fields {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.mm-edit-fields .form-group {
  margin-bottom: 0;
}

/* Status chips in media modal */
#mf-status-buttons .filter-chip {
  flex: 1;
  text-align: center;
  font-size: 12px;
  padding: 6px 10px;
}

#mf-status-buttons .filter-chip.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* Media modal responsive — mobile must scroll to right column */
@media (max-width: 600px) {
  .k-media-hero {
    flex: 0 0 auto;
  }
  .mm-cover-wrap {
    max-width: 200px;
    margin: 0 auto var(--space-md);
  }
  /* On mobile the body is column, so let it scroll fully */
  #media-modal .book-details-body {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Don't let right column have its own scroll on mobile */
  #media-modal .mm-details-section {
    overflow-y: visible;
    max-height: none;
  }
}

/* ─── Media empty state ─────────────────────────────────── */
.k-media-empty {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  color: var(--text-faint);
}
.k-media-empty-icon {
  font-size: 40px;
  margin-bottom: var(--space-sm);
}
.k-media-empty-text {
  font-size: 14px;
  margin-bottom: var(--space-md);
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .k-media-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .k-media-grid.landscape {
    grid-template-columns: 1fr;
  }
  .k-media-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .k-media-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }
}