/*
 * Conceptual Continuity application styles.
 *
 * Semantic tokens layered over Open Props: components reference ONLY the
 * semantic layer (--surface-*, --text-*, --brand, --border, --danger) so
 * theming is one block per theme. Raw Open Props values appear only here.
 */

:root {
  /* semantic light theme */
  --surface-1: var(--gray-0);
  --surface-2: var(--gray-1);
  --surface-3: var(--gray-3);
  --text-1: var(--gray-9);
  --text-2: var(--gray-7);
  --brand: var(--purple-7);
  --border: var(--gray-4);
  --danger: var(--red-7);
  --ok: var(--green-7);

  --tap-target: 2.75rem; /* 44px minimum touch target */
}

[data-theme="dark"] {
  --surface-1: var(--gray-9);
  --surface-2: var(--gray-8);
  --surface-3: var(--gray-7);
  --text-1: var(--gray-0);
  --text-2: var(--gray-4);
  --brand: var(--purple-4);
  --border: var(--gray-6);
  --danger: var(--red-4);
  --ok: var(--green-4);
}

/* "auto" follows the OS preference; must duplicate the dark block. */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --surface-1: var(--gray-9);
    --surface-2: var(--gray-8);
    --surface-3: var(--gray-7);
    --text-1: var(--gray-0);
    --text-2: var(--gray-4);
    --brand: var(--purple-4);
    --border: var(--gray-6);
    --danger: var(--red-4);
    --ok: var(--green-4);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-1);
  color: var(--text-1);
  min-height: 100dvh;
}

main {
  padding: var(--size-3);
  max-width: 70rem;
  margin-inline: auto;
}

/*
 * Base controls: every button, input, select and textarea gets the same
 * tap-friendly, themed treatment so nothing falls through to browser
 * defaults (QE review 01, group B). Component rules below only add to this.
 * Font size never drops below 1rem so mobile browsers do not zoom on focus.
 */

button,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  min-height: var(--tap-target);
  padding-inline: var(--size-2);
  font-family: inherit;
  font-size: max(1rem, var(--font-size-1));
  color: var(--text-1);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

textarea {
  padding-block: var(--size-2);
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  margin: 0;
  accent-color: var(--brand);
}

button {
  cursor: pointer;
  font-weight: var(--font-weight-6);
  background: var(--surface-2);
}

button:hover {
  background: var(--surface-3);
}

:is(button, input, select, textarea):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* Primary action on stand-alone form pages (barcode, discogs import). */
.form-page form button[type="submit"]:not(.ghost-button):not(.danger-button) {
  color: var(--gray-0);
  background: var(--brand);
  border-color: transparent;
}

/* Top bar */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--size-2);
  padding: var(--size-2) var(--size-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-weight: var(--font-weight-7);
  color: var(--brand);
}

.topnav {
  display: flex;
  gap: var(--size-2);
  margin-inline-end: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  padding-inline: var(--size-2);
  color: var(--text-2);
  text-decoration: none;
  border-radius: var(--radius-2);
}

.nav-link.active {
  color: var(--text-1);
  background: var(--surface-3);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--size-1);
}

/* Secondary action; used on both <button> and <a> so links must not look like text. */
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  padding-inline: var(--size-2);
  font-size: max(1rem, var(--font-size-1));
  font-weight: var(--font-weight-6);
  color: var(--text-2);
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  cursor: pointer;
}

.ghost-button:hover {
  color: var(--text-1);
  background: var(--surface-2);
}

/* Collection list */

.empty-state {
  padding: var(--size-5);
  text-align: center;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-3);
}

.item-list {
  display: grid;
  gap: var(--size-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.item-row {
  padding: var(--size-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
}

.item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--size-2);
}

.item-title {
  font-weight: var(--font-weight-7);
  font-size: var(--font-size-3);
  color: inherit;
}

.item-title:hover {
  text-decoration: underline;
}

.item-detail h1 a {
  color: inherit;
  text-decoration: none;
}

.item-detail h1 a:hover {
  text-decoration: underline;
}

.item-artist {
  color: var(--text-2);
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
  margin-block: var(--size-2);
  font-size: var(--font-size-0);
  color: var(--text-2);
}

.tag {
  padding: 0 var(--size-2);
  color: var(--text-1);
  background: var(--surface-3);
  border-radius: var(--radius-round);
}

.item-notes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--size-2);
}

.notes-text {
  margin: 0;
  white-space: pre-wrap;
}

.muted {
  color: var(--text-2);
}

.notes-form {
  display: grid;
  gap: var(--size-2);
  width: 100%;
}

.notes-form textarea {
  width: 100%;
  padding: var(--size-2);
  font-family: inherit;
  font-size: var(--font-size-1);
  color: var(--text-1);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  resize: vertical;
}

.notes-actions {
  display: flex;
  gap: var(--size-2);
}

.notes-actions button[type="submit"] {
  min-height: var(--tap-target);
  padding-inline: var(--size-4);
  font-weight: var(--font-weight-6);
  color: var(--gray-0);
  background: var(--brand);
  border: none;
  border-radius: var(--radius-2);
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Desktop breakpoint */

@media (min-width: 48rem) {
  .topbar {
    padding-inline: var(--size-5);
  }
}

/* Login page */

.login-page {
  max-width: 22rem;
  margin-top: var(--size-10);
  text-align: center;
}

.login-form {
  display: grid;
  gap: var(--size-2);
  text-align: left;
}

.login-form input {
  min-height: var(--tap-target);
  padding-inline: var(--size-2);
  font-size: var(--font-size-2);
  color: var(--text-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

.login-form button {
  min-height: var(--tap-target);
  font-size: var(--font-size-2);
  font-weight: var(--font-weight-6);
  color: var(--gray-0);
  background: var(--brand);
  border: none;
  border-radius: var(--radius-2);
  cursor: pointer;
}

.form-error {
  color: var(--danger);
}

/* CRUD pages: lists, detail views, forms, row editors */

.list-header {
  display: flex;
  gap: var(--size-3);
  align-items: center;
  justify-content: space-between;
  margin-block-end: var(--size-3);
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  padding-inline: var(--size-3);
  font-weight: var(--font-weight-6);
  color: var(--gray-0);
  text-decoration: none;
  background: var(--brand);
  border-radius: var(--radius-2);
}

.line-list {
  display: grid;
  gap: var(--size-2);
  padding: 0;
  list-style: none;
}

.line-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
  align-items: baseline;
  padding: var(--size-2) var(--size-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

.line-title {
  font-weight: var(--font-weight-6);
  color: var(--text-1);
}

.line-sub,
.line-extra {
  font-size: var(--font-size-0);
  color: var(--text-2);
}

.line-extra {
  margin-inline-start: auto;
}

.line-flag {
  white-space: nowrap;
}

.drafts-banner {
  margin-block: var(--size-2) var(--size-3);
  color: var(--text-2);
}

.detail-sub {
  color: var(--text-2);
}

.collection-count {
  margin-block: var(--size-2);
  font-size: var(--font-size-1);
}

.def-list {
  display: grid;
  gap: var(--size-1);
  margin-block: var(--size-3);
}

.def-row {
  display: flex;
  gap: var(--size-2);
}

.def-row dt {
  min-width: 7rem;
  font-weight: var(--font-weight-6);
  color: var(--text-2);
}

.def-row dd {
  margin: 0;
}

.detail-actions,
.editor-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
  margin-block: var(--size-4);
}

.inline-form {
  display: inline-flex;
  gap: var(--size-2);
  align-items: center;
}

.danger-button {
  min-height: var(--tap-target);
  padding-inline: var(--size-3);
  font-weight: var(--font-weight-6);
  color: var(--gray-0);
  cursor: pointer;
  background: var(--danger);
  border: none;
  border-radius: var(--radius-2);
}

.badge {
  padding: var(--size-1) var(--size-2);
  font-size: var(--font-size-0);
  color: var(--gray-0);
  vertical-align: middle;
  background: var(--ok);
  border-radius: var(--radius-round);
}

.form-page {
  max-width: 40rem;
}

.form-page form {
  display: grid;
  gap: var(--size-3);
}

.field {
  display: grid;
  gap: var(--size-1);
}

.field label {
  font-weight: var(--font-weight-6);
  color: var(--text-2);
}

.field input:not([type="checkbox"]),
.field select,
.field textarea {
  width: 100%;
}

.field-label {
  font-weight: var(--font-weight-6);
  color: var(--text-2);
}

.field-static {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-3);
  margin: 0;
}

.field-hint {
  font-size: var(--font-size-0);
  color: var(--text-2);
}

.field-checkbox label {
  display: flex;
  gap: var(--size-2);
  align-items: center;
}

/* Single-format shortcut on the release form and the add-item panel:
   format + quantity share a row; details take the full width below. */
.format-fields {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--size-3);
}

.format-fields .format-qty input {
  width: 6rem;
}

.format-fields .field:last-child,
.format-fields .field:first-child:nth-last-child(2) {
  /* Details always span; so does the select when there is no Quantity. */
  grid-column: 1 / -1;
}

.inline-create {
  display: grid;
  gap: var(--size-3);
  padding: var(--size-3);
  border: 1px dashed var(--border);
  border-radius: var(--radius-2);
}

.inline-create legend {
  padding-inline: var(--size-2);
  font-weight: var(--font-weight-6);
  color: var(--text-2);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
  align-items: center;
}

.form-actions button[type="submit"],
.form-actions button:not(.ghost-button) {
  min-height: var(--tap-target);
  padding-inline: var(--size-4);
  font-weight: var(--font-weight-6);
  color: var(--gray-0);
  cursor: pointer;
  background: var(--brand);
  border: none;
  border-radius: var(--radius-2);
}

.row-editor {
  width: 100%;
  border-collapse: collapse;
}

.row-editor th {
  padding: var(--size-1);
  font-size: var(--font-size-0);
  color: var(--text-2);
  text-align: left;
}

.row-editor td {
  padding: var(--size-1);
}

.row-editor input[type="text"] {
  width: 100%;
}

.row-ops {
  white-space: nowrap;
}

.row-ops button {
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  color: var(--text-1);
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

.track-table {
  width: 100%;
  border-collapse: collapse;
}

.track-table td {
  padding: var(--size-1) var(--size-2);
  border-block-end: 1px solid var(--border);
}

.track-pos {
  width: 4rem;
  color: var(--text-2);
}

.track-dur {
  width: 5rem;
  text-align: right;
  color: var(--text-2);
}

.credit-list,
.url-list {
  padding-inline-start: var(--size-5);
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
}

.tag.removable {
  display: inline-flex;
  gap: var(--size-1);
  align-items: center;
}

.tag.removable button {
  min-height: 0;
  padding: 0 var(--size-1);
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
}

.profile {
  white-space: pre-wrap;
}

.checklist-progress {
  color: var(--text-2);
  font-size: var(--font-size-0);
}

.checklist th {
  text-align: left;
}

.checklist th.checklist-num,
.checklist-num {
  color: var(--text-2);
  text-align: right;
  white-space: nowrap;
}

.checklist-meta {
  display: flex;
  gap: var(--size-2);
  color: var(--text-2);
  font-size: var(--font-size-0);
}

.checklist-source {
  color: var(--text-2);
  font-size: var(--font-size-0);
}

.checklist-missing {
  color: var(--text-2);
  font-size: var(--font-size-0);
  font-style: italic;
}

/* Covered = owned only inside a compilation/box set: same shape as the owned
   badge, outlined instead of filled so the two read as related but distinct. */
.badge-covered {
  color: var(--ok);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--ok);
}

/* "via <compilation>" sits on its own line under the badge and button. */
.checklist-covered-by {
  display: block;
  margin-block-start: var(--size-1);
}

.checklist-own {
  white-space: nowrap;
}

.checklist tr:not(.owned):not(.covered) td {
  color: var(--text-2);
}

.topbar-search input {
  max-width: 10rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2);
  align-items: end;
  padding: var(--size-2);
  margin-block-end: var(--size-3);
  font-size: var(--font-size-0);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: var(--size-1);
}

.toolbar-check {
  flex-direction: row !important;
  align-items: center;
}

.item-group {
  margin-block-end: var(--size-4);
}

.item-group-title {
  margin-block-end: var(--size-2);
  font-size: var(--font-size-2);
}

.search-form {
  display: flex;
  gap: var(--size-2);
  margin-block-end: var(--size-3);
}

.search-form input[type='search'] {
  flex: 1;
}

.search-results {
  padding: 0;
  list-style: none;
}

.search-hit {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-1) var(--size-2);
  align-items: baseline;
  padding-block: var(--size-1);
  border-block-end: 1px solid var(--border);
}

/* Titles stay on one line; the format (QE round 2, F) takes a second line
   on phones rather than squeezing the title into a narrow column. */
.search-hit > a {
  flex: 0 1 auto;
}

.search-format {
  flex-basis: 100%;
}

@media (min-width: 48rem) {
  .search-format {
    flex-basis: auto;
  }
}

.search-detail {
  color: var(--text-2);
  font-size: var(--font-size-0);
}

.advanced-search {
  margin-block: var(--size-3);
}

.advanced-search summary {
  cursor: pointer;
}

.year-range div {
  display: flex;
  gap: var(--size-2);
}

.year-range input {
  max-width: 6rem;
}

/* Discogs tracklist import (release detail) */

.discogs-import-row {
  display: flex;
  gap: var(--size-2);
  margin-block-start: var(--size-1);
}

.discogs-import-row input {
  flex: 1;
  max-width: 28rem;
}

/* Barcode flow */

/* Discogs drafts on the release page (QE review 01, F). */
.discogs-find {
  align-items: center;
  margin-bottom: var(--size-3);
}

.draft-panel {
  border: 1px solid var(--brand);
  border-radius: var(--radius-2);
  padding: var(--size-3);
  margin-bottom: var(--size-4);
}

.draft-panel h3 {
  margin-top: 0;
}

.draft-panel h4 {
  margin: var(--size-2) 0;
  font-size: var(--font-size-1);
  color: var(--text-2);
}

.draft-intro {
  margin: 0 0 var(--size-2);
}

.draft-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--size-4);
  align-items: start;
}

.nav-badge {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.4em;
  margin-left: 0.25em;
  border-radius: 999px;
  background: var(--brand);
  color: var(--gray-0);
  font-size: var(--font-size-0);
  font-weight: 600;
  line-height: 1.5em;
  text-align: center;
  vertical-align: middle;
}

.barcode-hits {
  list-style: none;
  padding: 0;
  margin-block: var(--size-3);
}

.barcode-hit {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-2) var(--size-3);
  align-items: center;
  padding-block: var(--size-2);
  border-block-end: 1px solid var(--border);
}

/* On phones the action button drops under the text so the ownership badge
   and title keep the full width (QE round 2, D). */
@media (max-width: 47.99rem) {
  .barcode-hit > .inline-form {
    flex-basis: 100%;
  }
}

.barcode-thumb {
  inline-size: 3.5rem;
  block-size: 3.5rem;
  object-fit: cover;
  border-radius: var(--radius-2);
  background: var(--surface-2);
  flex-shrink: 0;
}

.barcode-hit-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-inline-size: 0;
}

.barcode-hit-title {
  font-weight: var(--font-weight-6);
}

/* "You own 2 copies" sits above the title: at the record store it is the
   answer, the title is the confirmation. */
.hit-badge {
  align-self: flex-start;
  margin-block-end: var(--size-1);
  text-decoration: none;
}

.barcode-hit-sub {
  color: var(--text-2);
  font-size: var(--font-size-0);
}

.barcode-none {
  margin-block-start: var(--size-3);
}

/*
 * Phone layout (QE review 01, group G). Below the desktop breakpoint the
 * top nav and search box hide, a fixed bottom tab bar takes over, the
 * collection toolbar collapses behind a toggle, and dense tables become
 * stacked cards. Nothing here may create horizontal overflow: the live
 * browser tests assert scrollWidth <= innerWidth at 390px.
 */

.bottom-nav,
.filters-toggle {
  display: none;
}

@media (max-width: 47.99rem) {
  .topbar {
    flex-wrap: nowrap;
    padding-block: var(--size-1);
  }

  .topbar-title {
    margin-inline-end: auto;
  }

  .topbar-search,
  .topnav {
    display: none;
  }

  /* Room for the fixed tab bar plus the phone's home indicator. */
  main {
    padding-block-end: calc(var(--tap-target) + var(--size-5) + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: var(--layer-3);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding-block-end: env(safe-area-inset-bottom);
    background: var(--surface-2);
    border-block-start: 1px solid var(--border);
  }

  .tab {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(var(--tap-target) + var(--size-1));
    font-size: var(--font-size-0);
    font-weight: var(--font-weight-6);
    color: var(--text-2);
    text-decoration: none;
    cursor: pointer;
    list-style: none;
  }

  .tab.active {
    color: var(--brand);
    box-shadow: inset 0 3px 0 var(--brand);
  }

  .more-menu {
    position: relative;
  }

  .more-menu summary::-webkit-details-marker {
    display: none;
  }

  .more-menu summary::marker {
    content: "";
  }

  .more-sheet {
    position: absolute;
    inset-block-end: 100%;
    inset-inline-end: 0;
    display: grid;
    min-width: 12rem;
    padding: var(--size-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-3) 0 0 0;
    box-shadow: var(--shadow-3);
  }

  .more-sheet .nav-link {
    min-height: var(--tap-target);
  }

  /* Collapsible collection toolbar. */
  .filters-toggle {
    display: flex;
    width: 100%;
    margin-block-end: var(--size-2);
  }

  .toolbar-wrap:not(.open) .toolbar {
    display: none;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar label {
    min-width: 0;
  }

  .toolbar select,
  .toolbar button,
  .toolbar .ghost-button {
    width: 100%;
  }

  .toolbar-check {
    grid-column: 1 / -1;
  }

  /* Headers, actions and definition rows stack instead of squeezing. */
  .list-header {
    flex-wrap: wrap;
  }

  .def-row {
    flex-direction: column;
    gap: 0;
  }

  .line-extra {
    margin-inline-start: 0;
  }

  .draft-compare {
    grid-template-columns: 1fr;
  }

  .discogs-find {
    flex-direction: column;
    align-items: stretch;
  }

  .discogs-import-row,
  .search-form {
    flex-wrap: wrap;
  }

  .form-actions > *,
  .detail-actions > *,
  .editor-links > * {
    flex: 1 1 40%;
    justify-content: center;
    text-align: center;
  }

  .inline-form {
    display: flex;
  }

  .inline-form > * {
    flex: 1 1 auto;
  }

  /* Official checklist: one card per release. */
  .checklist thead {
    display: none;
  }

  .checklist tr {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: var(--size-1) var(--size-2);
    align-items: baseline;
    padding-block: var(--size-2);
    border-block-end: 1px solid var(--border);
  }

  .checklist td {
    padding: 0;
    border: none;
  }

  /* Status (badge or missing + "I own this") wraps under the title. */
  .checklist td:last-child {
    grid-column: 3;
    display: flex;
    flex-wrap: wrap;
    gap: var(--size-2);
    align-items: center;
  }

  .checklist-covered-by {
    flex-basis: 100%;
    margin: 0;
  }

  .checklist-meta {
    flex-wrap: wrap;
  }

  /* Row editors: each row is a card with labelled cells. */
  .row-editor thead {
    display: none;
  }

  .row-editor tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--size-2);
    padding-block: var(--size-2);
    border-block-end: 1px solid var(--border);
  }

  .row-editor td {
    padding: 0;
  }

  .row-editor td[data-label]::before {
    display: block;
    font-size: var(--font-size-0);
    color: var(--text-2);
    content: attr(data-label);
  }

  .row-editor td.row-ops {
    display: flex;
    grid-column: 1 / -1;
    gap: var(--size-2);
  }

  .row-editor td.row-ops button {
    flex: 1;
  }

  /* Media never wider than the screen. */
  img {
    max-width: 100%;
  }
}
