/* Video Saver — Shelf-style layout on Lumen tokens */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-app);
  color: var(--fg-default);
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv11";
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ======= APP SHELL ======= */
.shelf-app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

/* ======= LEFT RAIL ======= */
.rail {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  gap: 22px;
  overflow: hidden;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 2px;
}

.rail-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: radial-gradient(
    120% 120% at 30% 20%,
    var(--ember-600) 0%,
    var(--ember-500) 40%,
    var(--ember-700) 100%
  );
  display: grid;
  place-items: center;
  color: #1c1309;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  flex: 0 0 auto;
}

.rail-mark svg {
  width: 16px;
  height: 16px;
}

.rail-word {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--fg-strong);
  white-space: nowrap;
}

.rail-word em {
  font-style: italic;
  font-weight: 400;
  color: var(--fg-accent);
}

.rail-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-label {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  font-weight: 600;
  padding: 6px 10px 2px;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
  position: relative;
}

.rail-item:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}

.rail-item[hidden] {
  display: none;
}

.rail-item.is-active {
  background: var(--accent-subtle);
  color: var(--fg-accent);
}

.rail-item.is-active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.rail-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rail-item .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}

.rail-item.is-active .count {
  color: var(--fg-accent);
}

.rail-item .lbl {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-soon {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-muted);
  color: var(--fg-subtle);
  text-transform: uppercase;
}

/* ======= TYPE SWITCH (primary content types) ======= */
.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-inset);
}

.type-seg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 10px 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  line-height: 1.2;
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast), box-shadow var(--dur-fast);
  position: relative;
  min-height: 64px;
}

.type-seg:hover {
  color: var(--fg-strong);
}

.type-seg.is-on {
  background: var(--bg-surface);
  color: var(--fg-strong);
  border-color: var(--border-default);
  box-shadow: var(--shadow-sm);
}

.type-seg.is-on > svg {
  color: var(--fg-accent);
}

.type-seg .type-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.type-seg .type-lbl {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.type-seg .type-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-muted);
  line-height: 1.4;
  min-width: 20px;
}

.type-seg.is-on .type-count {
  color: var(--fg-accent);
  background: var(--accent-subtle);
}

.type-soon-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px;
  margin-top: -14px;
}

.type-soon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--fg-subtle);
  padding: 3px 8px;
  border: 1px dashed var(--border-default);
  border-radius: var(--r-full);
  opacity: 0.75;
  cursor: not-allowed;
}

.type-soon svg {
  color: var(--fg-subtle);
}

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rail-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border-subtle);
  margin-top: 6px;
  padding-top: 14px;
}

.rail-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--paper-300);
  color: var(--paper-900);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  flex: 0 0 auto;
}

.rail-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-strong);
}

.rail-user-sub {
  font-size: 11.5px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}

/* ======= MAIN ======= */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ======= TOPBAR ======= */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-app);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 8px 12px;
  max-width: 360px;
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.topbar-search svg {
  color: var(--fg-subtle);
}

.topbar-search:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.topbar-search input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--fg-strong);
  font-family: inherit;
  font-size: 14px;
  min-width: 0;
}

.topbar-search input::placeholder {
  color: var(--fg-subtle);
}

/* ======= QUICK ADD (inline in topbar) ======= */
.qadd {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 4px 4px 4px 12px;
  min-width: 0;
  flex: 1;
  max-width: 640px;
  transition: border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.qadd:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.qadd[hidden] {
  display: none;
}

.new-note-btn {
  flex: 0 0 auto;
  padding: 9px 14px;
  font-size: 14px;
  align-self: stretch;
}

.new-note-btn[hidden] {
  display: none;
}

.new-note-kbd {
  background: rgba(255, 255, 255, 0.18);
  border-color: transparent;
  color: var(--paper-50);
}

.qadd > svg {
  color: var(--fg-subtle);
  flex: 0 0 auto;
}

.qadd input[type="url"] {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--fg-strong);
  font-family: inherit;
  font-size: 14px;
  min-width: 0;
  padding: 0;
}

.qadd input[type="url"]::placeholder {
  color: var(--fg-subtle);
}

.qadd .qadd-list {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-muted);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% - 2px),
    calc(100% - 8px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  transition: background-color var(--dur-fast) var(--ease-out);
  max-width: 160px;
}

.qadd .qadd-list:hover {
  color: var(--fg-strong);
}

.qadd-paste {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.qadd-paste:hover {
  background: var(--bg-muted);
  color: var(--fg-strong);
}

.qadd-file {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px dashed var(--border-default);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  transition: border-color var(--dur-fast), color var(--dur-fast),
    background var(--dur-fast);
  min-width: 0;
}

.qadd-file:hover,
.qadd-file.is-dragover {
  color: var(--fg-strong);
  border-color: var(--ember-500);
  background: var(--accent-subtle);
}

.qadd-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qadd-file.has-file {
  color: var(--fg-accent);
  border-style: solid;
  border-color: var(--ember-500);
  background: var(--accent-subtle);
}

/* ======= PAGE CONTAINER ======= */
.page {
  max-width: 1180px;
  width: 100%;
  padding: 28px 28px 80px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 32px;
  align-items: start;
}

/* ======= PAGE HEADER ======= */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.page-head.is-hidden {
  display: none;
}

.page-title {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.02;
  color: var(--fg-strong);
  margin: 0;
}

.page-sub {
  font-size: 13px;
  color: var(--fg-muted);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.page-sub .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--paper-400);
  display: inline-block;
  flex: 0 0 auto;
}

.page-head-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ======= FILTER BAR ======= */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  border-radius: var(--r-full);
  font-size: 12.5px;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
  font-family: inherit;
}

.chip:hover {
  color: var(--fg-strong);
  background: var(--bg-subtle);
}

.chip.is-active {
  color: var(--fg-accent);
  border-color: var(--ember-500);
  background: var(--accent-subtle);
}

.chip .count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
  padding-left: 2px;
}

.chip.is-active .count {
  color: var(--fg-accent);
}

.filter-spacer {
  flex: 1;
}

.sort-select {
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 24px 6px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% - 2px),
    calc(100% - 8px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.sort-select:hover {
  color: var(--fg-strong);
}

/* ======= SELECTION BAR ======= */
.selection-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin-bottom: 14px;
  background: var(--accent-subtle);
  border: 1px solid var(--ember-500);
  border-radius: var(--r-md);
}

.selection-bar[hidden] {
  display: none;
}

.selection-bar .eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-accent);
  font-weight: 600;
}

.selection-bar h3 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  color: var(--fg-strong);
  letter-spacing: -0.01em;
}

.selection-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ======= VIDEO LIST ======= */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-list[hidden] {
  display: none;
}

.vid {
  display: grid;
  grid-template-columns: 24px 168px minmax(0, 1fr) auto;
  gap: 18px;
  padding: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  align-items: center;
  transition: border-color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    transform var(--dur-instant);
}

.vid:hover {
  border-color: var(--border-default);
  background: var(--bg-subtle);
}

.vid.is-selected {
  border-color: var(--ember-500);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.vid.is-done {
  opacity: 0.55;
}

.vid.is-done .vid-title {
  text-decoration: line-through;
  text-decoration-color: var(--fg-subtle);
}

.select-checkbox {
  width: 18px;
  height: 18px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border-strong);
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  display: grid;
  place-items: center;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}

.select-checkbox:hover {
  border-color: var(--fg-muted);
}

.select-checkbox:checked {
  background: var(--success-line);
  border-color: var(--success-line);
}

.select-checkbox:checked::after {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 1.5px solid var(--paper-0);
  border-bottom: 1.5px solid var(--paper-0);
  transform: rotate(-45deg) translate(1px, -1px);
}

[data-theme="dark"] .select-checkbox:checked::after {
  border-color: var(--paper-900);
}

.vid-thumb {
  position: relative;
  width: 168px;
  aspect-ratio: 16/9;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--paper-200);
  display: block;
  text-decoration: none;
}

.vid-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.9) contrast(1.02);
}

.vid-thumb .src-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(14, 13, 10, 0.85);
  color: var(--paper-800);
  font-family: var(--font-mono);
  font-size: 9.5px;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.vid-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vid-meta {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.vid-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--paper-400);
  flex: 0 0 auto;
}

.vid-meta .list-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--fg-accent);
}

.vid-meta .list-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.vid-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-strong);
  line-height: 1.35;
  letter-spacing: -0.005em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: pretty;
  text-decoration: none;
  cursor: pointer;
}

.vid-title:hover {
  color: var(--fg-accent);
}

.vid-inline-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  flex-wrap: wrap;
}

.vid-inline-actions .move-select {
  font-family: inherit;
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 4px 22px 4px 8px;
  max-width: 180px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 10px) calc(50% - 2px),
    calc(100% - 6px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.vid-inline-actions .move-select:focus {
  border-color: var(--border-focus);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.vid-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.act {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  color: var(--fg-muted);
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast);
}

.act svg {
  width: 15px;
  height: 15px;
}

.act:hover {
  background: var(--bg-muted);
  color: var(--fg-strong);
  border-color: var(--border-default);
}

.act.act-done:hover {
  color: var(--success-fg);
  border-color: var(--success-line);
}

.act.act-danger:hover {
  color: var(--danger-fg);
  border-color: var(--danger-line);
}

/* ======= COLLECTIONS SIDEBAR (right) ======= */
.side {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
}

.panel-head .eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  font-weight: 600;
}

.new-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.new-list input {
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--fg-strong);
  outline: 0;
  min-width: 0;
}

.new-list input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.coll-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.coll {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--fg-muted);
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast);
  width: 100%;
}

.coll:hover {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}

.coll.is-active {
  background: var(--accent-subtle);
  color: var(--fg-accent);
  border-color: transparent;
}

.coll .coll-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paper-400);
  flex: 0 0 auto;
}

.coll.is-active .coll-dot {
  background: var(--ember-500);
}

.coll .coll-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.coll .coll-n {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}

.coll.is-active .coll-n {
  color: var(--fg-accent);
}

.coll-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-plain {
  background: transparent;
  border: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background var(--dur-fast), color var(--dur-fast);
  width: 100%;
}

.btn-plain:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}

.btn-plain.danger:hover:not(:disabled) {
  color: var(--danger-fg);
}

.btn-plain:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.io-row {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.io-btn {
  flex: 1;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--bg-muted);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: 12px;
  color: var(--fg-muted);
  font-family: inherit;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.io-btn:hover {
  background: var(--paper-200);
  color: var(--fg-strong);
}

.io-btn input[type="file"] {
  display: none;
}

.hotkeys {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hotkeys .hk {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  color: var(--fg-muted);
}

.hotkeys .hk .keys {
  display: inline-flex;
  gap: 2px;
}

.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  background: var(--bg-muted);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  line-height: 1.5;
}

/* ======= BUTTONS ======= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast),
    border-color var(--dur-fast), box-shadow var(--dur-base),
    transform var(--dur-instant);
  line-height: 1.2;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-md {
  padding: 9px 14px;
  font-size: 14px;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 15px;
}

.btn-primary {
  background: var(--accent);
  color: var(--fg-on-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  background: var(--accent-press);
  transform: translateY(1px);
  box-shadow: var(--shadow-inset);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--fg-strong);
  border-color: var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}

.btn-danger {
  color: var(--danger-fg);
}

.btn-danger:hover {
  background: var(--danger-bg);
}

/* ======= EMPTY STATE ======= */
.empty {
  padding: 72px 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-xl);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  transition: border-color var(--dur-fast), color var(--dur-fast),
    background var(--dur-fast);
}

.empty.is-clickable {
  cursor: pointer;
}

.empty.is-clickable:hover {
  border-color: var(--ember-500);
  background: var(--accent-subtle);
}

.empty.is-clickable:hover h3 {
  color: var(--fg-accent);
}

.empty[hidden] {
  display: none;
}

.empty-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  display: grid;
  place-items: center;
  color: var(--fg-muted);
  border: 1px solid var(--border-default);
  margin-bottom: 4px;
}

.empty h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  margin: 0;
  color: var(--fg-strong);
  letter-spacing: -0.01em;
}

.empty p {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
  max-width: 420px;
  text-wrap: pretty;
}

.empty-hint {
  margin-top: 8px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--fg-subtle);
}

/* ======= BOOKS GRID ======= */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 22px;
}

.books-grid[hidden] {
  display: none;
}

.book {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.book-cover {
  aspect-ratio: 2 / 3;
  border-radius: var(--r-md);
  background: var(--paper-200);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
  transition: transform var(--dur-base) var(--ease-emphasized);
  display: block;
  text-decoration: none;
}

.book:hover .book-cover {
  transform: translateY(-2px);
}

.book-cover.placeholder {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px 14px 16px;
  font-family: var(--font-display);
  color: var(--paper-0);
}

[data-theme="dark"] .book-cover.placeholder {
  color: var(--paper-50);
}

.book-cover .bc-title {
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: pretty;
}

.book-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-strong);
  line-height: 1.3;
  text-decoration: none;
}

.book-title:hover {
  color: var(--fg-accent);
}

.book-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}

.book-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--paper-400);
  flex: 0 0 auto;
}

.book-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
  opacity: 0;
  transition: opacity var(--dur-fast);
  flex-wrap: wrap;
}

.book:hover .book-actions,
.book:focus-within .book-actions {
  opacity: 1;
}

.book-actions .move-select {
  font-family: inherit;
  font-size: 11.5px;
  color: var(--fg-muted);
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 3px 20px 3px 8px;
  max-width: 130px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 10px) calc(50% - 2px),
    calc(100% - 6px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.book-actions .delete-book {
  width: auto;
  padding: 3px 8px;
  font-size: 11.5px;
  gap: 4px;
}

/* ======= ARTICLES LIST ======= */
.article-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.article-list[hidden] {
  display: none;
}

.article {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  align-items: center;
  transition: border-color var(--dur-fast),
    background var(--dur-fast),
    transform var(--dur-instant);
}

.article:hover {
  border-color: var(--border-default);
  background: var(--bg-subtle);
}

.article.is-done {
  opacity: 0.55;
}

.article.is-done .article-title {
  text-decoration: line-through;
  text-decoration-color: var(--fg-subtle);
}

.article-fav {
  width: 52px;
  height: 52px;
  border-radius: var(--r-md);
  color: var(--paper-0);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  flex: 0 0 auto;
  letter-spacing: 0;
  background: var(--paper-300);
}

[data-theme="dark"] .article-fav {
  color: var(--paper-50);
}

.article-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  min-width: 0;
}

.article-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-strong);
  line-height: 1.35;
  letter-spacing: -0.005em;
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-body:hover .article-title {
  color: var(--fg-accent);
}

.article-meta {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.article-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--paper-400);
  flex: 0 0 auto;
}

.article-source {
  color: var(--fg-accent);
}

.article-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  opacity: 0;
  transition: opacity var(--dur-fast);
}

.article:hover .article-actions,
.article:focus-within .article-actions {
  opacity: 1;
}

.article-actions .move-select {
  font-family: inherit;
  font-size: 11.5px;
  color: var(--fg-muted);
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 3px 20px 3px 8px;
  max-width: 130px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 10px) calc(50% - 2px),
    calc(100% - 6px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

/* ======= NOTES GRID ======= */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  align-content: start;
  min-height: 320px;
  cursor: pointer;
}

.notes-grid[hidden],
.notes-grid:empty {
  display: none;
}

.notes-grid:not(:empty)::after {
  content: "Кликни сюда, чтобы создать ещё одну заметку";
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed var(--border-default);
  border-radius: var(--r-lg);
  color: var(--fg-subtle);
  font-size: 13px;
  margin-top: 4px;
  transition: border-color var(--dur-fast), color var(--dur-fast),
    background var(--dur-fast);
}

.notes-grid:not(:empty):hover::after {
  border-color: var(--ember-500);
  color: var(--fg-accent);
  background: var(--accent-subtle);
}

.note {
  padding: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
  cursor: pointer;
  transition: border-color var(--dur-fast),
    transform var(--dur-instant);
}

.note:hover {
  border-color: var(--border-default);
}

.note:active {
  transform: scale(0.995);
}

.note.is-done {
  opacity: 0.6;
}

.note-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  color: var(--fg-strong);
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: pretty;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-body {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
  white-space: pre-wrap;
}

.note-body:empty::before {
  content: "Без тела";
  color: var(--fg-subtle);
  font-style: italic;
}

.note-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
  gap: 8px;
}

.note-foot .note-list {
  color: var(--fg-accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.note-foot .note-list::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.note-foot .note-list:empty::before {
  display: none;
}

/* ======= INLINE NOTE EDITOR ======= */
.modal-head-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 5px 24px 5px 10px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--fg-muted);
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) calc(50% - 2px),
    calc(100% - 8px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  max-width: 200px;
  text-overflow: ellipsis;
}

.modal-head-select:hover,
.modal-head-select:focus {
  color: var(--fg-strong);
  border-color: var(--border-strong);
  outline: 0;
}

.inline-editor[hidden] {
  display: none;
}

.inline-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inline-editor-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.inline-editor-back {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.inline-editor-back:hover {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}

.inline-editor-spacer {
  flex: 1;
}

.inline-editor-status {
  font-size: 11.5px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}

.inline-editor-canvas {
  outline: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--fg-default);
  min-height: 60vh;
  padding: 12px 0 80px;
  caret-color: var(--accent);
}

.inline-editor-canvas::first-line {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.15;
  font-weight: 500;
  color: var(--fg-strong);
  letter-spacing: -0.015em;
}

.inline-editor-canvas:empty::before {
  content: attr(data-placeholder);
  color: var(--fg-subtle);
  white-space: pre-line;
  pointer-events: none;
}

/* ======= ARCHIVE ======= */
.archive-section {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.archive-section[hidden] {
  display: none;
}

.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.archive-header .eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  font-weight: 600;
}

.archive-header .summary-caption {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.archive-list {
  margin-top: 12px;
}

/* ======= TOAST ======= */
.toast-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--paper-800);
  color: var(--paper-0);
  border-radius: var(--r-full);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 220ms var(--ease-emphasized);
  pointer-events: all;
}

[data-theme="dark"] .toast {
  background: var(--paper-300);
  color: var(--paper-900);
}

.toast[hidden] {
  display: none;
}

.toast .toast-acc,
.toast-undo {
  background: transparent;
  border: 0;
  color: var(--ember-400);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.toast .toast-acc:hover {
  text-decoration: underline;
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* ======= RESPONSIVE ======= */
@media (max-width: 1140px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    position: static;
  }
}

@media (max-width: 900px) {
  .shelf-app {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    gap: 12px;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
  }

  .rail-section,
  .rail-foot {
    flex-direction: row;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .rail-label {
    display: none;
  }

  .rail-user {
    border-top: 0;
    padding: 0;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 16px;
  }

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

  .qadd {
    flex-wrap: wrap;
    max-width: none;
  }

  .qadd input[type="url"] {
    min-width: 180px;
  }

  .page {
    padding: 20px 16px 60px;
  }

  .page-title {
    font-size: 32px;
  }

  .vid {
    grid-template-columns: 24px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 10px;
  }

  .vid-thumb {
    grid-column: 1 / -1;
    width: 100%;
  }

  .vid-body {
    grid-column: 1 / -1;
  }

  .vid-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}
