/* ═══ Anchor HQ — Automations Section (The Workshop) ═══ */
/* Stardew Valley Workshop / Machinery Theme */

/* ── Keyframes ── */
@keyframes gearSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes gearSpinReverse {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}

@keyframes activePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108,191,74,0.12), inset 0 0 0 0 rgba(108,191,74,0.03); }
  50% { box-shadow: 0 0 12px 2px rgba(108,191,74,0.08), inset 0 0 12px 0 rgba(108,191,74,0.04); }
}

@keyframes statusBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes conveyorMove {
  0% { background-position: 0 0; }
  100% { background-position: 12px 0; }
}

@keyframes leverPull {
  0% { transform: translateY(0); }
  50% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

@keyframes steamPuff {
  0% { opacity: 0.4; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-8px) scale(1.5); }
}

/* ── Automations List ── */
.automations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Machine Cards — Pixel contraption panels ── */
.auto-card {
  background:
    linear-gradient(180deg, rgba(107,68,35,0.04) 0%, transparent 40%),
    var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 250ms;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  image-rendering: pixelated;
}

/* Riveted panel corners — top-left and top-right */
.auto-card::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 6px;
  width: 6px;
  height: 6px;
  background: radial-gradient(circle, rgba(180,160,120,0.4) 30%, transparent 70%);
  border-radius: 0;
  box-shadow:
    calc(100% - 12px) 0 0 0 rgba(0,0,0,0) /* placeholder for right rivet */;
  pointer-events: none;
}

.auto-card::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  background: radial-gradient(circle, rgba(180,160,120,0.4) 30%, transparent 70%);
  border-radius: 0;
  pointer-events: none;
}

.auto-card:hover {
  border-color: var(--border-accent);
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

/* ── Active Machine State — Glowing, alive ── */
.auto-card.machine-active {
  border-color: rgba(108,191,74,0.3);
  animation: activePulse 3s ease-in-out infinite;
}

.auto-card.machine-active:hover {
  border-color: rgba(108,191,74,0.5);
}

/* ── Paused Machine State — Dim, dormant ── */
.auto-card.machine-paused {
  opacity: 0.7;
  filter: saturate(0.6);
}

.auto-card.machine-paused:hover {
  opacity: 0.85;
  filter: saturate(0.8);
}

/* ── Failed Machine State — Red warning ── */
.auto-card.machine-failed {
  border-color: rgba(224,64,64,0.25);
}

/* ── Card Header ── */
.auto-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

/* ── Gear Icon for active cards ── */
.auto-card-header::before {
  content: '';
  position: absolute;
  right: -4px;
  top: -4px;
  width: 20px;
  height: 20px;
  opacity: 0;
  pointer-events: none;
  /* Pixel gear shape via box-shadow */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Crect x='8' y='0' width='4' height='4' fill='%236cbf4a' opacity='0.3'/%3E%3Crect x='8' y='16' width='4' height='4' fill='%236cbf4a' opacity='0.3'/%3E%3Crect x='0' y='8' width='4' height='4' fill='%236cbf4a' opacity='0.3'/%3E%3Crect x='16' y='8' width='4' height='4' fill='%236cbf4a' opacity='0.3'/%3E%3Crect x='6' y='6' width='8' height='8' rx='0' fill='%236cbf4a' opacity='0.2'/%3E%3Crect x='8' y='8' width='4' height='4' fill='%236cbf4a' opacity='0.1'/%3E%3C/svg%3E")
    center / contain no-repeat;
  image-rendering: pixelated;
}

.auto-card.machine-active .auto-card-header::before {
  opacity: 1;
  animation: gearSpin 4s linear infinite;
}

/* Second gear (smaller, counter-rotating) */
.auto-card-header::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 10px;
  width: 12px;
  height: 12px;
  opacity: 0;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Crect x='4' y='0' width='4' height='2' fill='%236cbf4a' opacity='0.25'/%3E%3Crect x='4' y='10' width='4' height='2' fill='%236cbf4a' opacity='0.25'/%3E%3Crect x='0' y='4' width='2' height='4' fill='%236cbf4a' opacity='0.25'/%3E%3Crect x='10' y='4' width='2' height='4' fill='%236cbf4a' opacity='0.25'/%3E%3Crect x='3' y='3' width='6' height='6' fill='%236cbf4a' opacity='0.15'/%3E%3C/svg%3E")
    center / contain no-repeat;
  image-rendering: pixelated;
}

.auto-card.machine-active .auto-card-header::after {
  opacity: 1;
  animation: gearSpinReverse 2.5s linear infinite;
}

/* ── Status Dots — Pixel-styled with animations ── */
.auto-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 0;
  flex-shrink: 0;
  image-rendering: pixelated;
  position: relative;
  border: 1px solid transparent;
}

.auto-status-dot.active {
  background: var(--green);
  box-shadow:
    0 0 0 2px rgba(108,191,74,0.15),
    0 0 6px rgba(108,191,74,0.3);
  animation: statusBlink 2s ease-in-out infinite;
  border-color: rgba(108,191,74,0.3);
}

/* Active dot pixel cross pattern */
.auto-status-dot.active::before {
  content: '';
  position: absolute;
  inset: 2px;
  background: rgba(255,255,255,0.3);
  image-rendering: pixelated;
}

.auto-status-dot.paused {
  background: var(--yellow);
  box-shadow: 0 0 0 2px rgba(240,192,64,0.15);
  opacity: 0.6;
  border-color: rgba(240,192,64,0.2);
}

.auto-status-dot.failed {
  background: var(--red);
  box-shadow:
    0 0 0 2px rgba(224,64,64,0.15),
    0 0 4px rgba(224,64,64,0.2);
  animation: statusBlink 1s ease-in-out infinite;
  border-color: rgba(224,64,64,0.3);
}

/* ── Machine Name ── */
.auto-name {
  font-weight: 700;
  font-size: .88rem;
  flex: 1;
}

/* ── Schedule Badge — Clock-styled pixel badge ── */
.auto-schedule {
  font-family: var(--font-pixel);
  font-size: .5rem;
  color: var(--gold);
  font-weight: 600;
  padding: 4px 10px 4px 24px;
  border-radius: 2px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Crect x='4' y='0' width='4' height='2' fill='%23daa520' opacity='0.6'/%3E%3Crect x='0' y='4' width='2' height='4' fill='%23daa520' opacity='0.6'/%3E%3Crect x='10' y='4' width='2' height='4' fill='%23daa520' opacity='0.6'/%3E%3Crect x='4' y='10' width='4' height='2' fill='%23daa520' opacity='0.6'/%3E%3Crect x='2' y='2' width='2' height='2' fill='%23daa520' opacity='0.4'/%3E%3Crect x='8' y='2' width='2' height='2' fill='%23daa520' opacity='0.4'/%3E%3Crect x='2' y='8' width='2' height='2' fill='%23daa520' opacity='0.4'/%3E%3Crect x='8' y='8' width='2' height='2' fill='%23daa520' opacity='0.4'/%3E%3Crect x='5' y='3' width='2' height='4' fill='%23daa520' opacity='0.8'/%3E%3Crect x='5' y='5' width='3' height='2' fill='%23daa520' opacity='0.8'/%3E%3C/svg%3E")
    8px center / 12px 12px no-repeat,
    var(--gold-soft, rgba(218,165,32,0.15));
  border: 1px solid var(--border-accent);
  image-rendering: pixelated;
  letter-spacing: .03em;
}

/* ── Description ── */
.auto-desc {
  font-size: .78rem;
  color: var(--muted);
  margin: 8px 0;
  line-height: 1.4;
  padding-left: 22px;
  position: relative;
}

/* Pipe connector from status dot area */
.auto-desc::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  bottom: 0;
  width: 2px;
  background:
    repeating-linear-gradient(
      180deg,
      var(--border) 0px,
      var(--border) 3px,
      transparent 3px,
      transparent 6px
    );
  opacity: 0.4;
}

/* ── Meta Information ── */
.auto-meta {
  display: flex;
  gap: 16px;
  font-size: .72rem;
  color: var(--muted);
  padding-left: 22px;
}

.auto-meta strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Action Buttons — Lever-switch styled ── */
.auto-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-left: 22px;
}

.auto-toggle-btn {
  padding: 6px 16px;
  border-radius: 2px;
  border: 2px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(0,0,0,0.04) 100%),
    transparent;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 200ms;
  position: relative;
  image-rendering: pixelated;
  text-transform: uppercase;
  letter-spacing: .02em;
}

/* Lever track on left side */
.auto-toggle-btn::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 3px;
  bottom: 3px;
  width: 3px;
  background: var(--border);
  border-radius: 0;
  transition: all 200ms;
}

/* Lever handle indicator */
.auto-toggle-btn::after {
  content: '';
  position: absolute;
  left: 3px;
  width: 5px;
  height: 5px;
  background: var(--muted);
  border-radius: 0;
  transition: all 200ms;
  image-rendering: pixelated;
}

.auto-toggle-btn:hover {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0.02) 100%),
    rgba(218,165,32,0.06);
  color: var(--text);
  animation: leverPull 300ms ease-out;
}

/* Pause lever — handle at top (active position) */
.auto-toggle-btn.pause {
  border-color: rgba(240,192,64,0.3);
  color: var(--yellow);
  padding-left: 20px;
}

.auto-toggle-btn.pause::before {
  background: rgba(240,192,64,0.3);
}

.auto-toggle-btn.pause::after {
  top: 3px;
  background: var(--yellow);
  box-shadow: 0 0 4px rgba(240,192,64,0.3);
}

.auto-toggle-btn.pause:hover {
  background: rgba(240,192,64,0.08);
  border-color: rgba(240,192,64,0.5);
  box-shadow: 0 1px 6px rgba(240,192,64,0.1);
}

/* Resume lever — handle at bottom (off position) */
.auto-toggle-btn.resume {
  border-color: rgba(108,191,74,0.3);
  color: var(--green);
  padding-left: 20px;
}

.auto-toggle-btn.resume::before {
  background: rgba(108,191,74,0.3);
}

.auto-toggle-btn.resume::after {
  bottom: 3px;
  top: auto;
  background: var(--green);
  box-shadow: 0 0 4px rgba(108,191,74,0.3);
}

.auto-toggle-btn.resume:hover {
  background: rgba(108,191,74,0.08);
  border-color: rgba(108,191,74,0.5);
  box-shadow: 0 1px 6px rgba(108,191,74,0.1);
}

/* ── Run History — Conveyor belt timeline ── */
.auto-history {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 2px solid var(--border);
  position: relative;
}

.auto-card.expanded .auto-history {
  display: block;
}

/* Conveyor belt track */
.auto-history::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 3px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(107,68,35,0.2) 0px,
      rgba(107,68,35,0.2) 4px,
      rgba(107,68,35,0.08) 4px,
      rgba(107,68,35,0.08) 8px,
      rgba(107,68,35,0.15) 8px,
      rgba(107,68,35,0.15) 12px
    );
  animation: conveyorMove 1s linear infinite;
  border-radius: 0;
  image-rendering: pixelated;
}

.auto-card.machine-paused .auto-history::before {
  animation-play-state: paused;
}

.auto-history-title {
  font-family: var(--font-pixel);
  font-size: .45rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding-top: 8px;
  position: relative;
  z-index: 1;
}

/* ── History Items — Gems on the conveyor ── */
.auto-history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: .72rem;
  position: relative;
}

/* Connecting pipe between history items */
.auto-history-item + .auto-history-item::before {
  content: '';
  position: absolute;
  left: 2px;
  top: -3px;
  width: 2px;
  height: 6px;
  background: var(--border);
  opacity: 0.3;
}

/* ── History Dots — Pixel gem stones ── */
.auto-history-dot {
  width: 8px;
  height: 8px;
  border-radius: 0;
  flex-shrink: 0;
  image-rendering: pixelated;
  position: relative;
  border: 1px solid transparent;
}

/* Success gem — green diamond shape via clip-path */
.auto-history-dot.success {
  background: var(--green);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  width: 10px;
  height: 10px;
  border: none;
  box-shadow: none;
  position: relative;
}

.auto-history-dot.success::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 4px;
  height: 4px;
  background: rgba(255,255,255,0.25);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

/* Failed gem — red diamond shape */
.auto-history-dot.failed {
  background: var(--red);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  width: 10px;
  height: 10px;
  border: none;
  box-shadow: none;
  position: relative;
}

.auto-history-dot.failed::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 4px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.auto-history-time {
  color: var(--muted);
  min-width: 120px;
  font-family: var(--font-pixel);
  font-size: .42rem;
  letter-spacing: .02em;
}

.auto-history-note {
  color: var(--text);
  font-size: .72rem;
}

/* ── Steam puff effect for active expanded cards ── */
.auto-card.machine-active.expanded::before {
  content: '';
  position: absolute;
  top: 8px;
  right: 30px;
  width: 6px;
  height: 6px;
  background: rgba(200,200,200,0.15);
  border-radius: 0;
  animation: steamPuff 2s ease-out infinite;
  image-rendering: pixelated;
  pointer-events: none;
}


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .auto-card {
    padding: 14px;
  }

  .auto-meta {
    gap: 12px;
    flex-wrap: wrap;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  .automations-list {
    gap: 8px;
  }

  /* ── Cards: full width, compact ── */
  .auto-card {
    padding: 12px;
  }

  .auto-card-header {
    gap: 8px;
    flex-wrap: wrap;
  }

  .auto-name {
    font-size: 0.82rem;
  }

  .auto-schedule {
    font-size: 0.42rem;
    padding: 3px 8px 3px 20px;
  }

  .auto-desc {
    font-size: 0.72rem;
    margin: 6px 0;
    padding-left: 18px;
  }

  .auto-desc::before {
    left: 2px;
  }

  /* ── Meta: wrap and compact ── */
  .auto-meta {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.68rem;
    padding-left: 18px;
  }

  /* ── Actions: proper touch targets ── */
  .auto-actions {
    padding-left: 18px;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
  }

  .auto-toggle-btn {
    padding: 8px 16px;
    min-height: 40px;
    font-size: 0.68rem;
    flex: 1 1 auto;
  }

  /* ── History: compact ── */
  .auto-history {
    margin-top: 10px;
    padding-top: 10px;
  }

  .auto-history-title {
    font-size: 0.4rem;
    margin-bottom: 8px;
  }

  .auto-history-item {
    gap: 8px;
    padding: 4px 0;
    font-size: 0.68rem;
  }

  .auto-history-time {
    min-width: 80px;
    font-size: 0.38rem;
  }

  .auto-history-note {
    font-size: 0.68rem;
  }

  /* Status dot touch area */
  .auto-status-dot {
    width: 12px;
    height: 12px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   OWNER BADGES — Distinguish Anchor crons from Claude Code skills
   ═══════════════════════════════════════════════════════════════════════════ */

.auto-owner-badge {
  font-family: var(--font-pixel);
  font-size: .38rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
  image-rendering: pixelated;
}

.auto-owner-badge.anchor {
  background: rgba(107,68,35,0.15);
  color: rgba(180,140,80,0.8);
  border: 1px solid rgba(107,68,35,0.25);
}

.auto-owner-badge.cc {
  background: rgba(139,92,246,0.12);
  color: rgba(167,139,250,0.9);
  border: 1px solid rgba(139,92,246,0.25);
}

.auto-owner-badge.both {
  background: rgba(108,191,74,0.1);
  color: rgba(108,191,74,0.85);
  border: 1px solid rgba(108,191,74,0.2);
}

/* Claude Code skill cards — subtle purple left border accent */
.auto-card.cc-skill {
  border-left: 3px solid rgba(139,92,246,0.35);
}

.auto-card.cc-skill:hover {
  border-left-color: rgba(139,92,246,0.6);
}

/* Both-owner cards — subtle green left border */
.auto-card.both-owner {
  border-left: 3px solid rgba(108,191,74,0.3);
}

.auto-card.both-owner:hover {
  border-left-color: rgba(108,191,74,0.5);
}

/* ─── Stats Bar ─── */
.auto-stats-bar {
  display: flex;
  gap: 24px;
  justify-content: center;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.auto-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.auto-stat-value {
  font-size: 0.75rem;
  color: var(--gold);
}

.auto-stat-ok { color: var(--green); }
.auto-stat-fail { color: var(--red, #e74c3c); }

.auto-stat-label {
  font-size: 0.62rem;
  color: var(--muted);
}

/* ─── Filter Buttons ─── */
.auto-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.auto-filter-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 150ms;
}

.auto-filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.auto-filter-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* ─── Health-based Card Colors ─── */
.auto-card.health-ok {
  border-top: 2px solid rgba(76, 175, 80, 0.3);
}

.auto-card.health-paused {
  border-top: 2px solid rgba(255, 193, 7, 0.3);
  opacity: 0.7;
}

.auto-card.health-fail {
  border-top: 2px solid rgba(231, 76, 60, 0.5);
  background: linear-gradient(135deg, var(--panel) 0%, rgba(231, 76, 60, 0.05) 100%);
}
