/**
 * notebook-magic.css — Phase 5: the Notebook view, Magic Shelves dialog and
 * the sidebar emoji glyph used for magic shelves.
 *
 * Shared primitives (`.library-page`, `.page-*`, `.controls-toolbar`, `.chip`,
 * `.segmented`, `.field*`, `.empty-state`, `.skeleton-line`, `.icon-button`)
 * live in the base component sheets and are only extended here.
 */

/* ------------------------------------------------------------------------- */
/* Sidebar magic-shelf glyph                                                 */
/* ------------------------------------------------------------------------- */

/* Sits next to `.sidebar-item-icon`; that class already sizes the box. */
.sidebar-item-emoji {
  font-size: 16px;
  line-height: 1;
}

/* ------------------------------------------------------------------------- */
/* Notebook — toolbar                                                        */
/* ------------------------------------------------------------------------- */

.notebook-toolbar {
  flex-wrap: wrap;
  row-gap: var(--space-2);
}

.notebook-type-chips {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.notebook-type-chips .chip {
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-card);
  transition:
    background var(--duration-micro) var(--ease-glide),
    color var(--duration-micro) var(--ease-glide),
    border-color var(--duration-micro) var(--ease-glide);
}

.notebook-type-chips .chip:hover {
  background: var(--color-surface-hover);
}

.notebook-type-chips .chip[aria-pressed="true"] {
  color: var(--color-primary-text);
  border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
  background: var(--color-active-surface);
}

.notebook-book-filter {
  min-width: 160px;
}

.notebook-book-filter .select {
  width: 100%;
  min-width: 160px;
}

/* ------------------------------------------------------------------------- */
/* Notebook — grouped list                                                   */
/* ------------------------------------------------------------------------- */

.notebook-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.notebook-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.notebook-group-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.notebook-group-title {
  font-size: var(--app-text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
}

.notebook-group-author {
  font-size: var(--app-text-sm);
  color: var(--color-text-muted);
}

.notebook-group-count {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--color-text) 7%, transparent);
  font-size: var(--app-text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.notebook-group-entries {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ------------------------------------------------------------------------- */
/* Notebook — single entry                                                   */
/* ------------------------------------------------------------------------- */

.notebook-entry {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-card);
}

.notebook-entry-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-text) 6%, transparent);
  color: var(--color-text-secondary);
}

.notebook-entry--note .notebook-entry-icon {
  color: var(--color-primary-text);
}

.notebook-entry--highlight .notebook-entry-icon {
  color: var(--color-warning);
}

.notebook-entry--bookmark .notebook-entry-icon {
  color: var(--color-info);
}

.notebook-swatch {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--color-card);
}

.notebook-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.notebook-entry-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
}

.notebook-quote {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid color-mix(in srgb, var(--color-primary) 45%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in srgb, var(--color-primary) 5%, transparent);
  font-size: var(--app-text-base);
  color: var(--color-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.notebook-note {
  font-size: var(--app-text-sm);
  color: var(--color-text-secondary);
  overflow-wrap: anywhere;
}

.notebook-note-label {
  margin-right: var(--space-1);
  font-size: var(--app-text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.notebook-entry-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-size: var(--app-text-xs);
  color: var(--color-text-muted);
}

.notebook-type-label {
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

.notebook-meta-sep {
  color: var(--color-text-muted);
}

.notebook-jump {
  flex-shrink: 0;
  align-self: center;
}

/* ------------------------------------------------------------------------- */
/* Notebook — skeletons                                                      */
/* ------------------------------------------------------------------------- */

.notebook-skeleton {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.notebook-skeleton-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

/* Companion to `.skeleton-line--short` from book-card.css. */
.skeleton-line--medium {
  width: 80%;
}

/* ------------------------------------------------------------------------- */
/* Magic shelf dialog                                                        */
/* ------------------------------------------------------------------------- */

.magic-form {
  display: flex;
  flex-direction: column;
}

.magic-form-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: var(--space-3);
  align-items: start;
}

.magic-field-icon .input {
  text-align: center;
}

.magic-match {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.magic-rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.magic-rules {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.magic-rules-empty {
  margin-top: var(--space-2);
  padding: var(--space-3);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: var(--app-text-sm);
  color: var(--color-text-muted);
}

.magic-rule {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.4fr) auto;
  gap: var(--space-2);
  align-items: center;
}

.magic-rule .select,
.magic-rule .input {
  min-width: 0;
}

.magic-rule-novalue {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  color: var(--color-text-muted);
}

.magic-rule-remove {
  justify-self: end;
  color: var(--color-text-muted);
}

.magic-rule-remove:hover {
  color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
}

.magic-form-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.magic-json {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-text) 3%, transparent);
}

.magic-json[hidden] {
  display: none;
}

.magic-json textarea {
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: var(--app-text-sm);
}

.magic-json-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.magic-preview {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--app-text-sm);
}

.magic-preview--idle,
.magic-preview--loading {
  border-color: var(--color-border);
  background: color-mix(in srgb, var(--color-text) 4%, transparent);
  color: var(--color-text-secondary);
}

.magic-preview--ok {
  border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  color: var(--color-success);
}

.magic-preview--error {
  border-color: color-mix(in srgb, var(--color-danger) 30%, transparent);
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  color: var(--color-danger);
}

.magic-preview-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.magic-preview-text {
  min-width: 0;
}

/* ------------------------------------------------------------------------- */
/* Responsive                                                                */
/* ------------------------------------------------------------------------- */

@media (max-width: 520px) {
  .magic-form-top {
    grid-template-columns: 1fr;
  }

  .magic-rule {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .magic-rule-remove {
    grid-column: 2;
  }

  .notebook-jump span {
    display: none;
  }
}
