.resources-page.stream-rebuild {
  --stream-columns: 4;
  --stream-grid-gap: 10px;
  --stream-card-width: 248px;
  --stream-card-height: 318px;
  --stream-visual-height: 210px;
  --stream-slot-width: calc(var(--stream-card-width) + var(--stream-grid-gap));
  --stream-slot-height: calc(var(--stream-card-height) + var(--stream-grid-gap));
  --stream-grid-width: calc(var(--stream-slot-width) * var(--stream-columns));
  height: calc(100% + 48px);
  margin: -24px;
  padding: 14px 16px;
  position: relative;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;

  .stream-toolbar {
    border: 1px solid color-mix(in srgb, var(--border-color) 78%, transparent);
    background: var(--card-bg, #f8f9fb);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
  }

  .toolbar-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    flex: 1;
  }

  .media-tabs {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 4px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-secondary) 85%, transparent);
    border: 1px solid var(--border-color);

    button {
      border: none;
      background: transparent;
      color: var(--text-secondary, #5f6674);
      border-radius: 6px;
      padding: 6px 12px;
      font-size: 13px;
      cursor: pointer;
      transition: background 0.15s ease, color 0.15s ease;

      &.active {
        background: color-mix(in srgb, var(--primary) 18%, var(--card-bg));
        color: var(--text-primary, #1c2230);
        box-shadow: none;
      }
    }
  }

  .filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;

    .filter-field {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      border: 1px solid color-mix(in srgb, var(--border-color, #d2d7df) 95%, transparent);
      background: var(--bg-secondary, #f3f5f8);
      color: var(--text-secondary, #566074);
      border-radius: 8px;
      padding: 0 10px;
      min-height: 34px;
      box-sizing: border-box;

      svg {
        color: var(--text-tertiary, #8a92a3);
        flex: 0 0 auto;
      }
    }

    .filter-select {
      min-width: 300px;
    }

    .filter-date {
      min-width: 160px;
    }

    input,
    select {
      border: none;
      outline: none;
      background: transparent;
      color: var(--text-primary, #1c2230);
      font-size: 13px;
      min-width: 0;
      height: 32px;
      line-height: 32px;
      font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
      appearance: none;
    }

    .contact-select {
      width: 100%;
      min-width: 220px;
      padding-right: 8px;
    }

    .date-input {
      width: 128px;
      min-width: 128px;
    }

    .sep {
      color: var(--text-tertiary);
      font-size: 12px;
    }

    .ghost {
      border: 1px solid var(--border-color);
      background: transparent;
      color: var(--text-secondary, #5f6674);
      border-radius: 8px;
      height: 34px;
      padding: 0 12px;
      cursor: pointer;
    }

    .reset-btn {
      border-color: color-mix(in srgb, var(--border-color, #d2d7df) 95%, transparent);
      background: var(--bg-secondary, #f3f5f8);
    }
  }

  .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;

    button {
      border: 1px solid var(--border-color);
      background: var(--bg-secondary, #f3f5f8);
      color: var(--text-secondary, #5f6674);
      border-radius: 8px;
      height: 32px;
      padding: 0 12px;
      font-size: 13px;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      cursor: pointer;

      &:disabled {
        opacity: 0.58;
        cursor: not-allowed;
      }

      &.danger {
        border-color: color-mix(in srgb, var(--danger) 45%, var(--border-color));
        color: var(--danger);
        background: color-mix(in srgb, var(--danger) 10%, var(--bg-secondary));
      }
    }
  }

  .stream-summary {
    display: flex;
    gap: 14px;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 0 4px;
    flex-wrap: wrap;
  }

  .stream-state {
    height: 104px;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    &.error {
      color: var(--danger);
      border-color: color-mix(in srgb, var(--danger) 45%, var(--border-color));
    }
  }

  .stream-grid-wrap {
    flex: 1;
    min-height: 0;
    border: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
    border-radius: 8px;
    background: color-mix(in srgb, var(--card-bg) 94%, transparent);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .stream-grid {
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow-anchor: none;
  }

  .stream-grid-list,
  .virtuoso-grid-list {
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    align-content: flex-start;
    padding: 8px 0 2px;
    width: var(--stream-grid-width);
    min-width: var(--stream-grid-width);
    max-width: var(--stream-grid-width);
    margin: 0 auto;
  }

  .stream-grid-item,
  .virtuoso-grid-item {
    box-sizing: border-box;
    width: var(--stream-slot-width);
    min-width: var(--stream-slot-width);
    max-width: var(--stream-slot-width);
    flex: 0 0 var(--stream-slot-width);
    height: var(--stream-slot-height);
    padding-right: var(--stream-grid-gap);
    padding-bottom: var(--stream-grid-gap);
    display: flex;
  }

  .stream-grid-item > *,
  .virtuoso-grid-item > * {
    width: 100%;
    height: 100%;
  }

  .media-card {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.16s ease;
    position: relative;
    display: flex;
    flex-direction: column;

    &:hover {
      border-color: color-mix(in srgb, var(--primary) 34%, var(--border-color));
    }

    &.selected {
      border-color: color-mix(in srgb, var(--primary) 56%, var(--border-color));
      outline: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
      outline-offset: -1px;
    }

    &.decrypting {
      .card-visual {
        opacity: 0.68;
      }
    }
  }

  .floating-info,
  .floating-delete {
    position: absolute;
    top: 10px;
    z-index: 4;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--danger) 48%, var(--border-color));
    color: var(--danger);
    background: color-mix(in srgb, var(--bg-secondary) 90%, transparent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: none;
    pointer-events: none;
    transition: opacity 0.15s ease;
  }

  .floating-info {
    right: 10px;
    border-color: color-mix(in srgb, var(--primary) 42%, var(--border-color));
    color: var(--text-primary);
  }

  .floating-delete {
    right: 44px;
  }

  .media-card:hover .floating-info,
  .media-card:focus-within .floating-info,
  .media-card:hover .floating-delete,
  .media-card:focus-within .floating-delete {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  .floating-update {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 4;
    border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border-color));
    background: color-mix(in srgb, var(--bg-secondary) 90%, transparent);
    color: var(--text-primary);
    border-radius: 6px;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;

    &:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }
  }

  .card-visual {
    width: 100%;
    height: var(--stream-visual-height);
    min-height: var(--stream-visual-height);
    max-height: var(--stream-visual-height);
    border: none;
    cursor: pointer;
    background: color-mix(in srgb, var(--bg-tertiary) 70%, transparent);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;

    &:disabled {
      cursor: not-allowed;
    }

    &.image img,
    &.video img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      object-position: center;
      display: block;
    }

    &.image img.long-image {
      object-fit: cover;
      object-position: top center;
    }

    .placeholder {
      width: 100%;
      min-height: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8px;
      color: var(--text-tertiary);
      padding: 12px;
      text-align: center;

      span {
        font-size: 12px;
        color: var(--text-secondary);
        max-width: 90%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    .decrypting-overlay {
      position: absolute;
      inset: 0;
      z-index: 3;
      display: flex;
      align-items: center;
      justify-content: center;
      pointer-events: none;
      background: rgba(255, 255, 255, 0.08);
      overflow: hidden;

      &::before {
        content: '';
        position: absolute;
        inset: -40%;
        background: none;
        animation: none;
        pointer-events: none;
      }
    }

    .decrypting-spinner {
      position: relative;
      z-index: 1;
      width: 30px;
      height: 30px;
      border-radius: 999px;
      border: 2px solid rgba(15, 23, 42, 0.2);
      border-top-color: color-mix(in srgb, var(--primary) 78%, #ffffff);
      animation: decrypt-spin 0.85s linear infinite;
      box-shadow: none;
    }
  }

  .card-meta {
    padding: 8px 10px;
    min-height: 58px;
    margin-top: auto;
    cursor: pointer;
    border-top: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
    transition: background-color 0.15s ease;

    &:hover {
      background: color-mix(in srgb, var(--bg-secondary) 68%, transparent);
    }
  }

  .title-row,
  .sub-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }

  .title-row {
    .session {
      color: var(--text-primary);
      font-size: 13px;
      font-weight: 600;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 62%;
    }
    .time {
      font-size: 11px;
      color: var(--text-tertiary);
      white-space: nowrap;
    }
  }

  .sub-row {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-tertiary);
  }

  .grid-loading-more,
  .grid-end {
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-tertiary);
  }

  .spin {
    animation: resources-spin 1s linear infinite;
  }

  .action-message {
    color: color-mix(in srgb, var(--primary) 75%, var(--text-secondary));
    font-weight: 600;
  }

  .resource-dialog-mask {
    position: absolute;
    inset: 0;
    background: rgba(8, 11, 18, 0.46);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
  }

  .resource-dialog {
    --dialog-surface: color-mix(in srgb, var(--bg-primary, #ffffff) 82%, var(--card-inner-bg, #ffffff) 18%);
    --dialog-surface-header: color-mix(in srgb, var(--dialog-surface) 90%, var(--bg-secondary, #ffffff) 10%);
    width: min(420px, calc(100% - 32px));
    background: var(--dialog-surface);
    border: 1px solid color-mix(in srgb, var(--border-color) 90%, transparent);
    border-radius: 10px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
  }

  .dialog-header {
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
    background: var(--dialog-surface-header);
  }

  .dialog-body {
    padding: 16px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.55;
    white-space: pre-wrap;
    background: var(--dialog-surface);
  }

  .dialog-info-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .dialog-info-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px;
    align-items: flex-start;
  }

  .info-label {
    color: var(--text-tertiary);
    font-size: 12px;
    line-height: 1.45;
  }

  .info-value {
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-all;
    white-space: pre-wrap;
    user-select: text;
  }

  .dialog-actions {
    padding: 0 14px 14px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    background: var(--dialog-surface);
  }

  .dialog-btn {
    min-width: 72px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 13px;
    cursor: pointer;

    &.ghost {
      background: var(--bg-secondary);
      color: var(--text-secondary);
    }

    &.solid {
      background: color-mix(in srgb, var(--primary) 16%, var(--bg-secondary));
      border-color: color-mix(in srgb, var(--primary) 45%, var(--border-color));
      color: var(--text-primary);
    }
  }
}

@media (max-width: 900px) {
  .resources-page.stream-rebuild {
    .stream-toolbar {
      flex-direction: column;
    }

    .toolbar-right {
      justify-content: flex-start;
    }

    .filters {
      .filter-select {
        min-width: 220px;
      }
    }
  }
}

@media (max-width: 680px) {
  .resources-page.stream-rebuild {
    --stream-grid-width: calc(var(--stream-slot-width) * var(--stream-columns));

    .stream-grid-list,
    .virtuoso-grid-list {
      margin: 0;
      padding-left: 0;
      padding-right: 0;
    }
  }
}

@keyframes resources-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes decrypt-sheen {
  from {
    transform: translateX(-45%);
  }
  to {
    transform: translateX(45%);
  }
}

@keyframes decrypt-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes decrypt-pulse {
  0%,
  100% {
    opacity: 0.92;
  }
  50% {
    opacity: 0.68;
  }
}
