.history-root {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  max-width: 960px;
  margin: 0 auto;
}

// ── Header ────────────────────────────────────────────────────────────────────

.history-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;

  .header-icon {
    font-size: 2rem;
    width: 2rem;
    height: 2rem;
    color: #558b2f;
  }

  .header-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    color: #1b5e20;
  }

  .mpob-badge {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .clear-btn {
    margin-left: auto;
  }
}

// ── Loading ───────────────────────────────────────────────────────────────────

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;

  .loading-label {
    font-size: 0.9rem;
    color: #546e7a;
  }
}

// ── Empty state ───────────────────────────────────────────────────────────────

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 3rem;
  color: #90a4ae;

  .empty-icon {
    font-size: 3rem;
    width: 3rem;
    height: 3rem;
  }

  .empty-label {
    font-size: 0.95rem;
    font-style: italic;
    margin: 0;
  }
}

// ── Batch card ────────────────────────────────────────────────────────────────

.batch-card {
  border: 1px solid #c8e6c9;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;

  &.expanded {
    border-color: #81c784;
  }
}

// ── Master row ────────────────────────────────────────────────────────────────

.batch-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f1f8e9;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;

  &:hover {
    background: #e8f5e9;
  }

  .chevron {
    color: #558b2f;
    transition: transform 0.2s;
    flex-shrink: 0;

    &.rotated {
      transform: rotate(90deg);
    }
  }

  .batch-meta {
    display: flex;
    flex-direction: column;
    min-width: 160px;

    .batch-timestamp {
      font-size: 0.85rem;
      font-weight: 500;
      color: #37474f;
    }

    .batch-id-label {
      font-size: 0.7rem;
      color: #90a4ae;
      font-family: monospace;
    }
  }

  .batch-stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    flex-wrap: wrap;
  }

  .stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.78rem;

    mat-icon {
      font-size: 0.9rem;
      width: 0.9rem;
      height: 0.9rem;
    }

    &.count {
      background: #e8f5e9;
      color: #2e7d32;
    }

    &.confidence {
      background: #e3f2fd;
      color: #1565c0;
    }
  }

  .mode-badge {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;

    &.remote {
      background: #e3f2fd;
      color: #1565c0;
      border: 1px solid #90caf9;
    }

    &.local {
      background: #f3e5f5;
      color: #6a1b9a;
      border: 1px solid #ce93d8;
    }

    &.n8n {
      background: #fff8e1;
      color: #e65100;
      border: 1px solid #ffcc02;
    }
  }

  .delete-btn {
    margin-left: auto;
    flex-shrink: 0;
  }
}

// ── Detail drawer ─────────────────────────────────────────────────────────────

.batch-detail {
  padding: 1rem;
  border-top: 1px solid #c8e6c9;
  background: #fafafa;
}

// ── Thumbnail grid ────────────────────────────────────────────────────────────

.thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.thumb-card {
  position: relative;
  width: 160px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
  background: #f5f5f5;

  .historical-frame-canvas {
    width: 100%;
    height: 120px;
    display: block;
    object-fit: cover;
  }

  .thumb-placeholder {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eeeeee;
  }

  .thumb-metrics {
    display: flex;
    justify-content: space-between;
    padding: 3px 6px;
    background: rgba(0, 0, 0, 0.6);
    font-size: 0.7rem;
    color: #fff;
  }

  .item-delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 24px;
    height: 24px;
    line-height: 24px;

    mat-icon {
      font-size: 1rem;
      width: 1rem;
      height: 1rem;
    }
  }
}
