@layer components {
/* Record table page — fixed header, scrollable body */
.record-table {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 8rem);
  background: var(--color-canvas);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.record-table__header {
  background: color-mix(in srgb, var(--color-ink-lightest) 50%, var(--color-canvas));
  padding: 0.6em var(--inline-space);
  border-block-end: var(--border);
  flex-shrink: 0;

  h5 {
    font-size: var(--text-small);
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--color-ink-dark);
  }
}

.record-table__body turbo-frame {
  display: contents;
}

.record-table__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;

  .table td {
    border-block-end: 1px solid color-mix(in srgb, var(--color-ink-lighter) 50%, transparent);
    padding-block: 0.6em;
    vertical-align: middle;
  }

  .table tr:last-child td {
    border-block-end: none;
  }

  .table tr:hover td {
    background: color-mix(in srgb, var(--color-link) 3%, var(--color-canvas));
  }
}

/* Cell components */

.cell-primary {
  min-width: 200px;

  > a:first-child {
    color: var(--color-ink);
    text-decoration: none;
    font-weight: 500;

    &:hover {
      text-decoration: underline;
    }
  }

  .cell-subtitle {
    color: var(--color-ink-medium);
    font-size: var(--text-x-small);
    margin-top: 0.125rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
  }
}

.cell-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 3px;
  font-size: var(--text-x-small);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

a.cell-tag:hover {
  filter: brightness(0.95);
  text-decoration: none;
}

.cell-date {
  color: var(--color-ink-medium);
  font-size: var(--text-x-small);
  white-space: nowrap;
  width: 8rem;
}

.cell-source {
  font-size: var(--text-x-small);
  white-space: nowrap;
  width: 2rem;

  a {
    color: var(--color-ink-medium);
    text-decoration: none;

    &:hover {
      color: var(--color-ink);
    }
  }
}

.cell-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.125rem 0.375rem;
  border-radius: 10px;
  font-size: var(--text-x-small);
  font-weight: 500;
}

.cell-property {
  font-size: var(--text-x-small);
  color: var(--color-ink);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-separator::before {
  content: "·";
  margin-inline-end: 0.25em;
}

.cell-debug {
  font-size: 0.6875rem;
  line-height: 1.2;
}

/* Notion solid color palette (OKLCH tokens) */
.solid-gray    { background: oklch(var(--lch-ink-lighter));     color: oklch(var(--lch-ink-darkest)); }
.solid-brown   { background: oklch(var(--lch-brown-lighter));   color: oklch(var(--lch-brown-darker)); }
.solid-orange  { background: oklch(var(--lch-yellow-lightest)); color: oklch(var(--lch-yellow-darkest)); }
.solid-yellow  { background: oklch(var(--lch-yellow-lighter));  color: oklch(var(--lch-yellow-darker)); }
.solid-green   { background: oklch(var(--lch-green-lighter));   color: oklch(var(--lch-green-darkest)); }
.solid-blue    { background: oklch(var(--lch-blue-lighter));    color: oklch(var(--lch-blue-darkest)); }
.solid-purple  { background: oklch(var(--lch-purple-lighter));  color: oklch(var(--lch-purple-darker)); }
.solid-pink    { background: oklch(var(--lch-pink-lighter));    color: oklch(var(--lch-pink-darker)); }
.solid-red     { background: oklch(var(--lch-red-lighter));     color: oklch(var(--lch-red-darkest)); }

/* Field tags */
.field-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.field-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.0625rem 0.375rem;
  border-radius: 3px;
  font-size: 0.6875rem;
  background: var(--color-ink-lightest);
  color: var(--color-ink-medium);
}

/* Row action buttons */
.row-actions {
  display: flex;
  gap: 0.25rem;
  white-space: nowrap;
  justify-content: flex-end;

  form {
    display: inline;
  }

  .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.25rem;
    border: none;
    background: transparent;
    color: var(--color-ink-medium);
    cursor: pointer;
    padding: 0;
    font-size: 0.875rem;

    &:hover {
      background: var(--color-ink-lightest);
      color: var(--color-ink);
    }
  }

  .btn-icon--danger:hover {
    background: oklch(var(--lch-red-lightest));
    color: var(--color-negative);
  }
}

/* Inline edit inputs — borderless, match display typography */
.inline-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--color-ink);
  padding: 0.15em 0;

  &:focus { outline: none; }
  &::placeholder { color: var(--color-ink-medium); }
}

.inline-input--title {
  font-size: var(--text-small);
  font-weight: 500;
}

.inline-input--description {
  font-size: var(--text-x-small);
  color: var(--color-ink-dark);
  resize: none;

  @supports (field-sizing: content) {
    field-sizing: content;
    min-height: 1lh;
  }
}

.inline-input--meta {
  width: auto;
  font-size: var(--text-x-small);
  color: var(--color-ink-medium);
  padding: 0;
  cursor: pointer;

  &:focus { color: var(--color-ink); }
}

/* When detail is open, dim the table rows below */
turbo-frame#record_detail:not(:empty) ~ .table {
  opacity: 0.2;
  pointer-events: none;
}

.row-clickable {
  cursor: pointer;
  position: relative;

  .cell-primary > a:first-child::after {
    content: "";
    position: absolute;
    inset: 0;
  }
}

.row-editing {
  display: none;
}

.row-updated td {
  animation: row-highlight 2s ease-out;
}

@keyframes row-highlight {
  0%, 30% { background-color: oklch(var(--lch-yellow-lighter)); }
  100% { background-color: inherit; }
}

/* Inline form — appears above the table body */
.inline-form {
  padding: var(--inline-space);
  background: var(--color-selected-light);
  border-inline-start: 3px solid var(--color-link);
  box-shadow: 0 4px 12px oklch(var(--lch-black) / 8%);
  position: relative;
  z-index: 1;
}

.inline-form__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  margin-top: 0.25rem;
}


/* Detail page — shared by memory show, reminder edit, etc. */
.detail-page {
  max-width: 720px;
  padding-block: var(--block-space);
}

.detail-page__nav {
  margin-block-end: var(--block-space-half);
}

.detail-page__footer {
  font-size: var(--text-x-small);
  color: var(--color-ink-medium);
  padding-top: var(--block-space);
  margin-top: var(--block-space);
  border-top: 1px solid color-mix(in srgb, var(--color-ink) 6%, transparent);
}

/* Mobile: detail page */
@media (max-width: 639px) {
  .detail-page__footer .flex {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;

    > :last-child {
      align-self: flex-end;
    }
  }
}

/* Mobile: responsive record table */
@media (max-width: 639px) {
  .cell-files {
    width: 28px;
    padding-inline: 2px;
  }

  .cell-primary {
    max-width: 60vw;
    min-width: 0;
    overflow: hidden;

    a {
      display: block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .cell-subtitle {
      max-width: 100%;
    }
  }

  .cell-date,
  .cell-source {
    display: none;
  }

  .table .row-actions {
    display: none;
  }

  .inline-form .flex.align-center {
    flex-wrap: wrap;
  }

  .inline-form .row-actions {
    margin-inline-start: auto;
  }
}
}
