/* V2 additions: topic management, tags, tasks, media, settings, admin.
   Depends on tokens.css and components.css. Plain CSS, no preprocessor. */

/* ---------- Skip link (keyboard users reach the content in one tab) ---- */
.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  z-index: var(--z-toast);
  background: var(--surface);
  color: var(--text);
  padding: var(--space-3) var(--space-4);
  border-radius: 0 0 var(--radius-md) 0;
  box-shadow: var(--shadow-md);
}
.skip-link:focus { inset-inline-start: 0; }

/* ---------- Flash messages ---------- */
.flash {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  font-size: var(--fs-sm);
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: rgba(26, 127, 78, 0.2); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(198, 47, 67, 0.2); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(146, 96, 10, 0.2); }
.flash-info { background: var(--info-bg); color: var(--info); border-color: rgba(47, 111, 237, 0.2); }
.warn-msg { background: var(--warning-bg); color: var(--warning); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); font-size: var(--fs-sm); }

/* ---------- Page header ---------- */
.page-header { margin-bottom: var(--space-4); }
.page-title-row { display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.page-title-row h1 { margin-bottom: var(--space-2); }
.back-link { margin: 0 0 var(--space-3); }
.back-link a { display: inline-flex; align-items: center; gap: 0.25rem; font-size: var(--fs-sm); }
.narrow { max-width: 640px; }
.mt { margin-top: var(--space-4); }
.indent { margin-inline-start: var(--space-5); margin-bottom: var(--space-3); }

.fact-list { margin: var(--space-3) 0; padding-inline-start: 1.1rem; color: var(--text-muted); font-size: var(--fs-sm); }
.fact-list li { margin-bottom: 0.35rem; }

.form-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-4); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); }
.field-inline { display: flex; align-items: center; gap: var(--space-2); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.inline-form .field { margin-bottom: 0; flex: 1 1 180px; min-width: 0; }
.inline-form .btn { flex: 0 0 auto; }
.stacked { display: flex; gap: var(--space-2); align-items: flex-start; margin-bottom: var(--space-2); }
.stacked .input, .stacked .textarea { flex: 1 1 auto; min-width: 0; }
.color-input { padding: 0.2rem; height: var(--tap-min); }

a.card-link { display: block; color: inherit; }
a.card-link:hover { text-decoration: none; border-color: var(--border-strong); }
.inbox-card { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* ---------- Topics ---------- */
.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-card { padding: var(--space-3) var(--space-4); }
.topic-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-height: var(--tap-min); }
.topic-row-spacer { flex: 1 1 auto; }
.topic-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.topic-name { font-weight: 600; color: var(--text); }
.topic-name:hover { color: var(--accent); }
.subtopic-list { list-style: none; margin: var(--space-2) 0 0; padding-inline-start: var(--space-5); border-inline-start: 2px solid var(--border); }
.subtopic-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-height: 40px; }
.hidden-topics summary { cursor: pointer; font-weight: 600; }

/* ---------- Tags / collections / sources grids ---------- */
.tag-grid, .collection-grid, .source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}
.tag-card, .collection-card, .source-card { margin-bottom: 0; }
.source-card { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ---------- Badges added in V2 ---------- */
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-muted { background: var(--surface-2); color: var(--text-faint); }
.badge-unread { background: var(--info-bg); color: var(--info); font-weight: 600; }
.badge-importance { background: var(--warning-bg); color: var(--warning); font-weight: 600; }
.badge-tag { background: var(--accent-tint); color: var(--accent); }
.badge-topic { border: 1px solid var(--border-strong); background: var(--surface); }
.badge-media { background: var(--surface-2); color: var(--text-muted); }
.badge-note { background: var(--accent-tint); color: var(--accent); }
.badge-tag:hover, .badge-topic:hover, .badge-media:hover { text-decoration: none; border-color: var(--accent); }

.chip-removable { cursor: pointer; border: none; }
.chip-saved { background: var(--surface-2); color: var(--text); }
.chip-saved a { color: inherit; }
.saved-views { margin-top: calc(var(--space-2) * -1); }
.tab-count {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin-inline-start: 0.4rem;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 0 0.4rem;
}
.view-tabs a[aria-current="page"] .tab-count { background: rgba(255, 255, 255, 0.25); color: inherit; }

/*
 * The per-record controls are dropdowns inside a card that is only about a
 * third of the content width on a wide screen. At default control size three
 * of them stack into three lines and the card turns into a form. Shrinking
 * them to the card's own scale keeps the record itself the thing you read
 * first.
 */
.item-card .actions-row select {
  font-size: var(--fs-xs);
  padding: 0.2rem 1.3rem 0.2rem 0.4rem;
  min-height: 30px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}
.item-card .actions-row select:hover { border-color: var(--border-strong); color: var(--text); }
.item-card .actions-row { gap: var(--space-2) var(--space-3); }

/* ---------- Item card additions ---------- */
.item-card.is-read .title { color: var(--text-muted); }
.item-card.is-note { border-inline-start: 3px solid var(--accent); }
.library-list-row.is-read .title { color: var(--text-muted); }
tr.is-read td .title { color: var(--text-muted); }

/*
 * `?highlight=<id>` after a share: the record the user just saved is marked
 * so they can find it in a long list. The mark fades on its own because a
 * permanent outline would read as a state the record is in, which it is not.
 * `prefers-reduced-motion` keeps the outline and drops the animation, so the
 * record is still findable without anything moving.
 */
.item-card.is-highlighted,
.library-list-row.is-highlighted {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-md);
  animation: sf-highlight-fade 4s ease-out forwards;
}
tr.is-highlighted > td {
  background: var(--surface-2);
  box-shadow: inset 0 2px 0 var(--accent), inset 0 -2px 0 var(--accent);
  animation: sf-highlight-fade 4s ease-out forwards;
}
@keyframes sf-highlight-fade {
  0%, 60% { opacity: 1; }
  100% { outline-color: transparent; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  .item-card.is-highlighted,
  .library-list-row.is-highlighted,
  tr.is-highlighted > td { animation: none; }
}
.note-line {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: var(--space-2) 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.item-extra { margin-top: var(--space-2); }
.item-extra summary { cursor: pointer; font-size: var(--fs-sm); color: var(--text-muted); min-height: 32px; }
.tag-remove-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }
.empty-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin: var(--space-5) 0; font-size: var(--fs-sm);
}
.pagination a, .pagination strong { min-width: 32px; text-align: center; }

/* ---------- Tasks ---------- */
.task-list { list-style: none; margin: 0; padding: 0; }
.task-card { display: flex; align-items: flex-start; gap: var(--space-3); }
.task-card.completed .task-title { text-decoration: line-through; color: var(--text-muted); }
.task-card.overdue { border-inline-start: 3px solid var(--danger); }
.task-check { flex: 0 0 auto; }
.check-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  color: var(--text-faint); cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center;
}
.check-btn:hover { border-color: var(--success); color: var(--success); }
.task-card.completed .check-btn { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.task-body { flex: 1 1 auto; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-card .meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; font-size: var(--fs-xs); color: var(--text-muted); margin-top: 0.25rem; }
.task-card .due { color: var(--text-muted); }
.lists-section summary { cursor: pointer; font-weight: 600; }

/* ---------- Media ---------- */
.media-summary { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.media-card { margin-bottom: 0; }
.media-card-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.media-position { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-muted); }

/* ---------- Settings ---------- */
.status-list { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-3) 0; }
.status-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; font-size: var(--fs-sm); }
.status-row > span:first-child { color: var(--text-muted); min-width: 150px; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); margin: var(--space-3) 0; }
.usage-item { display: flex; flex-direction: column; gap: 0.15rem; background: var(--surface-2); padding: var(--space-3); border-radius: var(--radius-sm); }
.usage-item strong { font-size: var(--fs-lg); }
.plan-card.is-current { border-color: var(--accent); }

.token-box, .pairing-code-box {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.token-value { display: block; overflow-wrap: anywhere; font-size: var(--fs-sm); margin-bottom: var(--space-2); }
.pairing-code {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--fs-xl);
  letter-spacing: 0.15em;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.password-wrap { display: flex; gap: var(--space-2); align-items: stretch; }
.password-wrap .input { flex: 1 1 auto; min-width: 0; }
.password-toggle { flex: 0 0 auto; }

.share-pending { font-size: var(--fs-sm); }
.share-result { text-align: center; }
.share-check {
  width: 56px; height: 56px; margin: 0 auto var(--space-4);
  border-radius: 50%; background: var(--success-bg); color: var(--success);
  display: flex; align-items: center; justify-content: center;
}
.share-check .icon-svg { width: 28px; height: 28px; }

/* ---------- Admin ---------- */
.admin-status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.status-card { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0; }
.status-card strong { font-size: var(--fs-2xl); line-height: 1.1; }
.status-card.is-warn { border-color: var(--warning); background: var(--warning-bg); }
.error-event { font-size: var(--fs-sm); }
.code-block {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  overflow-x: auto;
  font-size: var(--fs-xs);
  white-space: pre;
  max-height: 320px;
}

/* ---------- Error pages ---------- */
.error-page { max-width: 520px; margin: var(--space-7) auto; text-align: center; }
.support-code {
  display: inline-flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  justify-content: center;
  background: var(--surface-2); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); font-size: var(--fs-sm);
}

/* ---------- Bulk bar as a form ---------- */
.bulk-bar { flex-wrap: wrap; }

/*
 * A horizontally scrolling table needs to be a containing block, not just an
 * overflow container. Without `position: relative`, the absolutely positioned
 * `.sr-only` labels inside its cells resolve against the page instead of
 * against the wrapper, escape the clip, and widen the whole document — which
 * is how a table that scrolls correctly still made the page scroll sideways
 * on a phone.
 */
.table-wrap { position: relative; }

@media (max-width: 767px) {
  .status-row > span:first-child { min-width: 0; flex: 1 1 100%; }
  .inline-form { flex-direction: column; align-items: stretch; }
  /* In a column, `flex: 1 1 180px` becomes a 180px *height* — which is what
     left large empty gaps between the fields of a stacked form. */
  .inline-form .field { flex: 0 0 auto; }
  .inline-form .btn { width: 100%; }
  /* Same reason as .library-grid: a bare 1fr takes its minimum from the
     content, and one unbreakable field then widens the whole row. */
  .field-row { grid-template-columns: minmax(0, 1fr); }
}

/* --- Administrator area ---------------------------------------------------
 *
 * Deliberately its own chrome. The administrator area shares no navigation
 * with the customer interface, so there is no link here that leads into
 * somebody's library and no customer control that could turn up on a
 * management screen by accident.
 */
.admin-body .app-shell-v2.admin-shell { display: block; }

/*
 * The topbar wraps rather than pushing its own controls off the edge.
 *
 * `.app-topbar` is a fixed-height, non-wrapping flex row, which is right for
 * the customer chrome (a brand, a search field, three icons). The admin bar
 * carries four text links and a sign-out button, and those are words -- so
 * their width depends on the language. In Brazilian Portuguese at 390px the
 * sign-out button was pushed 42px past the viewport, where
 * `body { overflow-x: hidden }` clipped it rather than showing a scrollbar.
 * That is the same failure shape as the mobile Archive card, found the same
 * way, and the fix is the same in spirit: let the layout give, instead of
 * assuming the content fits.
 */
.admin-topbar {
  border-bottom: 2px solid var(--border-strong);
  flex-wrap: wrap;
  height: auto;
  min-height: var(--topbar-h);
  padding-block: var(--space-2);
  row-gap: var(--space-2);
}
.admin-nav { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: center; min-width: 0; }
.admin-nav a { color: var(--text-muted); text-decoration: none; padding: var(--space-1) 0; }
.admin-nav a:hover, .admin-nav a:focus-visible { color: var(--text); text-decoration: underline; }
.admin-whoami { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-shell .content { max-width: 1100px; margin-inline: auto; }
@media (max-width: 640px) {
  /* The spacer's only job is to push the actions to the right on a wide bar;
     once the bar wraps it would force a needless third line. */
  .admin-topbar .topbar-spacer { display: none; }
  .admin-topbar .topbar-actions { margin-inline-start: auto; }
  .admin-nav { gap: var(--space-3); font-size: 0.9rem; }
  .admin-whoami { display: none; }
}

/*
 * The reveal control sits beside its field, never under it.
 *
 * `.inline-form .btn { width: 100% }` below 640px is right for a form's submit
 * button and wrong for this one: a full-width toggle inside `.password-wrap`
 * pushed the row one pixel past the viewport on the Settings account screen,
 * in every language. One pixel is still an overflow, and `overflow-x: hidden`
 * turns it into silent clipping rather than a scrollbar.
 */
.inline-form .password-wrap .password-toggle,
.password-wrap .password-toggle {
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}
