/* ─── Library Screen ─── */

#libraryScreen {
  flex-direction: column;
  min-height: 100vh;
}

.library-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.library-search {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 180px;
  min-width: 100px;
  flex-shrink: 1;
  transition: border-color 0.2s;
}

.library-search:focus {
  border-color: var(--accent);
}

.library-sort-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
}

.library-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ─── Grid ─── */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 20px;
  min-height: calc(100vh - 60px);
}

.library-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.library-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.library-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.library-card-info {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.library-filename {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Stars ─── */
.library-stars {
  display: flex;
  gap: 2px;
}

.library-stars .star {
  font-size: 0.85rem;
  color: var(--border);
  cursor: pointer;
  transition: color 0.1s;
  line-height: 1;
}

.library-stars .star:hover,
.library-stars .star.active {
  color: #f5a623;
}

/* ─── Flags ─── */
.library-flag {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}

.library-flag.pick {
  background: #34a853;
}

.library-flag.reject {
  background: #ea4335;
}

/* ─── Color labels ─── */
.library-color-label {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.8);
}

.library-color-label.red { background: #ea4335; }
.library-color-label.yellow { background: #fbbc04; }
.library-color-label.green { background: #34a853; }
.library-color-label.blue { background: #4285f4; }
.library-color-label.purple { background: #9c27b0; }

/* ─── Empty state ─── */
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ─── Context menu ─── */
.context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 6px 0;
  min-width: 180px;
}

.context-item {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}

.context-item:hover {
  background: var(--accent-light);
}

.context-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .library-card img {
    height: 120px;
  }

  .library-toolbar {
    justify-content: stretch;
  }

  .library-search {
    width: 100%;
  }
}
